Commit Graph
3101 Commits
Author SHA1 Message Date
Jon Shallow 30db3eaa1f coap_address.c: Validate length of provided host name
Host names larger than 255 bytes will cause an internal buffer overflow.

Hostnames provided to coap_resolve_address_info() now have their length validated.

Discovered by SecMate (https://secmate.dev).

Sanity check host lengths when parsing a CoAP URI when using the coap_split_uri()
function.
2025-09-12 13:28:22 +01:00
Jon Shallow 1cae046728 CMakeLists.txt: Remove need for deprecated CMP0115 2025-09-05 16:48:37 +01:00
Jon Shallow b47c82535c coap_net.c: Include MID check in coap_pdu_cksum() 2025-09-05 16:45:01 +01:00
Jon Shallow da534de75e OSCORE: Fix OSCORE configuration file parsing issue
With a large boolean parameter value, (longer than "false"), memory
would be read past the "true" or "false" string boundaries in the ".rodata"
section when doing a memcmp(), potetially causing the application to crash
when calling coap_new_oscore_conf() with a specially crafted configuration
file.

It also can provide a mechanism to determine the byte values following the
"true" or "false" string boundaries which could lead to accessing sensitive
information. The standard libcoap library does not have defined keys or
certificates. This can only be done by a specially crafted local application.

Discovered by SecMate (https://secmate.dev).

Now fixed.
2025-09-05 16:16:32 +01:00
Jon Shallow 56a90642d3 coap_session.c Fix CID update check 2025-09-05 16:11:17 +01:00
Jon Shallow ea01661faf Zephyr: Support C++ builds
Some of the Zephyr include files need to be C++, not C based. The 'extern "C"'
wrapper in include/coap3/coap.h means that all #include are treated as being C.

Remove 'extern "C"' wrapper from include/coap3/coap.h and add wrapper to
include files after #include and before any function / structure definitions.

Add in a C++ build test for CI.
2025-08-21 12:17:41 +01:00
Jon Shallow 7dff177f29 Sockets: Update documentation
Separate out the Datagram (UDP) and Stream (TCP) socket documentation.

Add in a Doxygen Datagram (UDP) topic.
2025-08-18 17:24:36 +01:00
Sandro Scherer f438c61b6e Zephyr: improve POSIX API integration 2025-07-30 11:38:44 +01:00
Jon Shallow 690e5fa8aa coap_block.c: Stop premature deletion of lg_srcv 2025-07-22 11:23:15 +01:00
fj-blanco 022e848da4 Zephyr: Add wolfSSL DTLS backend support
- Add wolfSSL detection and configuration in zephyr/CMakeLists.txt
- Set wolfSSL to take priority over mbedTLS when both are available
- Bypass find_package() call and link wolfSSL library directly
- Prevent system wolfSSL library conflicts with ZEPHYR_BASE checks
- Fix compiler warnings in coap_wolfssl.c for unused functions
2025-07-21 08:43:13 +01:00
Jon Shallow 79a041414c Zephyr: Enable CI builds
Fix a Zephyr unexpected success response for ioctl FIONBIO.
2025-07-19 12:17:38 +01:00
Jon Shallow b359512f8d coap_block.c: Fix ETag generation for CoAP responses
If the response code in the PDU was not set before calling
coap_add_data_large_response(), the ETag option was not getting
set.
2025-07-19 12:04:23 +01:00
Jon Shallow 433f483f2c WIN32: Support determining local broadcast addresses 2025-07-12 13:09:26 +01:00
Jon Shallow c9a162b610 MinGW: Add in more CI workflow builds 2025-07-09 14:55:18 +01:00
Jon Shallow df0b820d88 coap_threadsafe.c: Support Visual Studio builds
Fix missing external references
2025-07-09 10:54:26 +01:00
Jon Shallow f62c836ece coap_resource.c: Make dynamic resource handling thread safe
Let libcoap do the necessary multi-thread locking during resource
generation, lookup and deletion.

Supported using a new handler set up by coap_register_dynamic_resource_handler().
2025-07-08 13:37:57 +01:00
Jon Shallow 33b3f02006 coap_session.c: Clean up session close down order 2025-07-07 17:55:46 +01:00
Jon Shallow 6d322e1f1c coap_io.txt.in: Fix some compiler errors when building examples
The variable name of socket creates issues for some compilers.
2025-07-07 17:54:04 +01:00
kkrentz 71d16929dd coap_net: Use platform-independent format specifier 2025-07-03 09:43:37 +01:00
Jon Shallow d33b7fa571 coap_session.c: Support converting a Client session to a Server session
Server to Client is already supported, this provides the reverse with
coap_session_set_type_server().

Add in call-home support to coap-client and coap-server for testing.

Addition of a new event COAP_EVENT_SERVER_SESSION_CONNECTED.
2025-07-02 17:41:07 +01:00
fj-blanco 4fa3dfa0c7 Zephyr: add POSIX API support
Changes:
- Remove duplicate OBSERVE_PERSIST configuration block

Improve example build:

- Make virtual environment activation optional in Makefile
- Remove --fresh flag unsupported in newer west versions
- Copy mbedTLS config header to workspace include directory
- Add TARGET check for mbedTLS before configuring include directories
- Add mbedTLS linking to coap-3 target

Add POSIX API support:

- Enable CONFIG_POSIX_API=y in examples/zephyr
- Replace direct Linux/Windows system calls with Zephyr POSIX API
equivalents
- Add Zephyr's sys_rand_get() to coap_prng_default()
- Define missing network macros (IN_MULTICAST, IN6_IS_ADDR_MULTICAST,
etc.)
- Add FIONBIO and OPTVAL_T/OPTVAL_GT macro definitions for Zephyr
- Add native Zephyr timing functions to replace missing mbedTLS timing
support
- Fix fd_set mapping using zephyr/net/socket_select.h
- Exclude strnlen redefinition conflicts for Zephyr
- Add proper IPv6 packet info and address mapped definitions

(Patch) Add DNS resolution and net setup to example client:
- Enable CONFIG_DNS_RESOLVER for hostname resolution
- Add Linux networking setup instructions for native_sim board
- Configure static IP gateway and DNS server (8.8.8.8)
- Add DHCP vs static IP configuration documentation
Co-authored-by: mrdeep1
2025-06-26 15:23:23 +01:00
Jon Shallow cf45e84be2 coap_io.c: Cleanup MinGW builds
Move the MinGW #if tests to after where mswsock.h is included.

Tidy up documentation.

Tested against MSYS2 UCRT64, CLANG64, MINGW32 and MINGW64 on Windows 11.
Fixed a couple of minor build issues found.
2025-06-26 15:17:48 +01:00
Jon Shallow 2dac61cf50 LwIP: Update to STABLE-2_2_1_RELEASE 2025-06-21 12:20:16 +01:00
Jon Shallow 68c3e861ed src/coap_net.c: Make CSM Max-Message-Size handling more generic
Cater for environments like ESP-IDF which use LwIP under the hood.
2025-06-21 11:55:38 +01:00
Jon Shallow f28f4109ec coap_check_async: Fix async callback timing window
Multiple threads can call coap_check_async() when one of them does a callback
into application space. Only allow one thread to be scanning async_state.
2025-06-20 19:23:02 +01:00
Jon Shallow e6883c3d67 coap_mbedtls.c: Fix SNI hostname definition if not provided
MbedTLS based PKI clients may report

SSL - Attempt to verify a certificate without an expected hostname.
This is usually insecure.  In TLS clients, when a client authenticates a
server through its certificate, the client normally checks three things: ....

The application provided client_sni may have been removed as per
https://datatracker.ietf.org/doc/html/rfc6066#section-3

   Literal IPv4 and IPv6 addresses are not permitted in "HostName".

and so MbedTLS is now explicitly told that therw is no hostname.
2025-06-20 16:30:52 +01:00
Jon Shallow 7889db616a coap_net.c: Set remote CSM Max Message Size to local max if bigger
Prevent remote endpoint from setting Max Message Size to be larger
than the local endpoint can handle.
2025-06-20 16:10:15 +01:00
Jon Shallow 1b790ea800 coap-server: Sanity check maximum value of server new base time
Check for time overflow in hnd_put_time.
2025-06-18 10:07:58 +01:00
Jon Shallow e5f268fd5d coap_io.c: Support MinGW build with _WIN32_WINNT == 0x0a00 2025-06-17 09:57:27 +01:00
Jon Shallow 17c3feeb08 coap_session_mfree: Check for lg_crcv all cleared out if failure
Call to coap_cancel_observe_lkd() may cause session->lg_crcv to be cleared
out if transmission failure.
2025-06-12 13:55:53 +01:00
Jon Shallow 06ff7e092b Proxy: Remove proxy subscribe on unsolicited response timeout
Also handle large upstream stream packets being converted to downstream
datagram packets.
2025-06-09 10:25:34 +01:00
Jon Shallow 1ed516a2bf MinGW: Fix latest MinGW support build 2025-06-09 10:15:04 +01:00
Jon Shallow d328fc5330 OSCORE: Handle extended tokens when Echo option is returned for B.1.2 2025-06-03 21:35:56 +01:00
@pawel.szwarnowski 67a38770a1 OSCORE: Validate a non-OSCORE response to an OSCORE request 2025-05-27 12:36:49 +01:00
Jon Shallow 358da10706 Proxy: Correctly handle OBSERVE cancellations 2025-05-26 17:04:04 +01:00
Jon Shallow 9f3c1301b8 Proxy: Flush out all proxy requests for proxy entry 2025-05-23 15:50:43 +01:00
Jon Shallow 396dbacfe2 LwIP: Fix locking
In particular for TCP support.

Also added in retrying to get the lwip git 3 times for the CI tests as the
lwip host server is currently not that reliable, returning 502 gateway errors.
2025-05-22 17:06:34 +01:00
Mario Kicherer 8401ff1ffe coap_session.c: fix free callback for endpoint app data 2025-05-22 12:26:44 +01:00
Jon Shallow 3ebb745c91 coap_session.c: Fix coap_lock_lock() issue 2025-05-22 08:41:53 +01:00
Mario Kicherer 0ec5f799f2 add coap_session_get_endpoint, coap_endpoint_get_app_data and coap_endpoint_set_app_data 2025-05-22 08:20:45 +01:00
Jon Shallow ce2057b7a9 Locking: Remove context from a subset of the lock function macros (3 of 3)
Makes reading the code simpler.

Context is no longer used as global_lock is used in the coap_lock_lock() and
coap_lock_unlock() functions.

Part 3 of 3.

Update coap_lock_lock() and coap_lock_unlock() macros and all users.
2025-05-21 16:50:00 +01:00
Jon Shallow 882cd6b735 Locking: Remove context from a subset of the lock function macros (2 of 3)
Makes reading the code simpler.

Context is no longer used as global_lock is used in the coap_lock_lock() and
coap_lock_unlock() functions.

Part 2 of 3.

Update coap_lock_check_locked() and all users.
2025-05-21 15:49:40 +01:00
Jon Shallow ccf53a41af Locking: Remove context from a subset of the lock function macros (1 of 3)
Makes reading the code simpler.

Context is no longer used as global_lock is used in the coap_lock_lock() and
coap_lock_unlock() functions.

Part 1 of 3.

Update coap_lock_callback(), coap_lock_callback_ret(),
coap_lock_callback_release(), coap_lock_callback_ret_release() and
coap_lock_invert() macros and all users.
2025-05-21 14:54:54 +01:00
Jon Shallow 8975c15cd8 coap_resource.c: Fix observe callback timing window
If multiple clients subscribe to the same resource, one of the clients
'goes away', the server will eventually close down the session for that client
which will then remove any subscriptions, iterating through the different
resources.

If this happens at the same time that coap_resource_notify_observers() is called
in another thread, and the GET/FETCH handler is called for a common resource
and in particular for the session that is now going away, on return from the
callback the subscription may no longer exist.  This PR fixes this window.

In addition, if the resource subscriber list is being traversed, then a another
call to coap_notify_observers() for the same resource will not generate a new set
unsolicited observe responses for multi-thread protection.

Update
2025-05-20 15:25:31 +01:00
Jon Shallow 24ec7b19bf RIOT: Fix building RIOT with RIOT's utlist.h change 2025-05-20 11:46:26 +01:00
Jon Shallow 0c18ad5228 coap_net.c: Remove timing window for tcp based session reads
Clear session->partial_pdu before calling coap_dispatch().
2025-05-20 10:53:10 +01:00
Jon Shallow 60e9f08e47 LwIP: Fix TCP support 2025-05-16 14:40:52 +01:00
Jon Shallow 07c880b56e coap_pdu.c: Report options with invalid length
Malformed PDUs were responsed to with a RST.  Now request PDUs with invalid
lengths are also reported with a 4.02 response.

See RFC7252 5.4.3 and 5.4.1.
2025-05-16 10:01:11 +01:00
Mario Kicherer 1f3f881656 remove SNI caching for OpenSSL >= 1.1.1 2025-05-16 09:58:58 +01:00
Jon Shallow 551a71572a coap_openssl.c: Fix OpenSSL < 1.1.1 builds 2025-05-16 08:31:39 +01:00