Commit Graph
2411 Commits
Author SHA1 Message Date
Jon Shallow 21fd838dc7 coap_io_prepare_io: Re-order function code for correctly updating sockets[]
Two cases for not updating active sockets[] with file descriptors from a
session (non epoll code)
  coap_retransmit() can release a session
  coap_dtls_handle_timeout() can disconnect a session

Move the restransmit test code to before any updates to socket[].

Update coap_dtls_handle_timeout() to return a value indicating a DTLS timeout
has occurred.  At the same time move the coap_dtls_handle_timeout() checks
into the first sessions iteration loop, removing having to iterate through the
sessions twice if DTLS.
2022-05-20 11:10:32 +01:00
obgm 50128de191 Merge pull request #847 from mrdeep1/async_con
net.c: Make sure separate response is CON for CON requests
2022-05-11 15:07:45 +02:00
Olaf Bergmann cfbf3ab617 doc/main.md: Update copyright year 2022-05-11 13:03:51 +02:00
Jon Shallow f28044303a net.c: Make sure separate response is CON for CON requests 2022-05-10 15:25:16 +01:00
obgm abbe3edd5a Merge pull request #795 from mrdeep1/async_fix
async: Handle changes to delay when using epoll
2022-05-06 14:47:39 +02:00
obgm 7404ee172f Merge pull request #833 from mrdeep1/csm_message_size
CSM: Support different XMT and RCV Max-Message-Size
2022-05-06 13:28:27 +02:00
obgm 13f53368c3 Merge pull request #844 from mrdeep1/mutex_fix
recursive mutex: Stop recursive Mutex when doing handler callbacks
2022-05-06 12:10:20 +02:00
Jon Shallow 069a0786ce CSM: Support different XMT and RCV Max-Message-Size
Track the RCV mtu size separately from the XMT mtu, so that sufficiently
large PDUs can be built for receiving incoming data.

Wait until reliable session is complete and the initial CSM have been exchanged
before building any new PDUs for transmission so that they can hold the
appropriate amount of Max-Message-Size data.

Add in support into coap-server and coap-client for defining the
Max-Message-Size to use by adding in 2 new functions
coap_context_set_csm_max_message_size() and
coap_context_get_csm_max_message_size().

Add in flexibility into coap-server to control the initial example_data size.

Requires #844 to prevent recursive mutex locking when initiating proxy ongoing
session to upstream server.
2022-05-04 10:01:37 +01:00
Jon Shallow 9cbe5757cb recursive mutex: Stop recursive Mutex when doing handler callbacks
Move around some of the COAP_CONSTRAINED_STACK mutex locking to prevent
recursive locking (issue when a proxy initiates an ongoing reliable client
connection).
2022-05-04 09:57:34 +01:00
obgm 0691f4ff5d Merge pull request #839 from namib-project/server_session_events
Add events for server session state management
2022-04-29 10:57:15 +02:00
Hugo Hakim Damer d9c19c378f event.h: Add events for server session state management
This commit adds two new events (`COAP_EVENT_SERVER_SESSION_NEW`
and `COAP_EVENT_SERVER_SESSION_DEL`), which are triggered when the
IO loop creates or deletes server-side sessions.
2022-04-29 09:18:51 +02:00
obgm d9fbdba7ec Merge pull request #842 from mrdeep1/sessions_balance
coap_session.c: Balance SESSIONS_ADD and SESSIONS_DELETE usage
2022-04-29 08:58:26 +02:00
obgm a53a026e29 Merge pull request #802 from namib-project/non_vendored_tinydtls
Allow usage of a non-vendored TinyDTLS version when using autotools
2022-04-27 10:23:13 +02:00
Jon Shallow 7e20aa9ef1 coap_session.c: Balance SESSIONS_ADD and SESSIONS_DELETE usage 2022-04-22 13:23:22 +01:00
Hugo Hakim Damer 806861359b configure.ac: Allow using non-vendored TinyDTLS with autotools build
This commit allows using a system-provided version of TinyDTLS when
building libcoap.
To do so, some potentially backwards-incompatible changes to the way
TinyDTLS is handled in the configure-script were made:
- The argument `--with-submodule-tinydtls` is added. If it is set to
  yes, the configure-script will use the TinyDTLS git submodule for
  DTLS functionality (assuming `--with-tinydtls` is also set).
- The configure-script will prefer using the system-provided version
  of TinyDTLS as long as `--with-submodule-tinydtls` is not explicitly
  set to yes.
- It will however fall back to the vendored version by default if no
  system-provided version could be found and if
  `--without-submodule-tinydtls` is not explicitly set.
- If a system-provided version of TinyDTLS was found, it will be used
  automatically if no DTLS backend was selected explicitly (with the
  lowest priority compared to the other DTLS libraries). However,
  the submodule will *never* be used automatically, even if
  `--with-submodule-tinydtls` is set (i.e., to use the submodule,
  `--with-tinydtls` must be set as well).

