Commit Graph
335 Commits
Author SHA1 Message Date
Jon Shallow 14e75a54b8 net.c: Delay sending ACK until after response_handler() is called
In handle_response() the ACK is sent before calling ctx->response_handler() so
if the response_handler() wants to send RST the server ignores it as the ACK
has already been received.

By updating coap_response_handler_t to return a value, this can be used to
send the ACK (return of COAP_RESPONSE_OK) or a RST (return of COAP_RESPONSE_FAIL)
after ctx->response_handler() is called.

include/coap2/net.h:
man/coap_handler.txt.in:

Create a new enum coap_response_t for use as the return value for
coap_response_handler_t.
Update coap_response_handler_t and associated documentation.

src/net.c:

Send CoAP ACK or RST depending on return value of ctx->response_handler().

examples/client.c:

Update message_handler() to use the new coap_response_handler_t return values
(coap_response_t).
2021-02-24 09:37:32 +00:00
obgm b0e47d71d0 Merge pull request #580 from mrdeep1/with_observe
Observe: Remove WITHOUT_OBSERVE conditional statements in the library.
2021-02-24 09:52:33 +01:00
Jon Shallow 9cb2f62a3e RFC7641: Move block handling logic down into libcoap
This change removes the need for applications having to know about handling
requests for the next block etc.  It also gives the application the ability
to pass a large body of data to be transmitted and be told when this body is
no longer required.

This logic is enabled in libcoap by setting COAP_BLOCK_USE_LIBCOAP using
coap_context_set_block_mode()

This change breaks down into 4 specific areas

1) Client doing a PUT/POST etc. of a large amount of data (BLOCK1).

coap_add_data_large_request() is used which provides a 'finished with data'
callback function as well as adding required options to the PDUs.  This
function calls coap_add_data_large_internal().

Internal coap_handle_response_send_block() sends off the subsequent blocks
(using session->lg_xmit).

2) Server receiving PUT/POST etc. of a large amount of data (BLOCK1).

Internal coap_handle_request_get_block() acknowledges the appropriate blocks
(using session->lg_srcv) and either passes in the individual blocks or the body
depending on whether COAP_BLOCK_SINGLE_BODY is set or not using
coap_context_set_block_mode().

3) Server sending a large data response to GET / observe (BLOCK2)

coap_add_data_large_response() is used which provides a 'finished with data'
callback function.  This function calls coap_add_data_large_internal() as well
as filling in the necessary options for each PDU.

Interal coap_handle_request_send_block() will then send the next requested block
(using session->lg_xmit).

4) Client receiving a large data response (BLOCK2)

coap_send_large() for the initial request sets this up.

Internal coap_handle_response_get_block() will then request the next block when
previous block received (using session->lg_crcv) and either passes the
individual blocks or the body depending on COAP_BLOCK_SINGLE_BODY being set in
coap_context_set_block_mode().

----

The following new internal functions have been added

coap_handle_request_get_block()
coap_handle_request_send_block()
coap_handle_response_get_block()
coap_handle_response_send_block()
coap_add_data_large_internal()

The following new functions have been added.

coap_add_data_large_request()
coap_add_data_large_response()
coap_context_set_block_mode()
coap_get_data_large()
coap_pdu_duplicate()
coap_send_large()
coap_session_init_token()
coap_session_new_token()

The coap_session_init_token() and coap_session_new_token() were added to make
the handling of unique tokens for each request/response easier.
https://datatracker.ietf.org/doc/html/draft-ietf-core-echo-request-tag-10#section-4

New files

include/coap2/coap_block_internal.h:
man/coap_block.txt.in:

New memory types

COAP_LG_XMIT
COAP_LG_SRCV
COAP_LG_CRCV
2021-02-23 18:01:04 +00:00
obgm b7fed2a706 Merge pull request #571 from Delsian/develop
refactor: replace magic numbers with defines
2021-02-23 17:50:06 +01:00
Eug Krashtan 6b58bfa96c examples: replace magic numbers with defines
CoAP response codes in examples represented by non-human-readable magic
numbers. It makes code harder to read, understand, and maintain.
Magic numbers there where replaced by human-readable enums.

Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
2021-02-22 21:20:31 +02:00
obgm 9f778cabca Merge pull request #583 from mrdeep1/doxygen_update
doxygen: Tidy up comments and add in missing modules
2021-02-19 16:04:13 +01:00
obgm 6a087687e8 Merge pull request #574 from mrdeep1/mbedTLS_naming
Mbed TLS: Update MbedTLS and mbedTLS to Mbed TLS to reflect brand name
2021-02-19 10:00:16 +01:00
Jon Shallow 05d30e5ef1 PKI: Make (D)TLS operation consistent across all TLS libraries
The use of the verify_peer_cert and require_peer_cert variables in the
coap_dtls_pki_t structure was giving inconsistent results across all the
TLS libraries.  This primarily was down to the large numbers of options
available to control the TLS handshakes in OpenSSL compared to the limited
control available to mbedTLS port which followed later. require_peer_cert is
not easy to control in mbedTLS as it is an implicit configuration based on how
other, not always related, items were configured.

