Commit Graph
1757 Commits
Author SHA1 Message Date
Jon Shallow 48cc799d42 Update DTLS interface modules to use the parameters in _psk2() functions
include/coap2/coap_dtls.h:
include/coap2/coap_session.h:

Update coap_dtls_cpsk_key_t and coap_dtls_spsk_key_t to use coap_bin_const_t.
Update coap_dtls_id_callback_t to return coap_bin_const_t*.
Update coap_session_t to use coap_bin_const_t for psk_identity, psk_hint
and psk_key.
Update coap_session_refresh_psk_key() to have a coap_bin_const_t parameter.

src/coap_gnutls.c:
src/coap_openssl.c:
src/coap_tinydtls.c:

Add in new callback functions to handle SNI, Identity and Hint request
information following the principles used for the PKI logic.

Install the appropriate callback functions by setting them up by using the
appropriate TLS library functions.

src/coap_session.c:
src/net.c:

Use the new versions of coap_dtls_cpsk_key_t and coap_dtls_spsk_key_t.

src/coap_session.c:

Add in new coap_session_refresh_psk_hint() function.
Update coap_session_refresh_psk_key() function.
2019-12-05 21:48:44 +00:00
Jon Shallow 23b3e6e17e Add in coap_new_client_session_psk2 and coap_context_set_psk2 functions
This fix is in preparation for the full coap_new_client_session_psk2()
and coap_context_set_psk2() functions.  Structures are updated with the
necessary information, as well as provide the high level support.

