Commit Graph
1784 Commits
Author SHA1 Message Date
Jon Shallow 8abd8fa677 Add mbedtls build into Travis builds
.travis.yml
build-env/Dockerfile.build-env
build-env/Dockerfile.develop
scripts/build.sh
scripts/dist.sh

Update with mbedtls information
2020-01-16 09:38:43 +00:00
Jon Shallow e81af636af Add in MbedTLS support documentation
man/coap_attribute.txt.in:
man/coap_context.txt.in:
man/coap_encryption.txt.in:
man/coap_handler.txt.in:
man/coap_logging.txt.in:
man/coap_observe.txt.in:
man/coap_pdu_setup.txt.in:
man/coap_recovery.txt.in:
man/coap_resource.txt.in:
man/coap_session.txt.in:
man/coap_tls_library.txt.in:

Add in reference to MbedTLS where appropriate.

man/coap_encryption.txt.in:

Add in PKI Key type COAP_PKI_KEY_PEM_BUF for passing in PEM information
that is held in memory instead of in a file.
2020-01-16 09:38:43 +00:00
Jon Shallow de5945bed7 Add support for COAP_PKI_KEY_PEM_BUF in coap_openssl.c and coap_gnutls.c
Existing COAP_PKI_KEY_PEM key type reads the PEM file from disk.
COAP_PKI_KEY_PEM_BUF key type has the same PEM content format, but provided
in a memory buffer.  The buffer should be NULL terminated and the size of
the buffer passed in should include the NULL terminator.

src/coap_gnutls.c:

Add in support for COAP_PKI_KEY_PEM_BUF.
Make use of COAP_DTLS_RETRANSMIT_MS and COAP_DTLS_RETRANSMIT_TOTAL_MS rather
than hard coded numbers.

src/coap_openssl.c:

Add in support for COAP_PKI_KEY_PEM_BUF.
2020-01-16 09:38:43 +00:00
Jon Shallow f601ddbf78 Add in MbedTLS support
Add in MbedTLS library support as another alternative TLS library

Makefile.am:

Include new src/coap_mbedtls.c file.

configure.ac:

Add in --with-mbedtls support which generates HAVE_MBEDTLS in coap_config.h.

include/coap2/coap_dtls.h:

Add in TLS Library type COAP_TLS_LIBRARY_MBEDTLS and make COAP_TLS_LIBRARY_*
defines an enum.
Add in PKI Key type COAP_PKI_KEY_PEM_BUF for passing in PEM information
that is held in memory instead of in a file.
Add in #define COAP_DTLS_RETRANSMIT_MS, COAP_DTLS_RETRANSMIT_TOTAL_MS
and COAP_DTLS_RETRANSMIT_COAP_TICKS

src/coap_debug.c:

Output MbedTLS information if appropriate.

src/coap_mbedtls.c: (New)

Contains the MbedTLS interface code.

src/coap_notls.c:

Do not use code if MbedTLS is being built.

tests/test_tls.c:

Include MbedTLS library checks.

README.md:

Include MbedTLS as a valid (D)TLS library.
2020-01-16 09:38:43 +00:00
obgm cca37f465c Merge pull request #439 from mrdeep1/coap-rd-dtls
coap-rd: Add in (D)TLS support
2020-01-16 10:23:58 +01:00
Jon Shallow da41a91a11 coap-rd: Add in (D)TLS support
Add in basic (D)TLS support using code and options from coap-server.

Closes #435
2020-01-15 17:29:10 +00:00
obgm 0a5bf521b4 Merge pull request #440 from mrdeep1/coap-server-doc
coap-server: Correct man and help documentation
2020-01-15 17:52:35 +01:00
obgm 183450f5d0 Merge pull request #438 from mrdeep1/windows_builds
Windows: Update code to build on Windows
2020-01-15 17:35:32 +01:00
obgm ef1a67d0a9 Merge pull request #436 from mrdeep1/white_space
tests/test_encode.c: Remove trailing white space
2020-01-15 17:26:15 +01:00
obgm e008a0781e Merge pull request #445 from mrdeep1/observe_always_non
observe: Add in support for all observe responses to be non-confirmable
2020-01-13 18:02:52 +01:00
Jon Shallow d2f7b4f23a observe: Add in support for all observe responses to be non-confirmable
https://tools.ietf.org/html/rfc7641#section-4.5 requires that non-confirmable
observe responses should be sent as confirmable at least once every 24 hours.

However there is a requirement to override this periodical confirmable sending
behavior in lossy under DDoS attack type environments.

https://tools.ietf.org/html/draft-ietf-dots-signal-channel-41#section-4.4.2.1

Add in support for, and document, a new coap_resource_init() flag
COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS to handle this non RFC7641 requirement.
2020-01-13 13:14:25 +00:00
Jon Shallow ba7089994d coap-server: Correct man and help documentation
Found when updating the coap-rd documentation.
2019-12-28 16:58:51 +00:00
Jon Shallow 82a68f4457 Windows: Update code to build on Windows
Add in specific _WIN32 definitions for the missing functionality from
recent PR updates.