require_peer_cert was used by the server to control whether the client could
use anonymous certificates or not.  This is now controlled by verify_peer_cert.

require_peer_cert variable has been replaced with check_common_ca, so that
the OpenSSL functionality can continue, but enable GnuTLS / mbedTLS to
produce the same results.  This allows peers to mutually authenticate (because
the peer certs are signed by the same common CA) or not which was in effect
controlled by verify_peer_cert previously.

If check_common_ca is set, then allow_self_signed is ignored.

If is_rpk_not_cert is set, then all certificate validation is ignored.

In the examples, use of the -R option unsets check_common_ca, so disables
mutual authentication support by having a common CA.  This was needed as
mbedTLS and GnuTLS only have a single trust store for CAs.

configure.ac:

Increase the number of mbed libraries to use when checking for mbedTLS.

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

Add in -n (unset verify_peer_cert) option. In the case of coap-server and
coap-rd, make -n refer to verify_peer_cert.
Add in TLS library capabilites in usage().

Update usage() documentation as appropriate, with some changes to fit
everything into a 80 column output.

include/coap2/coap_dtls.h:
include/coap2/net.h:

Update with variable changes, and make the coap_dtls_pki_t parameter const for
the *_context_set_pki() functions.

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

Update documentation to reflect the examples option usage.

man/coap_context.txt.in:
man/coap_encryption.txt.in:
man/coap_session.txt.in:

Update with the new variable name and document as appropriate.

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

Update to make variable usage consistent. Update logging from LOG_WARNING to
LOG_INFO where there is an override of a PKI check failure by one of the
coap_dtls_pki_t variables.

Timing window closed for TLS where the peer does not like a certificate, sends
fatal alert and closes connection.  local then fails on writing the next
handshake - but now also reads in alert and reports on it.

src/coap_io.c:

Update logging from LOG_WARNING to LOG_INFO for EPIPE or ECONNRESET errors in
coap_socket_write().

src/net.c:

Handle the const coap_dtls_pki_t parameter in coap_context_set_pki() function.
2021-02-18 16:51:32 +00:00
obgm 9b45575cdf Merge pull request #586 from timgates42/bugfix_typo_updated
docs: fix simple typo, udated -> updated
2021-02-12 15:28:24 +01:00
沈文武 ad01c1d5eb Fix some compile error in windows visual studio
1. since coap_add_option_later() has been removed, so remove
coap_add_option_later in lib-coap-2.(map,sym) and pdu.h
2. [PRNG] need include coap_prng.c into visual studio project too, since new
functions for generating pseudo numbers replace the old macro-based
approach.
3. [PRNG] need define coap_prng() coap_prng_init() coap_set_prng() for
windows too since these function are exported in lib-coap-2.(map,sym)
2021-01-06 10:47:24 +08:00
Jon Shallow f4d4cd60d8 Mbed TLS: Update MbedTLS and mbedTLS to Mbed TLS to reflect brand name
LICENSE:
README.md:
include/coap2/coap_dtls.h:
man/coap_encryption.txt.in:
man/coap_tls_library.txt.in:
src/coap_debug.c:
src/coap_mbedtls.c:

Replace MbedTLS and mbedTLS with "Mbed TLS".
2021-01-04 10:18:26 +00:00
Tim Gates 3e437e6910 docs: fix simple typo, udated -> updated
There is a small typo in include/coap2/coap_asn1_internal.h.

Should read `updated` rather than `udated`.
2020-12-20 07:32:03 +11:00
Jon Shallow 74fbbd3d55 doxygen: Tidy up comments and add in missing modules
Make documentation more consistent across doxygen output.

Add in caching module.
Add in encoding/decoding module.
Add in application i/o internal module.

