Commit Graph
1810 Commits
Author SHA1 Message Date
Jon Shallow bb38e995bc Windows C4267 errors: Fix size_t conversion warnings in windows builds
examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:
include/coap2/block.h:
include/coap2/coap_hashkey.h:
src/block.c:
src/coap_debug.c:
src/coap_hashkey.c:
src/coap_io.c:
src/coap_openssl.c:
src/net.c:

Fix C4267 windows compilation warnings when using Visual Studio where
size_t variable parameters are being converted  in both size and sign.

There still are some C4116 warnings to fix.
2020-02-21 17:28:11 +00:00
Olaf Bergmann 636a4df2b5 .travis.yml: Cleanup
* Remove deprecated option `sudo`
* Explicitly set `os` to `linux`
2020-02-21 17:57:44 +01:00
Olaf Bergmann fb92c07ae4 .travis.yml: eliminate concurring build options
Eliminate the matrix description which overides the jobs.
If both keywords are present, matrix takes precedence. This made
subsequent stages specified in the jobs section to be ignored.

Fixes #452
2020-02-21 17:44:16 +01:00
obgm ef4c01df04 Merge pull request #419 from mrdeep1/coap_run_once
Rename coap_run_once() to coap_io_process()
2020-02-14 10:26:35 +01:00
Jon Shallow 9cf4f10b35 Rename coap_run_once() to coap_io_process()
coap_read(), coap_write() and coap_run_once() are confusing in their names
and do not really describe what they do.

For example, coap_read() does both reading and writing, coap_write() may
do some writing, but primarily is used to determine what should be monitored
and for how long to wait in the following select() or epoll_wait() calls.

coap_run_once() implies that the code is only to be run once - again confusing.

By renaming coap_read() to coap_io_do_io(), this better describes what this
function does.

By renaming coap_write() to coap_io_prepare_io() this better describes what this
function does.

By renaming coap_run_once() to coap_io_process(), this better describes what
this function does.

By renaming coap_io_do_events() to coap_io_do_epoll(), this better describes what
this function does and is associated with.

A wrapper function coap_io_prepare_epoll() has been created, using
coap_io_prepare_io() with some preset values to simplify function usage.

include/coap2/net.h:

Update with the new function names, and deprecate the old functions.  Also
document the fact that coap_io_prepare_io(), coap_io_do_io(),
coap_io_prepare_epoll(), and coap_io_do_epoll() are really internal functions.

Create app_io module for Doxygen.

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

Expose the new functions to applications.

examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:
examples/contiki/coap-observer.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
man/coap_io.txt.in:
man/coap_observe.txt.in:
src/coap_io.c:
src/coap_io_lwip.c:
src/net.c:
src/pdu.c:

Update using the new function names.

Setting the etimer has been moved out of coap_io_process() into
coap_io_do_epoll(), making the logic easier for applications to use
coap_io_do_epoll() should they need to.  This also gets rid of a
potential timing window where a pending etimer event gets missed.

coap_io_do_epoll() now calls coap_io_prepare_epoll() if the etimer has
triggered removing the need for applications using coap_io_do_epoll() to
set up their own loops if etimer is triggered.
2020-02-13 19:54:48 +00:00
Olaf Bergmann fca966385e coap-server.c: Immediate exit when no endpoints defined
get_context() creates a new context object and adds coap_endpoint_t
objects for all listen addresses. The function now clears the
context object and returns NULL when no endpoint was created,
causing the server to exit immediately.
2020-02-12 13:28:39 +01:00
obgm af841d3a91 Merge pull request #451 from nmeum/coap-server-segfault
coap_free_endpoint: fix segfault with incorrect -A argument
2020-02-12 13:24:26 +01:00
Sören Tempel 605d56eb8d coap_free_endpoint: fix segfault with incorrect -A argument
`coap-server(1)` segfaults when invoked as:

	$ coap-server -A '2001:db8::1'
	Feb 09 18:28:49 WARN coap_socket_bind_udp: bind: Address not available
	Segmentation fault

In this case, the `ep->context->endpoint` is NULL but
`coap_free_endpoint` still attempts to access it. To prevent this
invocation from causing a segmentation fault, check if
`ep->context->endpoint` is NULL before accessing it.
2020-02-09 18:39:07 +01:00
obgm 978b228f5f Merge pull request #447 from mrdeep1/missing_no_tcp_openssl
coap_openssl.c: OpenSSL < 1.1.1 fails to build with --disable-tcp
2020-02-06 14:42:28 +01:00
obgm a52cce58af Merge pull request #450 from mrdeep1/con_active_fix
net.c: Correct setting of con_active if error
2020-02-06 14:40:11 +01:00
Jon Shallow 591c130276 net.c: Correct setting of con_active if error
Only update con_active if PDU has been successfully sent
2020-02-06 12:01:09 +00:00
Jon Shallow 15f9cf568a coap_openssl.c: OpenSSL < 1.1.1 fails to build with --disable-tcp
Missing COAP_DISABLE_TCP wrapper in OpenSSL 1.1.0 - 1.1.1 specific code