R_OK (used by access())
strndup()
strcasecmp()
2019-12-26 20:55:53 +00:00
Jon Shallow 07f054a2bb tests/test_encode.c: Remove trailing white space 2019-12-23 13:24:20 +00:00
obgm 03cc5791c5 Merge pull request #417 from mrdeep1/coap_run_once_fds
coap_io.c: Add in additional FD checking support for coap_run_once()
2019-12-20 17:47:35 +01:00
obgm 5d4d7d1043 Merge pull request #432 from mrdeep1/endpoint_closure_message
coap_session.c: Re-order socket closure so TLS closed messages are sent
2019-12-20 17:33:08 +01:00
Jon Shallow 2502dbd4fa coap_session.c: Re-order socket closure so TLS closed messages are sent
Fix socket closure order in coap_free_endpoint() so
the closure message correctly gets out.
2019-12-20 15:38:36 +00:00
obgm 8886857813 Merge pull request #429 from mrdeep1/broken_psk
client.c: Fix ordering of encryption selection to fix PSK
2019-12-19 17:13:53 +01:00
Jon Shallow 0be55e96ed client.c: Fix ordering of encryption selection to fix PSK
PR #338 broke the PKI/PSK selection order for the encryption type
to use when trying to include the SNI even if PSK or PKI had not
been configured - even though coaps or coaps+tcp was in use. If
PSK had been defined, then it failed.

This fix puts the creation of the correct type of session into a separate function
which is then called from 2 places.
2019-12-18 17:06:41 +00:00
obgm e186e68632 Merge pull request #426 from ltaskpt/develop
bugfix: ea72c3d7 outstanding CON requests limitation may drop new request.
2019-12-17 11:20:11 +01:00
YangYayun d5a9f26b77 resource.c: outstanding CON requests limitation may drop new request.
In ea72c3d7, the r->partiallydirty is set to 0 before the limitation.
A new request will be dropped when the last request hasn't received its
ACK.
The force clear operation of 'r->dirty' after 'LL_FOREACH' loop will
drop new request too.

resource.c:
In coap_notify_observers(), outstanding CON requests limitation, set
'r->partiallydirty' & 'obs->dirty' to 1 before 'continue'.
2019-12-17 13:56:07 +08:00
obgm 91e779192b Merge pull request #338 from mrdeep1/pki_sni_demo
coap-server: Add in support for SNI to change PKI certificates
2019-12-16 16:40:53 +01:00
Jon Shallow 543581d1ae coap-server: Add in support for SNI to change PKI certificates
examples/client.c:

Update to send SNI if coaps, but certs/PSK not defined.

examples/coap-server.c:

Add in -S option to support changing certificate/ca if there is as SNI match.

man/coap-server.txt.in:

Update man page with new -S option.
2019-12-16 15:16:45 +00:00
obgm 1c90defd66 Merge pull request #335 from mrdeep1/psk2_api
Add in PSK support for SNI, Identity and Hint checking to enable PSK changes
2019-12-09 11:46:22 +01:00
Jon Shallow c6a1d2ad8c Update documentation for new _psk2() functions
doc/main.md:

Correct copyright date

man/Makefile.am:

Update A2X_EXTRA_PAGES to include man pages that have digits in the name

man/coap_context.txt.in:
man/coap_encryption.txt.in:
man/coap_handler.txt.in:
man/coap_logging.txt.in:
man/coap_observe.txt.in:
man/coap_pdu_setup.txt.in:
man/coap_resource.txt.in:
man/coap_session.txt.in:

Update with _psk2() information.
Update examples to remove compiler warnings

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

Add in documentation on additional support for using / testing out the new
_psk2() functionality
2019-12-09 09:49:44 +00:00
Jon Shallow 1c8dce06b9 Update coap-client and coap-server to use new _psk2 functions
examples/client.c:

Update code to use the new coap_new_client_session_psk2() function, adding
the new Identity Hint callback.

Add in new option -h to define a file containing new PSK information if
Identity Hint is matched.

examples/coap-server.c:

Update code to use the new coap_context_set_psk2() function, adding
the new Identity and SNI callbacks.

Add in new option -i to define a file containing new Pre-Shared Key
if Hint and Identity is matched.
Add in new option -s to define a file containing new PSK information if
SNI is matched.
2019-12-09 09:35:30 +00:00
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
Jon Shallow 039826b83e coap_io.c: Add in additional FD checking support for coap_run_once()
coap_write() and coap_read() are really internal functions that are called
from within coap_run_once() separated by a select() to wait for i/o and
ideally should not be used in applications.

However, currently, coap_write() and coap_read() are needed instead of
coap_run_once() if there is no epoll support in libcoap so that if additional
non libcoap FDs need to be set up and monitored by the select() call they
then can be processed accordingly if the non libcoap FDs are set in the
select() response.

coap_io_process_with_fds() is a new function extending coap_run_once() that
allows non libcoap FDs to be monitored in the coap_run_once() internal
select() call and can then be tested by the caller of
coap_io_process_with_fds().

coap_run_once() now calls coap_io_process_with_fds() with readfds, writefds,
exceptfds set to NULL and nfds set to 0.

Note: nfds, readfds, writefds and exceptfds are ignored if there is underlying
epoll support in libcoap as epoll functions are used, not select().  Use
coap_context_get_coap_fd() to get a single FD that covers all the libcoap
FDs that can be used in the application along with other non-libcoap FDs
when there is epoll support.  See coap_io(3) for further information.

include/coap2/net.h:
libcoap-2.map:
libcoap-2.sym:
man/coap_io.txt.in:
src/coap_io.c:

Include and document the new coap_io_process_with_fds() function.
2019-11-04 17:16:16 +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