If TinyDTLS is not installed system-wide (or if the installed version
is too old to contain a pkg-config file), the behaviour should be
identical to older versions.
Otherwise, use the `--with-submodule-tinydtls` option to force usage
of the git submodule version if required.
2022-04-11 19:18:13 +02:00
Hugo Hakim Damer 6c8b76d534 tinydtls: Update to latest version
Update the tinydtls submodule to commit fbf2bd8.
2022-04-11 14:58:42 +02:00
Jon Shallow aa391b5b76 async: Handle changes to delay when using epoll
Add in new function coap_async_trigger() to immediately release an async
session, rather than using coap_async_set_delay(async, 1).

Add new internal function coap_update_epoll_timer() to reduce code
duplication and use it for the async logic.

Move doing coap_io_prepare_epoll() for every epoll event to just doing it once
outside of the loop.

Update documentation.
2022-04-07 13:14:49 +01:00
obgm 20eac7bd2f Merge pull request #773 from mrdeep1/client_repeat_delay
coap-client.c: Delay sending each request using -G by 1 second
2022-04-07 13:58:12 +02:00
obgm f188ae57d8 Merge pull request #840 from mrdeep1/add_data_leak
block.c: Fix data leak in coap_add_data_large_internal
2022-04-07 13:57:22 +02:00
Jon Shallow 65cba25cc7 coap-client.c: Delay sending each request using -G by 1 second
This then allows any (D)TLS to be set up between sending off the requests and
better demonstrates how this can be done in user code.

Allocate separate data for each post/put PDU.

Hold off on starting timer for next transmission until after response has
been received from the server (handles relatively slow DTLS startup).
2022-04-07 09:45:28 +01:00
Jon Shallow d57d44aa14 block.c: Fix data leak in coap_add_data_large_internal 2022-04-07 09:42:27 +01:00
Olaf Bergmann eb7656850f pdu.h: Add Content-Format for application/ace+cbor
RFC 9200 defines the new media type application/ace+cbor for
Authentication and Authorization in Constrained Environments.  The
CoAP Content-Format value for this media type is registered as value
19.
2022-03-15 13:01:04 +01:00
obgm fe0f4ba236 Merge pull request #835 from mrdeep1/mbedtls_fix
coap_mbedtls.c: Fix return brace location
2022-03-04 08:31:36 +01:00
Jon Shallow c8458f262a coap_mbedtls.c: Fix return brace location 2022-03-03 22:02:51 +00:00
obgm 6afee4a9ec Merge pull request #807 from mrdeep1/mbedtls_tcp_fixes
coap_mbedtls.c: Make TLS error recovery more rigorous
2022-02-24 08:42:21 +01:00
Jon Shallow 583c29fd47 coap_mbedtls.c: Make TLS error recovery more rigorous
Support self-signed certificates that have expired.

Correct variable ret initialization in coap_tls_read().

Catch some additional MbedTLS SSL error codes in do_mbedtls_handshake().
2022-02-23 09:30:30 +00:00
obgm 0ae4d62ff4 Merge pull request #828 from laukik-hase/feature/mbedtls_3x_rng_alt
`coap_prng.c`: Added alternate RNG implementation
2022-02-23 10:04:48 +01:00
obgm ecb931db24 Merge pull request #822 from laukik-hase/feature/mbedtls-3.1.0
`coap_mbedtls.c`: Upgrade to mbedTLS `v3.1.0`
2022-02-23 09:54:40 +01:00
Laukik Hase 02deef8da6 coap_prng.c: Added alternate RNG implementation
- For targets having their own hardware entropy/RNG implementation
  using mbedtls_hardware_poll()
- This change was made as since mbedtls-3.x, passing a RNG function
  to all functions that accept a f_rng parameter is mandatory
2022-02-23 09:40:20 +05:30
Laukik Hase 916a534e17 coap_mbedtls.c: Upgrade to mbedTLS v3.x
- Added MBEDTLS_ALLOW_PRIVATE_ACCESS to access private struct
  members wherever required
- Updated deprecated functions from hashing module
  (E.g. mbedtls_sha256_starts_ret() -> mbedtls_sha256_starts())
- Added mandatory RNG parameter for some functions
  (mbedtls_pk_parse_keyfile(), mbedtls_pk_parse_key())
- Remove support for parsing SSLv2 ClientHello
2022-02-22 15:56:27 +05:30
obgm 9727399c0b Merge pull request #832 from obgm/fix-block2-nullref
block.c: Fix possible null-pointer dereference
2022-02-21 17:41:49 +01:00
obgm ee171b2b8c Merge pull request #826 from mrdeep1/proxy_critical_options
Proxy: Support unknown Critical but Safe-To-Forward options
2022-02-21 17:40:03 +01:00
obgm 52c96ba9b3 Merge pull request #829 from mrdeep1/vs_openssl
coap_openssl.c: Support Microsoft VS builds
2022-02-21 14:44:41 +01:00
Olaf Bergmann b42c184f74 block.c: Fix possible null-pointer dereference
Commit 9cb2f62a3 [1] has introduced library-internal handling of
Block1 and Block2 requests. To add the data to the response body the
function coap_add_data_large_internal() is used.

