Commit Graph
1961 Commits
Author SHA1 Message Date
Jon Shallow 1a349d5cb4 coap_cache: Add in Cache Key and Cache Entry support
This updates the initial work done for adding in cache support

include/coap2/coap_cache.h: (new)
include/coap2/coap_cache_internal.h: (new)
src/coap_cache.c: (new)

New files to support cache support.

CMakeLists.txt:
Makefile.amMakefile.am:
Makefile.libcoap:
configure.ac:
examples/lwip/Makefile:
include/coap2/coap.h.in:
include/coap2/coap.h.windows:
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

Add in the new files.

examples/client.c:

Fix valgrind reported memory leak.

examples/coap-server.c:

Add in new example_data resource that uses the new caching logic.
Update hnd_put() to use the new cache logic for BLOCK1 PUTs.

include/coap2/coap_forward_decls.h:
include/coap2/coap_internal.h:
include/coap2/coap_session.h:
include/coap2/net.h:

Add in new cache support.

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

Include the new functions.

man/Makefile.am:
man/coap.txt.in:
man/coap_cache.txt.in: (new)

Update documentation.

src/coap_io.c:

Idle timeout cache entries.

src/coap_session.c:

Delete cache entry when session is deleted.

src/net.c:

Delete cache entries when context is freed off.

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

Add in SHA256 digest support.
2020-10-14 10:04:12 -04:00
Olaf Bergmann 0b142f9eda coap_cache: initial caching code 2020-10-14 09:33:37 -04:00
Jon Shallow e0a6593728 memory: Add in support for creating coap_binary_t objects
Add in coap_new_binary() and coap_delete_binary() functions which operate
in the same way as coap_new_string() and coap_delete_string() but work on
coap_binary_t objects.

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

Add in the coap_new_binary(), coap_resize_binary() and coap_delete_binary()
functions.

configure.ac:
man/Makefile.am:
man/coap.txt.in:
man/coap_string.txt.in: (new)

Add in documentation for the coap_string functions.

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

Update with new functions.

coap_config.h.contiki:
include/coap2/lwippools.h:
include/coap2/mem.h:
src/mem.c:

Add support for fixed memory allocations for Cacke-Key and Cache-Entry
2020-10-14 09:33:37 -04:00
Olaf Bergmann e581813a55 [tinydtls] update to latest version
libcoap now includes tinydtls commit 290c48d
2020-10-14 15:05:53 +02:00
Olaf Bergmann c7c416b8a0 Doxyfile.in: updated to version 1.8.20
The Doxyfile template has been updated to version 1.8.20 to get of
warnings due to deprecated features that were still referenced.
2020-10-14 14:41:40 +02:00
obgm 10db554d3e Merge pull request #523 from mrdeep1/doxygen_warnings
Doxygen: Clean up documentation errors
2020-10-14 13:35:36 +02:00
obgm 45df1c083a Merge pull request #551 from mrdeep1/epoll_spin
epoll: Stop spin between TCP connect and received data
2020-09-23 09:25:45 +02:00
Jon Shallow 8c635e709b epoll: Stop spin between TCP connect and received data
If a client TCP connection connects, EPOLLOUT remains enabled so epoll_wait()
always returns immediately causing a loop until there is other data traffic.

This fix is to enable EPOLLIN and disable EPOLLOUT if COAP_SOCKET_WANT_WRITE
is not set at point of connection successful.
2020-09-21 12:47:31 +01:00
Olaf Bergmann f00be554cc net.c: Fix fail_cnt reset on empty ACK
coap_touch_observer() must be called on empty ACKs before leaving the
dispatch function.

Fixes #550 [1]

[1] https://github.com/obgm/libcoap/issues/550
2020-09-15 10:10:11 +02:00
obgm af067703a0 Merge pull request #521 from mrdeep1/lwip_strings
LwIP: Check memory allocation sizes for COAP_OPTLIST and COAP_STRING
2020-09-10 18:44:51 +02:00
obgm 9ee4895797 Merge pull request #540 from mrdeep1/fetch_observe
Observe: Support FETCH
2020-09-10 18:08:46 +02:00
obgm c42c97044d Merge pull request #483 from mrdeep1/dtls_handshake
DTLS: Sessions unnecessarily being re-handshaked
2020-09-10 18:00:47 +02:00
obgm 24ce7425b9 Merge pull request #513 from mrdeep1/gnutls_fix
coap_gnutls.c: Fix issues found with interoperability testing
2020-09-09 17:24:55 +02:00
Jon Shallow ce4c26608f coap_gnutls.c: Fix issues found with interoperability testing
Make sure that gnutls_priority_set_direct() is called after
gnutls_priority_set().