doc/main.md:

Update Copyright year.

include/coap2/coap_tcp_internal.h:

Update documentation for the internal TCP functions

src/coap_session.c
src/coap_tinydtls.c

Delete trailing space
2020-02-04 10:30:16 +00:00
obgm 69dd4426c5 Merge pull request #449 from mrdeep1/coap_request_enum
Make COAP_REQUEST_* enum for clarity
2020-02-03 12:38:29 +01:00
Jon Shallow e9cffe9b91 Make COAP_REQUEST_* enum for clarity
Make the COAP_REQUEST_* #defines enum coap_request_t for clarity.

This should help prevent mistakes such as in #448.
2020-02-03 09:33:15 +00:00
obgm b136504d22 Merge pull request #446 from mrdeep1/coap-rd-windows
coap-rd: Fix windows build
2020-01-17 10:58:25 +01:00
obgm ea838843ac Merge pull request #431 from mrdeep1/dtls_spin
coap_gnutls.c: Fix potential spin in DTLS retransmit timeout loop
2020-01-17 10:57:29 +01:00
obgm 8a31e24a85 Merge pull request #414 from mrdeep1/disable-tcp
Rebase disable-tcp branch and reduce code further
2020-01-16 16:46:10 +01:00
Jon Shallow 2a48f44fe4 coap-rd: Fix windows build
Define S_ISDIR if needed for Windows.
2020-01-16 15:36:28 +00:00
Jon Shallow c237b15b16 Correct Disable TCP for TLS and Windows
Makefile.am:

include coap_tcp_internal.h in EXTRA_DIST

libcoap-2.map
libcoap-2.sym:

Don't expose previously static coap_socket_format_errno().

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

Correct ENABLE_TCP (never defined) to !COAP_DISABLE_TCP.
Conditionally compile in TLS code as appropriate.

src/coap_io.c:

Correct #endif description.

src/coap_session.c:

Conditionally compile in TLS code as appropriate.

src/coap_tcp.c

Merge in appropriate parts of https://github.com/obgm/libcoap/pull/396 and
https://github.com/obgm/libcoap/pull/345 fixes.

include/coap2/coap_tcp.h:
include/coap2/coap_tcp_internal.h:

Rename include/coap2/coap_tcp.h to include/coap2/coap_tcp_internal.h and
remove reference to coap_tcp_is_supported().

include/coap2/coap.h.in:

Remove reference to coap_tcp.h.

coap_config.h.windows:

Include #define COAP_DISABLE_TCP 0.

include/coap2/coap.h.windows:

Reorder #includes

include/coap2/coap_internal.h:

Add #include coap_tcp_internal.h

include/coap2/coap_io.h:

Add in definition of coap_tcp_is_supported().

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

Include src/coap_tcp.c and include/coap2/coap_tcp_internal.h.
2020-01-16 15:17:10 +00:00
Olaf Bergmann b43907ef2b Conditionally disable TCP
The pre-processor flag COAP_DISABLE_TCP controls if TCP support is
compiled into the library. If set to 1, some bytes can be saved
by omitting TCP-specific code. By default, this flag is set to 0.

The new configure option '--disable-tcp' will set this flag to 1.
2020-01-16 13:37:24 +00:00
obgm bbe620f997 Merge pull request #427 from mrdeep1/handle_timeouts
coap_io.c: Stop calls to coap_dtls_handle_timeout() dereferencing the session
2020-01-16 13:10:25 +01:00
obgm e4e6676dcb Merge pull request #353 from mrdeep1/mbedtls
Add in MbedTLS support
2020-01-16 11:14:52 +01:00
Jon Shallow 2d6c50e041 coap-server: Add in support for using/testing COAP_PKI_KEY_PEM_BUF
Add in -m option to enable using COAP_PKI_KEY_PEM_BUF instead of
COAP_PKI_KEY_PEM when defining certificates.  This is done by reading in
the contents of the file into a temporary buffer and the buffer is
passed in instead of the filename to the PKI logic.
2020-01-16 09:40:44 +00:00
Jon Shallow d7055d16d8 Update win32 builds
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

Include coap_mbedtls.c in the files
2020-01-16 09:38:43 +00:00
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 d561151592 coap_gnutls.c: Fix potential spin in DTLS retransmit timeout loop
coap_dtls_get_timeout() may continue to return 'now' if the underlying
GnuTLS library gets confused by duplicate packets and so clears out
the data is to be retransmitted flag.  If there is a DTLS timeout retry, the
underlying logic does not reset 'last retransmit' on retrying the re-send
of the (now) non-existent data, so causing a spin in the coap_write() logic.

src/coap_gnutls.c:

This fix is to return 'now+dtls_timout' on the second and subsequents attempts
to return 'now'.

include/coap2/coap_dtls.h:

Make use of the new #defines that #353 is using so that this code compiles.
2020-01-06 16:00:20 +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