This change calls the function independent of a Block2 request unless
request is NULL. The response code is set to 500 if
coap_add_data_large_internal() failed.

Fixes Coverity-Id 1514379

[1] https://github.com/obgm/libcoap/commit/9cb2f62a3eef2e0aeb682615b785d4734b473bd4
2022-02-21 14:10:16 +01:00
Jon Shallow df72a53f2d coap_openssl.c: Support Microsoft VS builds
Correct reported errors

Update workflow for ms-build to include OpenSSL.
2022-02-21 12:37:44 +00:00
Olaf Bergmann 0f76881802 autogen.sh: Fix missing file ar-lib
After autogen.sh --clean, all auto-generated files need to be
re-created. Before this has happened, autoreconf complains
with

  configure.ac: error: required file 'ar-lib' not found

and signals an error on exit.

This change fixes the issue by touching ar-lib to force creation of an
empty file if it does not exist. Because autoreconf is called with the
options --force --install, this file will get replaced afterwards.
2022-02-21 13:04:49 +01:00
obgm ce88036fc4 Merge pull request #830 from mrdeep1/distribution
doc/Makefile.am: Include module_api_wrap.h in a distribution
2022-02-21 11:02:39 +01:00
obgm 9a0d1c2fe4 Merge pull request #831 from mrdeep1/warn_error
builds: Set CFLAGS += -Werror in all linux subdirectory compilations
2022-02-21 11:01:35 +01:00
Jon Shallow 19928e81bd builds: Set CFLAGS += -Werror in all linux subdirectory compilations 2022-02-18 14:23:43 +00:00
Jon Shallow b2ad43319a doc/Makefile.am: Include module_api_wrap.h in a distribution 2022-02-18 13:34:24 +00:00
Jon Shallow dfc678c33b Proxy: Support unknown Critical but Safe-To-Forward options
The CoAP Proxy may not know how to handle a Critical option, but if it
is safe to forward it should be able to handle this.

RFRC7252 5.4.1
   Critical/elective rules apply to non-proxying endpoints.  A proxy
   processes options based on Unsafe/Safe-to-Forward classes as defined
   in Section 5.7.

If this is an incoming proxy type request special case any
critical options that are safe to forward.

Track ongoing sessions from an enabled proxy server so unknown critical
response options can be passed back to the originating requestor.

Update coap-server to handle Proxy-Scheme for proxying.

Update tests to use critical option 25 instead of 9.
2022-02-18 12:51:35 +00:00
obgm 69b865cd3b Merge pull request #823 from mrdeep1/pdu_setup_docs
coap_pdu_setup.txt.in: Clarify / more make readable the pdu setup information
2022-02-16 09:15:32 +01:00
Jon Shallow 93f2738c45 coap_pdu_setup.txt.in: Clarify / more make readable the pdu setup information 2022-02-14 17:05:00 +00:00
obgm a5eb61d25d Merge pull request #824 from mrdeep1/windows_2022
github workflow: Support windows-2022
2022-02-10 11:15:30 +01:00
obgm f9c3e13a18 Merge pull request #804 from mrdeep1/insert_option
pdu.c: Fix coap_insert_option with delta = 269
2022-02-10 10:21:43 +01:00
Jon Shallow 5b32d716fa github workflow: Support windows-2022
The provided host for windows-latest is migrating across from
windows-2019 to windows-2022 on github.  This allows things to be built on
a windows-2022 system.
2022-02-09 21:44:37 +00:00
Jon Shallow bd9ced550e pdu.c: Fix coap_insert_option with delta = 269
Fix off-by-one error for option delta = 269.

Correct / clarify the tests in coap_insert_option() when working out extended
option delta for inserting new option.
2022-02-09 16:51:39 +00:00
Olaf Bergmann ba585f848f [OSS-Fuzz] pdu_parse_target.c: Check result of coap_pdu_parse()
When coap_pdu_parse() returns 0, the contents of pdu are undefined and
must not be processed. This change proceeds fuzzer tests only if parsing
succeeded.

Fixes OSS-Fuzz issue 44503 [1]

[1] https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44503
2022-02-09 16:34:35 +01:00
Olaf Bergmann a2e0046c80 [OSS-Fuzz] pdu_parse_target.c: Fix compiler warning
Declare prototype for internal function coap_pdu_encode_header().
2022-02-09 16:32:00 +01:00
obgm afb4f2b7a1 Merge pull request #812 from mrdeep1/multiple_sessions
sessions: Prevent multiple client session confusion
2022-02-09 12:38:35 +01:00