Output alert information if an alert occurred.

Handle valgrind slowing things down, causing packet retries.
2020-09-09 14:41:33 +01:00
obgm ffc1979b6b Merge pull request #476 from mrdeep1/rfc_8768
RFC8768: Add in support for CoAP Option Hop Limit loop detection
2020-09-08 18:08:59 +02:00
Jon Shallow 7033555d29 RFC8768: Add in support for CoAP Option Hop Limit loop detection
All this is handled by libcoap with coap-client having the ability to define
an initial Hop Count value for testing. No other application support is
required.

Incoming requests are checked for the Hop Limit option - if found, the value
is decremented in the PDU before passing it up to the application. If it
decrements to 0, a 5.08 response is generated.

coap_add_option() checks if this is a Proxy option for a request. If so, and
Hop Limit option does not exist, then the Hop Limit option is inserted into
the PDU with the default value (16).

coap_send() checks if it is a 5.08 response and if so, prepends the diagnostic
data with the IP address of the transmitting interface. If the IP address
already exists, then the PDU is dropped as the return path for the 5.08 response
is looping.  An alternative method for return path looping check is also
used by initially setting, then testing and then decrementing the Hop Limit
value as response packets pass back through the proxies.  If a proxy does not
copy the Hop Limit options when returning the 5.08 response, then the IP address
duplication is used.

Makefile.am:

Hide the coap_insert_option(), coap_update_option and coap_pdu_check_resize()
function from applications.

README.md:

Add in RFC8768 is supported by libcoap.

examples/client.c:

Add in the -H hoplimit option.

include/coap2/pdu.h:

Add in the default Hop-Limit: option COAP_OPTION_HOP_LIMIT.
Re-organize the COAP_OPTION_ descriptions to include
the C, U, N, R, E, I and U flags.
Expose the internal coap_pdu_check_resize() function so src/net.c can use it.
Define the two new internal functions coap_insert_option() and
coap_update_option() and expose them so that the test suites can use them.

man/coap-client.txt.in:

Document the new -H hoplimit option.

man/coap.txt.in:

Include the new RFC8768.

man/coap_pdu_setup.txt.in:

Update documentation for the CoAP options.

src/coap_debug.c:

Add in support for printing out COAP_OPTION_HOP_LIMIT.

src/net.c:

Make sure that COAP_OPTION_HOP_LIMIT is not returned in an error response.
Decrement received Hop-limit in handle_request() and generate 5.08 response
if appropriate.
Update coap_send() to prepend IP in 5.08 response.
Support COAP_OPTION_HOP_LIMIT being used in the 5.08 response message.

src/pdu.c:

Report on CoAP options that are repeated, but not defined as repeatable.
Define new (5.08) Hop Limit Reached error response.

Add in new internal coap_insert_option() function. This now means that
callers of coap_add_option() no longer have to have the options in the
correct order.

Add in new internal coap_update_option() function that updates the value of
an option.

Make coap_pdu_check_resize() non-static.

tests/test_pdu.c:

Check that options are getting inserted in the correct order when using
coap_insert_option(), even though they are provided in a random order.

Test the coap_update_option() function.
2020-09-07 12:34:04 +01:00
Jon Shallow e85e3abb82 Observe: Support FETCH
Support observe for both GET and FETCH.

Correct coap-client programatic addition of observe establish option which
"happened" to work previously because COAP_OBSERVE_ESTABLISH was 0.
2020-08-19 11:24:08 +01:00
obgm 1739507a1e Merge pull request #536 from mrdeep1/bad_tcp
net.c: memory leak in handle_request if error input
2020-08-12 17:26:00 +02:00
Olaf Bergmann 1b63deb3c3 Updated tinydtls to latest develop HEAD
Tinydtls builds have failed due to [1].

[1] https://github.com/eclipse/tinydtls/pull/44
2020-08-12 17:23:11 +02:00
Jon Shallow b3eacf2eac net.c: memory leak in handle_request if error input
coap_add_token() can error for multiple reasons when building the response
PDU - but then the response PDU is not deleted on error if it exists.