Move deprecated items out of respective modules.
2020-12-16 12:26:45 +00:00
Jon Shallow a12e573046 Observe: Remove WITHOUT_OBSERVE conditional statements in the library.
As RFC7641 is now fully supported, these code segments should always be
compiled in and WITHOUT_OBSERVE wrappers are no longer required.

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

Remove WITHOUT_OBSERVE wrappers.

include/coap2/async.h:

Correct definition for coap_async_state_t and remove references for
supporting observing as this is no longer supported.
2020-12-09 11:06:49 +00:00
obgm 33ba0fc261 Merge pull request #538 from mrdeep1/endpoint_t
coap_endpoint_t: Update usage of struct coap_endpoint_t to coap_endpoint_t
2020-11-11 20:12:40 +01:00
Jon Shallow 9083189f95 Proxy: Update Proxy support for Proxy-Uri: CoAP option
Add code to better support the Proxy-Uri: and Proxy-Scheme: CoAP Options.

examples/client.c:

Make sure that the Proxy-Uri: option is added (if set) when clearing down an
observation (fixes #112).
Check that Proxy-Uri: option has a maximum data length of 1034 bytes.
Handle user defined Proxy-Scheme: option correctly.
Update -P option to include scheme to be used when connecting to the proxy.

examples/coap-server.c:

Add in hnd_proxy_uri() handler function. This has support for a direct or ongoing
proxy connection for the coap* protocols. The ongoing connection is set up as a
different CoAP session and is assocated with the incoming session for relaying
requests / responses.

Internal functions taken from client.c are used where appropriate.

Proxy support code has a SERVER_CAN_PROXY wrapper, so footprint can easily be
reduced if required.

New -P and -u options added to support ongoing connections.

include/coap2/net.h:

Add in tracking the proxy uri handler into coap_context_t.

include/coap2/resource.h:

Track whether a resource definition is for Proxy-Uri:/Proxy-Scheme:.
Define the coap_resource_proxy_uri_init() function for handling the Proxy-Uri:
option or Proxy-Scheme: option in an incoming request.

include/coap2/uri.h:

Add in COAP_URI_SCHEME_HTTP and COAP_URI_SCHEME_HTTPS as valid Proxy-Uri:
schemes.
Define the coap_split_proxy_uri() function (similar to coap_split_uri() but
supports the proxy extras.  Both now use a common sub function internally.

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

Expose the new coap_resource_proxy_uri_init() and coap_split_proxy_uri()
functions.

man/Makefile.am:

Handle coap_resource_get_userdata(3) now being over the 10 definition limit
in man/coap_resource.txt.in.

man/coap-client.txt.in:

Update documentation for the -P option.

man/coap-server.txt.in:

Document the new -P proxy option.
Document the new -u user option.

man/coap_resource.txt.in:

Include documentation for coap_resource_proxy_uri_init().

src/coap_debug.c:

Output the Proxy-Scheme: Option as text.

src/net.c:

Sanity check and handle COAP_OPTION_PROXY_URI and COAP_OPTION_PROXY_SCHEME
in handle_request().

src/resource.c:

Add in coap_resource_proxy_uri_init() function.
Handle the addition of a proxy uri handler in coap_add_resource().

src/uri.c:

Rename coap_split_uri() to coap_split_uri_sub() and add in extra proxy
handling support based on input parameters.

Create new coap_split_uri() and coap_split_proxy_uri() which call
coap_split_uri_sub() appropriately.

TODO:

Remove reference to Proxy support required

src/coap_gnutls.c:

Fix a double deallocate found during testing
2020-11-11 17:46:17 +00:00
Jon Shallow 8d2a788c1c coap_endpoint_t: Update usage of struct coap_endpoint_t to coap_endpoint_t
Use 'coap_endpoint_t' instead of 'struct coap_endpoint_t' in library source
files where possible.

Remove unnecessary 'struct xxx_t;' forward declarations.

Remove unnecessary 'void coap_free_endpoint(coap_endpoint_t *ep);'
2020-10-22 13:37:47 +01:00
Jon Shallow e5d052cd57 RPK: Move common asn1 code into separate file
src/coap_asn1.c: (New)
include/coap2/coap_asn1_internal.h: (New)

Created and common asn1 functions added in

Makefile.am:
include/coap2/coap_internal.h:

Reference the new files.

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

Updated to use new common asn1 functions.
2020-10-22 12:21:37 +01:00
Jon Shallow 25fbb26c60 RPK: Do not support PKI key type COAP_PKI_KEY_PEM
Support of COAP_PKI_KEY_PEM requires reading files which may not be supported
in libcoap running in a non Posix environment.

Remove RPK support when using PKI key type COAP_PKI_KEY_PEM.  Update
coap-server and coap-client to read the optional .pem files into memory and
use PKI key type COAP_PKI_KEY_PEM_BUF instead.
2020-10-22 12:21:30 +01:00
Jon Shallow d40f2d6a3f RPK RFC7250: Add in support
Currently OpenSSL and MBedTLS do not support RFC7250. See
https://en.wikipedia.org/wiki/Comparison_of_TLS_implementations#Extensions
last column.

GnuTLS >= 3.6.6 required.

TinyDTLS update required.

New option is_rpk_not_cert added to PKI setup structure which is enabled
in coap-client and coap-server by the -M option and the use of a PUBLIC KEY
instead of a CERTIFICATE in the cert file.  If file is EC PRIVATE KEY, then
it can be used for both the public and private key files.

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

Document -M option.

man/coap_encryption.txt.in:
man/coap-server.txt.in:
man/coap_context.txt.in:

Add in documentation for RPK.

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

Add in support for is_rpk_not_cert and -M option.
Stop sending ::1 for SNI - use localhost instead.

include/coap2/coap_dtls.h:

Add in is_rpk_not_cert option.

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

Add in coap_new_binary() and coap_delete_binary() functions.

src/coap_openssl.c:

Report RPK is not supported if invoked.
Check that all received data is used up for error recovery.

src/coap_mbedtls.c:

Report RPK is not supported if invoked.
Handle more MbedTLS generated errors.
Check that all received data is used up for error recovery.

src/coap_gnutls.c:

Add in support for RPK.
Add in sending Hello Verify if not cookie match in Client Hello
Check that all received data is used up for error recovery.

src/coap_tinydtls.c:

Add in support for RPK.

HOWTO.pkcs11:

Update for use with RPK.
Use .der file for '-C ca_file' definitions as later GnuTLS needs CA
to be trusted in HSM.
2020-10-21 15:54:20 +01:00
obgm b8c66fb401 Merge pull request #537 from mrdeep1/deprecated_warnings
Deprecated: Replace deprecated functions in library
2020-10-20 14:46:04 +02:00
Olaf Bergmann 605f990ef6 option.[hc]: remove unused function coap_opt_delta() 2020-10-20 13:16:19 +02:00
Olaf Bergmann b1ee9c8912 options: fix integer overflow in option parser
As the numeric range of CoAP option codes is [0..65804], the data
type for representing these codes must be uint32_t rather than
uint16_t.

Fixes OSS-Fuzz 26371. [1]

[1] https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26371
2020-10-20 13:16:00 +02:00
obgm 4ca959ca53 Merge pull request #499 from mrdeep1/coap_cache
coap_cache: Add in Cache Key and Cache Entry support
2020-10-14 16:32:35 +02:00
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
Jon Shallow 4d039eb01d Options: Sanity check CoAP options in the PDU
include/coap2/pdu.h:
src/pdu.c:
tests/test_pdu.c:

Change parameter max_delta to max_opt to better reflect actual usage.

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

Remove unneeded COAP_OPT_LONG and COAP_OPT_END definitions.

Remove unused function coap_add_option_later().

src/pdu.c:

Update coap_pdu_parse_opt() to sanity check the valid lengths of all the
known options.

src/coap_io_lwip.c:
src/net.c:

Ignore packets < 4 bytes
Send back a RST for UDP/DTLS if malformed PDU.

src/option.c:

Clean up coap_option_filter_get() documentation.
2020-10-14 09:26:27 -04: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 9ee4895797 Merge pull request #540 from mrdeep1/fetch_observe
Observe: Support FETCH
2020-09-10 18:08:46 +02:00
Jon Shallow 26cd2446a8 Deprecated: Replace deprecated functions in library
examples/contiki/coap-observer.c:
examples/etsi_iot_01.c:
include/coap2/coap_prng.h:
include/coap2/net.h:
src/coap_debug.c:
src/coap_openssl.c:
src/coap_session.c:
src/net.c:
src/option.c:
tests/test_error_response.c:
tests/test_options.c:

prng -> coap_prng
prng_init -> coap_prng_init
coap_option_setb -> coap_option_filter_set
coap_option_clrb -> coap_option_filter_unset
coap_option_getb -> coap_option_filter_get

include/coap2/coap.h.windows:
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

prng.h -> coap_prng.h

include/coap2/option.h:

Add in COAP_DEPRECATED in deprecated functions.
2020-09-08 17:21:34 +01: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
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 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 f92bfe9af3 Renamed prng.h to coap_prng.h 2020-06-19 17:51:25 +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 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
Jon Shallow 88151d3eb7 TCP: Prevent incorrectly formed PDUs causing RAM exhaustion.
src/net.c:

Add in a sanity check that the PDU length is not more that the negotiated
CSM size for incoming data.
Track CSM remote supports block transfer.
Do not allow Block options if CSM has not negotiated block transfer.

src/coap_session.c:

Include block-wise-transfer is supported in the CSM

include/coap2/coap_session.h:

Make MTU size bigger than 32 bits as CSM mtu size can be greater than 32 bits.
Track CSM remote supports block transfer.

include/coap2/pdu.h:

Make COAP_DEFAULT_MAX_PDU_RX_SIZE a unsigned long to be bigger than 32 bits.
2020-06-16 08:28:14 +01:00
Olaf Bergmann 6b19f19562 uri.h: improved documentation 2020-06-03 10:06:25 +02:00
Olaf Bergmann 617ac895ec Merge branch 'develop' of github.com:obgm/libcoap into develop 2020-06-03 09:48:17 +02:00
Jon Shallow 9dd16a3260 RFC7872: Add in media type application/dots+cbor
include/coap2/pdu.h:
src/coap_debug.c:

Include in coap_show_pdu() output if appropriate.
2020-06-01 11:29:03 +01:00
Olaf Bergmann 2c7c35cf74 coap.h.in: Set LIBCOAP_VERSION 2020-05-29 08:11:44 +02:00
Olaf Bergmann ffeeee1976 pdu.h: add Content-Format number for application/cwt
RFC 8392 defines the CoAP Content-Format number 61 for application/cwt
(CBOR web tokens).
2020-05-13 16:40:58 +02:00
Olaf Bergmann 93e75e44e3 [RIOT] coap_debug.h: define missing log levels
RIOT defines a subset of the syslog levels in log.h with different
numeric values. The remaining levels are defined here. Note that
output granularity differs from what would be expected when adhering
to the syslog levels.
2020-05-10 20:18:38 +02:00
Olaf Bergmann 789202ccb8 [RIOT] net.h: exclude coap_io_process_with_fds()
RIOT supports fd_set only for BOARD=native. For now,
coap_io_process_with_fds() is completely disabled on RIOT as it is not
yet implemented in coap_io_riot.c, anyway.
2020-05-10 13:46:50 +02:00
Jon Shallow 8559e40cce async: Fix session->ref assertion failure and timeout values
Calling coap_free_context() does not free off any async entries, and so
raises assertion errors when coming to freeing off sessions if any async
entries exist.

async_data_t is a union, but the size of val and ptr are not the same - so
usage can have uninitialized data - hence bad timeout values.

Makefile.am:

Do not expose coap_delete_all*() functions.

examples/coap-server.c:

Fix async_data_t issue.

examples/etsi_iot_01.c:

Fix 32 bit compiler warnings using same logic as coap-server for holding the
async timeout value.

examples/lwip/Makefile:

Include async.c for the LwIP build.

include/coap2/async.h

Define coap_delete_all_async() function.

include/coap2/net.h
include/coap2/resource.h

Document coap_delete_all*() functions as internal.

libcoap-2.map
libcoap-2.sym

Remove non-exposed coap_delete_all*() functions.

src/async.c

Provide coap_delete_all_async() function.

src/net.c

Call coap_delete_all_async() from within coap_free_context().
2020-05-07 09:44:41 +01:00
Jon Shallow f08f9ea86e TCP_DISABLE: reduce more of the dead code when --disable-tcp is in used
src/coap_session.c:
src/net.c:

Wrap more code with #if !COAP_DISABLE_TCP

include/coap2/coap_tcp_internal.h:

Wrap function definitions with #if !COAP_DISABLE_TCP to force compiler
warnings if there still is reference to TCP functions and COAP_DISABLE_TCP
is set.
2020-05-06 10:26:37 +01:00
obgm 8b31d1415a Merge pull request #488 from mrdeep1/riot_base
Merge in riot/posix_sockets branch
2020-05-05 14:25:07 +02:00