As new sessions are now created for every genuine incoming session (#333),
coap_context_t will only hold the initial information provided by
coap_context_set_psk2() (server mode), but if there is any updated
(triggered by SNI or Indentity), this will be kept in coap_session_t.

Likewise, the client initial information will be kept in the
coap_session_t, and if modified (triggered by Hint) will be kept separately
in coap_session_t.

This change does not include the support required in the DTLS interface modules
other than changes required to make the code compilable and still run the
existing examples - so it is a standalone change.

Makefile.am:

Make coap_dtls_context_set_cpsk, coap_dtls_context_set_spsk,
coap_session_refresh_psk_key and coap_session_refresh_psk_hint hidden
Remove coap_dtls_context_set_psk

include/coap2/*.h:

Replace call-back with callback for consistency

include/coap2/coap_dtls.h:

Include coap_dtls_cpsk_key_t and coap_dtls_spsk_key_t definitions
Define coap_dtls_spsk_key_t for the new coap_*_psk2 functions.
Include all the new call back function definitions

include/coap2/coap_session.h:

Update coap_session_t with the new PSK information
Define coap_new_client_session_psk2(), coap_session_refresh_psk_key() and
coap_session_refresh_psk_hint() functions

include/coap2/net.h:

Update coap_context_t with the new PSK information
Define the coap_context_set_psk2() function

include/coap2/str.h:

Add in a new struct coap_bin_const_t
Define new functions coap_new_bin_const(), coap_delete_bin_const()
and coap_binary_equal().

libcoap-2.{map|sym}

Expose the new coap_context_set_psk2, coap_new_client_session_psk2,
coap_new_bin_const and coap_delete_bin_const functions

src/coap_gnutls.c:
src/coap_notls.c:
src/coap_tinydtls.c:

Replace coap_dtls_context_set_psk() with coap_dtls_context_set_spsk()
and coap_dtls_context_set_cpsk()

src/coap_openssl.c:

Replace coap_dtls_context_set_psk() with coap_dtls_context_set_spsk()
and coap_dtls_context_set_cpsk()
Update the SSL_CTX_use* and SSL_set_* functions with the new variable
locations

src/coap_session.c:

Free off new information on coap_session_t in coap_session_mfree()

Build parameters for coap_new_client_session_psk2() in
coap_new_client_session_psk() and call coap_new_client_session_psk2() instead
of coap_session_create_client().
Create new coap_new_client_session_psk2().
Create new coap_session_refresh_psk_key() (will be used when DTLS interface
code is updated

src/net.c:

Update coap_get_session_client_psk() to use the new PSK locations.
Update coap_get_session_server_psk() to use the new PSK locations.
Update coap_get_session_server_hint() to use the new PSK locations.
Build parameters for coap_context_set_psk2() in
coap_context_set_psk() and call coap_context_set_psk2().
Create new coap_context_set_psk2().
Cleanup usage of old PSK information in coap_free_context()

src/str.c:

Code for coap_new_bin_const() and coap_delete_bin_const() functions
2019-12-03 14:46:26 +00:00
obgm 1b2246992e Merge pull request #425 from mrdeep1/man_resource
Update resource documentation
2019-12-03 10:37:45 +01:00
obgm e7cacb44fb Merge pull request #424 from mrdeep1/memory_ref_after_free
net.c: Fix memory access after session is freed
2019-12-03 10:32:29 +01:00
Jon Shallow 02923e7ffb Update resource documentation
man/coap_resource.txt.in:

Add in coap_resource_set_userdata() and coap_resource_get_userdata()
documentation

include/coap2/resource.h:

Re-organize order and put into appropriate doxygen groups

include/coap2/subscribe.h:

Fix Doxygen title case
2019-11-28 16:19:18 +00:00
Jon Shallow 5a2fe9a261 net.c: Fix memory access after session is freed
Make sure that session is not freed off in one of the callbacks while
testing the socket flags in the epoll logic.

Wrap the code with a coap_session_reference(session) and
coap_session_release(session) and remove all the interim wrappers.

Issue found when coap_read_session() internally does a coap_session_release().
2019-11-28 11:57:42 +00:00
Olaf Bergmann d6c25a9a07 coap-server.c: Fix warnings on 32-bit architectures
Casting an unsigned long to void * caused a compiler warning
on 32-bit architectures. This change uses unsigned int as
this has a sufficient range for the respective calculation
and introduces a union to avoid the explicit type cast.
2019-11-08 11:17:54 +01:00
Olaf Bergmann 39592e8519 configure.ac: Prepare for version 4.3.x
As upcoming changes will affect the existing API of libcoap, the
version number in configure.ac has been bumped to 4.3.x to avoid
confusion.
2019-11-06 16:36:43 +01:00
Olaf Bergmann 6fc3a7315f configure.ac: Bump version to 4.2.1, fix spelling errors v4.2.1 2019-11-05 21:09:06 +01:00
Olaf Bergmann d52c26642e doc/main.md: Small fixes in documentation main page
* Updated copyright year.
* Use EN_US for consistency.
2019-11-05 14:07:00 +01:00
Olaf Bergmann bb797c04a2 Merge branch 'develop' of github.com:obgm/libcoap into develop 2019-11-05 12:10:41 +01:00
obgm 3be41b0b9d Merge pull request #416 from mrdeep1/openssl_ciphers
OpenSSL: Update ciphers
2019-11-05 12:10:04 +01:00
Jon Shallow 5d01cf3139 OpenSSL: Update ciphers
src/coap_openssl.c:

Remove NULL as a valid cipher from the cipher list.

Add in TLSv1.3 ciphers if OpenSSL 1.1.1 (they are already included in
TLSv1.2 definition, but this is to document this is happening).

Remove the TLSv1.0 deprecated ciphers.

Cipher strings can now be overridden during compilation by
using -DCOAP_OPENSSL_CIPHERS=xxx compiler option where xxx is the
cipher string as defined in
https://www.openssl.org/docs/man1.1.0/man1/ciphers.html

Explicit PSK cipher strings can now be overridden during compilation
by using -DCOAP_OPENSSL_PSK_CIPHERS=xxx compiler option where xxx is the
cipher string.

Log the client ciphers presented, and the cipher chosen.

include/coap2/coap_debug.h:
src/coap_debug.c:

Add in COAP_LOG_CIPHERS as a debug level (value 9) which matches getting the
cipher information reported in GnuTLS, and is now used for OpenSSL.

man/coap-client.txt.in:
man/coap-rd.txt.in:
man/coap-server.txt.in:

Include OpenSSL for verbosity > 7.
2019-11-05 10:19:45 +00:00
Olaf Bergmann d4219549d4 Merge branch 'develop' of github.com:obgm/libcoap into develop 2019-11-04 17:01:02 +01:00
obgm 0389a6c0ae Merge pull request #398 from mrdeep1/epoll_timing
Fix timing window in epoll logic
2019-11-04 17:00:51 +01:00
Olaf Bergmann e8a2a6643e Revert "ext/tinydtls: Updated to latest develop version"
This reverts commit 118bdaba9c.
2019-10-30 10:30:49 +01:00
Olaf Bergmann 608249263d Merge branch 'develop' of github.com:obgm/libcoap into develop 2019-10-30 10:30:04 +01:00
obgm a3361b7062 Merge pull request #415 from cgudrian/fix-epoll-detection
Fix epoll detection
2019-10-30 10:29:07 +01:00
Christian Gudrian f8a6debe81 Fix epoll detection
The "ac_cv_header-..." macros are either set to "yes" or "no" and never to
the empty string.
2019-10-25 23:20:55 +02:00
Olaf Bergmann 118bdaba9c ext/tinydtls: Updated to latest develop version 2019-10-02 23:20:04 +02:00
Olaf Bergmann 7858c57919 Add unit tests for coap_encode/decode_var_safe/safe8 2019-10-02 16:57:57 +02:00
obgm 9b09c7dd2f Merge pull request #408 from mrdeep1/encode8
encode.c: Support encoding/decoding 8 byte options
2019-10-02 16:57:30 +02:00
obgm f93aa9977a Merge pull request #410 from mrdeep1/windows_building
BUILDING: Update adding Windows build information
2019-09-23 15:59:22 +02:00
obgm 9767659950 Merge pull request #411 from mrdeep1/vs2019
Update Windows projects to VS Independent
2019-09-23 15:47:38 +02:00
Jon Shallow 4dec5225c0 Update Windows projects to VS independent.
win32/coap-client/coap-client.vcxproj:
win32/coap-rd/coap-rd.vcxproj:
win32/coap-server/coap-server.vcxproj:
win32/install/install.vcxproj:
win32/libcoap.vcxproj:
win32/testdriver/testdriver.vcxproj:

Update WindowsTargetPlatformVersion to $(LatestTargetPlatformVersion)
and PlatformToolset to $(DefaultPlatformToolset).
2019-09-23 10:21:32 +01:00
Jon Shallow 5ac269755a BUILDING: Update adding Windows build information
Add in instructions as to how to build libcoap on a Windows platform
as well as update the other information with how to get the libcoap
code.
2019-09-20 21:02:53 +01:00
obgm f697b7b67a Merge pull request #409 from mrdeep1/asserts
Add --disable-assert support for the library
2019-09-20 16:35:05 +02:00
Jon Shallow 8faa8c28ff Add --disable-assert support for the library
Let configure enable (the default) or disable assert() code.

configure.ac:

Add in --enable-assert (the default) / --disable-assert support in libcoap.
Previously this was always enabled unless -DNDEBUG was passed in as a compiler
option.  Now NDEBUG is set or unset as appropriate in coap_config.h
This does not affect how assert()s work within the examples etc., only in the
library.

TODO:

HAVE_ASSERT_H is now cleaned up, so remove entry.

include/coap2/coap_internal.h:

Include assert.h for the library.

include/coap2/coap_io.h:
include/coap2/net.h:
include/coap2/resource.h:
src/address.c:
src/block.c:
src/coap_debug.c:
src/encode.c:
src/mem.c:
src/option.c:
src/pdu.c:
src/subscribe.c:
src/uri.c:

Remove un-needed '#include <assert.h>'
Note: address.h and utlist.h still include assert.h as there are assert()
within the header files.

examples/client.c:
src/coap_io.c:
src/coap_session.c:
src/net.c:
src/pdu.c:
src/resource.c:
src/str.c:

Remove any '#ifndef NDEBUG' wrappers for coap_log() output as they were true
before, but may not be now.
2019-09-20 13:09:56 +01:00
Olaf Bergmann 98cf51eae2 README.md: Added status badge for OSS-Fuzz
OSS-Fuzz [1] is a decentralized fuzzing service for open-source
software projects. This badge shows the status of libcoap wrt to the
latest fuzzer runs.

[1] https://google.github.io/oss-fuzz/
2019-09-19 09:50:38 +02:00
Jon Shallow 851cb374e8 encode.c: Support encoding/decoding 8 byte options
Options such as COAP_OPTION_ETAG are up to 8 bytes in size.  While
being opaque, they can internally be represented as an 8 byte number.

include/coap2/encode.h:
libcoap-2.map:
libcoap-2.sym:
src/encode.c:

Create 8 byte versions coap_decode_var_bytes8() and coap_encode_var_safe8().
2019-09-18 11:55:33 +01:00
obgm 1ccd3685ee Merge pull request #407 from mrdeep1/readme_update
README.md: Add in further information about libcoap
2019-09-17 12:58:37 +02:00
Jon Shallow 6e25d9df91 README.md: Add in further information about libcoap
Add in information on Documentation and Building.
Update the Package contents.

LICENCE:

Update date.
2019-09-17 11:19:58 +01:00
Jon Shallow 23a6daf1e5 Fix timing window in epoll logic
It is possible to miss a packet retransmission if it is just about to happen
and the coap_run_once() logic takes the time past the packet retransmission.
The retransmission will take place when coap_run_once() is next run, but that
could be significantly later.

1) Create a new coap_io_prepare_epoll() function that calls coap_write(), but
sets the etimer within this function instead of at the end of coap_run_once().

2) Handle the etimer trigger within coap_io_do_events() rather than loop
checking coap_io_do_events() within coap_run_once().

include/coap2/net.h:

Define coap_io_prepare_epoll().
Update coap_io_do_events() to be type void.

src/coap_io.c:

Add in coap_io_prepare_epoll().
Update coap_run_once() to use new/updated functions.

src/net.c:

Update coap_io_do_events().
Make coap_new_context() always fail if there is an epoll logic setup failure
libcoap compiled for epoll will not continue to run.
Give a runtime warning if coap_read() or coap_io_do_events() are called when
libcoap is compiled or not compiled respectively for using epoll.
[Both coap_read() and coap_io_do_events() need to be in libcoap-2.{map|sym} to
support when compiling with or without epoll support]

libcoap-2.map:
libcoap-2.sym:

Make coap_io_prepare_epoll() application accessible.
2019-09-13 21:08:04 +01:00
Olaf Bergmann 4e626d53a4 .travis.yml: Expand build matrix with EPOLL and SMALL_STACK
Some builds now have epoll support disabled and small stack enabled.
2019-09-13 14:04:05 +02:00
Olaf Bergmann 4a13437b69 scripts/build.sh: Additional options for epoll and small stack
* Passing EPOLL=no disables the epoll interface usage. Other values
  default to yes, i.e. epoll is used if available.
* Passing SMALL_STACK=yes enables some values stored in static
variables instead pushing on the stack. This usually requires
mutex support in the operating system.
2019-09-13 12:44:55 +02:00
Olaf Bergmann 45b5d23665 .travis.yml: Move Contiki and LwIP to separate stage
Special handling of platforms other than POSIX reduces the build
matrix and thus speeds up CI once additional configure options
need to be checked.
2019-09-13 12:28:45 +02:00
obgm f5cf6ef5cc Merge pull request #405 from mrdeep1/small_stack
configure.ac: Make COAP_CONSTRAINED_STACK configurable
2019-09-13 11:26:18 +02:00
obgm 9893c7222b Merge pull request #402 from mrdeep1/windows_project
Fix Windows builds
2019-09-12 13:01:48 +02:00
Jon Shallow c5ab99369f Fix Windows builds
coap_config.h.windows:

Windows has struct cmsghdr so use it.
Update libcoap versions.

include/coap2/coap.h.windows:

Update libcoap versions.
Bring in line with build include/coap2/coap.h.

include/coap2/coap_session.h:

Include coap_forward_decls.h so things build correctly.

win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

Add in missing include files.
2019-09-12 11:49:26 +01:00
Jon Shallow 75e3e8595d configure.ac: Make COAP_CONSTRAINED_STACK configurable
Add in support for --enable-small-stack to define
COAP_CONSTRAINED_STACK in coap_config.h
2019-09-11 15:41:14 +01:00
obgm 3266e6cfcc Merge pull request #404 from obgm/pthread-configure-check
Pthread configure check
2019-09-11 12:03:01 +02:00
Olaf Bergmann abec5b8228 coap_mutex.h: Use pthread mutexes if detected by configure
On systems that support pthread mutexes, stack usage can be minimized
with the use of static variables. Concurrent access is protected
on these systems with mutexes. Platforms that do not have pthread
support must map the coap_mutex_* macros accordingly.
2019-09-10 13:28:44 +02:00
Olaf Bergmann 07156ea048 configure.ac: Check for pthread.h and pthread_mutex_lock 2019-09-10 13:14:50 +02:00
Olaf Bergmann 30583fbed9 coap_session.h: Adjust whitespace 2019-09-09 17:17:49 +02:00
Olaf Bergmann d49d38849e Merge branch 'develop' of github.com:obgm/libcoap into develop 2019-09-09 17:17:05 +02:00
obgm 49867a8c48 Merge pull request #400 from mrdeep1/reverse_enums
Revert out changes to make 1 byte enums
2019-09-09 17:16:50 +02:00
Olaf Bergmann da1ac8572c Merge branch 'develop' of github.com:obgm/libcoap into develop 2019-09-09 14:31:25 +02:00
obgm a584864bcf Merge pull request #397 from mrdeep1/configure_epoll
Make epoll support configurable if O/S supports epoll
2019-09-09 14:31:11 +02:00
Jon Shallow 209c8a9267 Revert out changes to make 1 byte enums
include/coap2/coap_dtls.h
include/coap2/coap_session.h
include/coap2/pdu.h
man/coap_encryption.txt.in
src/net.c

Revert out all the #define -> enum in #386 that require the enum to be
one byte long.
2019-09-09 09:59:44 +01:00
Jon Shallow 480aa73bd7 Make epoll support configurable if O/S supports epoll
Add in --with-epoll as a ./configure option
2019-09-06 13:03:52 +01:00