The PDU is now deleted on coap_add_token() error.
2020-08-12 15:32:54 +01:00
obgm cbc3430ade Merge pull request #532 from mrdeep1/cmake_build
cmake: Fix builds with new TinyDTLS
2020-08-12 14:36:37 +02:00
Jon Shallow 63665a620e cmake: Fix builds with new TinyDTLS
Use autoreconf instead of autoconf
2020-07-23 14:30:19 +01:00
Olaf Bergmann e74fc73d8d configure.ac: show library type to be built in summary
The configure summary now shows whether libcoap is built as shared or
static library.
2020-07-23 12:09:55 +02:00
obgm b373aeca57 Merge pull request #525 from mrdeep1/testdriver
testdriver: Add in support for access to libcoap internal functions
2020-07-23 12:04:15 +02:00
obgm 65041c934d Merge pull request #475 from mrdeep1/pkcs11_support
PKCS11: Add in PKCS11 support for PKI
2020-07-23 11:40:50 +02:00
Olaf Bergmann 5f2f4ecf81 tinydtls: update to latest version
This change points the submodule to the changed tinydtls repository
which now lives at https://github.com/eclipse/tinydtls and updates
to the latest development HEAD.

Closes PR #531. [1]

[1] https://github.com/obgm/libcoap/pull/531
2020-07-23 10:00:32 +02:00
Jon Shallow b1245a95d7 testdriver: Add in support for access to libcoap internal functions
libtool marks functions included in the Makefile.am CTAGS_IGNORE list as
nm type 't' in .so library files so that they are not globally visible.
This means that tests/testdriver is unable to access these functions.

However, when building .a files, these functions remain as nm type 'T', so
are globally available.

This change causes tests/testdriver to always be be built with the .a
library file.

configure.ac:

Always enable --enable-static if --enable-tests is set.
Include this --enable-static requirement in the help information.

tests.Makefile.am

Change the default library type to always be .a and re-order parameters.
2020-07-16 11:25:22 +01:00
Jon Shallow 9443d9034a PKCS11: Add in PKCS11 support for PKI
Add in a new PKI_KEY type for PKCS11 URI to get the PKI information from a
smart card or HSM device.

Currently only OpenSSL and GnuTLS are supported.

Makefile.am:

Do not expose coap_dtls_shutdown() function.

examples/client.c:
examples/coap-server.c:

Add in support for using pkcs11: URIs for defining the Certificates and
Private Keys.

include/coap2/coap_dtls.h:

Add in COAP_PKI_KEY_PKCS11 Key type.

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

Update documentation for supporting PKCS11.

man/coap_encryption.txt.in:

Add in documentation for COAP_PKI_KEY_PKCS11.
Correct some typos.

HOWTO.dual.gnutls (new):
HOWTO.dual.openssl (new):
HOWTO.dual.softhsm2 (new):
HOWTO.pkcs11 (new):

HowTo information.

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

Add in PKCS11 support.

src/coap_mbedtls.c:

PKCS11 not yet supported.
Add in no-op coap_dtls_shutdown() function.

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

Add in no-op coap_dtls_shutdown() function.

src/net.c:

Invoke coap_dtls_shutdown() function in coap_cleanup().

NOTE: There are memory leaks after cleanly closing down.  These are not within
libcoap as far as can be determined.  These leaks are a work in progress.
2020-07-07 09:15:58 +01:00
Jon Shallow ff023a183a Doxygen: Clean up documentation errors
include/coap2/async.h:
include/coap2/coap_prng.h:

Correct documentation errors
2020-07-01 10:23:07 +01:00
obgm 4107f42d90 Merge pull request #522 from mrdeep1/block_restriction
net.c: Relax TCP CSM Block-Wise-Transfer tests
2020-07-01 10:52:22 +02:00
Jon Shallow 63ab45b6a2 net.c: Relax TCP CSM Block-Wise-Transfer tests
If the initial coap_send() PDU initiates a TCP/TLS connection, the PDU is
delayed until the CSM packets are exchanged.  If the initial PDU contains
a BLOCK1 or BLOCK2 option, the PDU gets dropped as Block-Wise-Transfer in the
CSM has not been seen yet.  Seen if '-b X' option is used for coap-client.

The check is now only when the session has fully established and the
situation only logged and the PDU Not dropped.
2020-06-30 21:45:26 +01:00
Jon Shallow f1bc324f9b LwIP: Check memory allocation sizes for COAP_OPTLIST and COAP_STRING
These are fixed memory sizes, but applications can ask for a bigger size
which will lead to memory corruption.

src/option.c:
src/str.c:

Check the requesting size to verify that it is within limits.  Contiki
properly checks the sizes.  Return NULL if too large with a logged varning.
2020-06-30 19:51:06 +01:00
obgm 098fa85395 Merge pull request #512 from mrdeep1/tcp_fixes
TCP: Prevent incorrectly formed PDUs causing RAM exhaustion.
2020-06-30 14:04:20 +02:00
Olaf Bergmann 448e08ae6c Merge branch 'develop' of github.com:obgm/libcoap into develop 2020-06-29 17:30:54 +02:00
Olaf Bergmann 0d2ba8ce35 CMakeLists.txt: add coap_prng.c and rename prng.h 2020-06-19 17:51:51 +02:00
Olaf Bergmann f92bfe9af3 Renamed prng.h to coap_prng.h 2020-06-19 17:51:25 +02:00
Olaf Bergmann 8fdc5696f7 configure.ac: check for getrandom() 2020-06-19 17:44:20 +02:00
Olaf Bergmann f17112659e [PRNG] improve pseudo number generation on platform POSIX
These new functions for generating pseudo numbers replace the old
macro-based approach:

coap_prng() replaces prng() to generate new pseudo random numbers.
This function uses getrandom() if HAVE_GETRANDOM is defined at
build time.

coap_prng_init() replaces prng_init() to seed the pseudo random
number generator. The function does nothing if HAVE_GETRANDOM is
set at build time.

coap_set_prng() can be used to register a custom pseudo number
generation function replacing the default.
2020-06-19 17:40:13 +02:00
Olaf Bergmann f0e8ebe0d0 coap-server.c: free allocated uri memory in hnd_delete
This fixes CID 1483548.
2020-06-19 16:51:55 +02:00
Olaf Bergmann 784c2ddc5f coap-server.c: fix memory leak in hnd_unkown_put()
Reverse the sequence of sanity checks to avoid allocating a new object
when not necessary.

This fixes CID 1483549.
2020-06-19 16:49:13 +02:00
Olaf Bergmann c98cc237b3 net.c: fix memory leak for query in handle_request
The storage for query was not released when coap_add_token() has
failed. As the query is used only if successful, the storage
allocation is moved downwards to improve handling of error cases.

This fixes CID 1483550.
2020-06-19 16:42:42 +02:00
Olaf Bergmann 48dc4538ce resource.[hc], net.c: fix use after free for query string
If a resource is observed, handle_request() passes the ownership
of a Uri-Query to the observer structure for later retrieval. In
this case, the query is not free'd in handle_request. However, if
the observer data structure ("subscription") was not created due
to insufficient memory, the query string must not be deleted as
it is used for the resource handler callback later in
handle_request(). The solution here passes ownership to the
observer only if case coap_add_observer() is successful.

This fixes CID 1483551.
2020-06-19 16:27:51 +02:00
Olaf Bergmann ec3dfda228 coap-server.c: Fix memory leak in hnd_put()
Added missing coap_delete_string() for uri_path in case of an error
return.

This fixes CID 1483553.
2020-06-19 16:13:50 +02:00
Olaf Bergmann da38169b42 examples-code-check.c: add NULL pointer check before closing file
This fixes CID 1495717.
2020-06-19 16:07:37 +02:00
Olaf Bergmann ba45a57efc coap-server.c: add missing fclose in read_file_mem
This fixes CID 1495722.
2020-06-19 16:01:29 +02:00
Olaf Bergmann e413fd545b coap-server.c: avoid fopen on NULL pointer in read_file_mem
As the behavior for calling fopen() on a NULL pointer is undefined in
ISO C99, a check is added before passing the file name to fopen().

This fixes CID 1495723.
2020-06-19 16:01:29 +02:00
Olaf Bergmann 1fded5dace coap-server.c: close file after reading SNI file
Add missing fclose() to cmdline_read_pki_sni_check() and
cmdline_read_psk_sni_check().

This fixes CIDs 1495719 and 1495724.
2020-06-19 16:01:09 +02:00
Olaf Bergmann 9c64e90517 net.c: fix check_return false positive from Coverity
In coap_io_do_epoll(), read() is called after timeout to clear the
file descriptor associated with the firing timer. As this function is
only called for its side effect, the result is ignored. Coverity scan
reports this as check_return event. A cast to void has been added to
document that the result is ignored on purpose.

This fixes CID 1495728.
2020-06-19 15:19:08 +02:00
Olaf Bergmann f97a7c5bde coap_session.c: avoid false positives with coverity for session release
coap_session_release() decrements a reference counter and releases
session resources when zero is reached. In certain function call
chains this leads to false positives with Coverity code analysis.
This change adds specific primitives to avoid these false positives.
This behavior is controlled by pre-processor conditionals.
2020-06-19 15:09:35 +02:00
Olaf Bergmann 7efa65077b Makefile.am: Add EXTRA_CFLAGS to AM_CFLAGS
Invoking make with EXTRA_CFLAGS allows to pass build configuration
parameters on the command line.
2020-06-19 15:09:35 +02:00