Commit Graph
3401 Commits
Author SHA1 Message Date
Jon Shallow 18df85af6d Nits: Fix documentation 2026-09-14 09:52:17 +02:00
Jon Shallow 9c5983b3f2 Responses: RST sent only for CON or NON
Also RST response packets that have no response handling context.
2026-09-14 09:30:18 +02:00
Jon Shallow 68849057f1 Delayqueue: Add delayqueue_tail to coap_session to avoid scanning long queues 2026-09-11 12:30:08 +01:00
Mario Kicherer b20841965e Fix callback data handling for TCP BERT
TCP BERT payloads can exceed the 1024-byte callback scratch buffer. Allocate a temporary buffer sized to the requested chunk, pass it to the large-data callback, and release it after the PDU has copied the data. Preserve the stack buffer for regular block transfers and report allocation failures explicitly.
2026-09-10 17:13:20 +01:00
Jon Shallow fab32682ea coap_pdu_duplicate: Make max size of duplicated PDU same as original
When calling coap_pdu_check_resize(), start with a smaller size for embedded
systems.
2026-09-10 14:59:45 +01:00
Jon Shallow 64211f744e Block1: Handle concurrent transfers over the same session 2026-09-09 14:12:28 +01:00
Jon Shallow 9a27dbd0be OSCORE: Delete association on error response 2026-09-09 14:09:35 +01:00
Magdalena Szumny b61cb7683a Use cryptographic safe entropy for Zephyr 2026-09-08 19:42:10 +01:00
Michiel De Witte e61c8c8ef7 Preserve the observe request's local address for notifications
Packets from the same peer can overwrite a session's local address with a
multicast destination. Save the address when an observation is created or
renewed and restore it before generating notifications, so deferred responses
snapshot the correct address instead of being dropped as invalid multicast.

Add regression coverage for CON and NON observations, including renewals and
the local address captured by a notification's async response.

Validation: 215 unit tests passed (1712 assertions).
2026-09-07 15:58:29 +01:00
Jon Shallow 421107b4b7 Resource: Caution about setting up resources in thread-safe manner 2026-09-07 15:53:01 +01:00
Jon Shallow 73bd9fa543 OSCORE: Remove unnecessary CBOR assert()
Report error when creating AAD or External AAD when CBOR fails.
2026-09-07 15:27:52 +01:00
Michiel De WitteandClaude Opus 5 5e86d78e6d coap_net.c: Do not send an Empty message as a separate response
A request handler that leaves the response code unset asks for no
response to be sent.  That is honoured for a piggybacked ACK (the token
gets stripped, so an empty ACK goes out) and for a non-confirmable or
reliable response (dropped in no_response()), but not for a separate
response set up with coap_register_async().

There the response is turned into a CON, and a 0.00 CON was put on the
wire.  An Empty message is a ping (RFC 7252 4.2), not a response, and the
PDU still carries the request's token, which RFC 7252 4.1 does not allow.
Being confirmable, it was then retransmitted up to MAX_RETRANSMIT times,
usually at a client port that had long gone away.

Drop it like the other two cases, delete it without logging it as a
dropped response since the application asked for this, and document in
coap_handler(3) that a separate response is not sent either.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 15:22:26 +01:00
Jon Shallow 05e9a9caf4 Epoll: Handle server side read errors
Models that done for clients.
2026-09-02 12:59:47 +01:00
Jon Shallow 741729de08 Q-Block: Faster recovery times
Initiate a request for missing blocks if there are missing blocks and the
last 2 blocks of a PAYLOAD_SET are in.
2026-09-02 08:50:49 +01:00
Jon Shallow fcbd803828 Q-Block: Better recovery for lossy networks
Following the principles laid out in RFC9177.
2026-09-02 08:50:49 +01:00
Jon Shallow 2029e51727 coap_pdu.c: Check option lengths when adding options
Support adding options to CSM PDUs.
2026-09-01 20:47:57 +01:00
Jon Shallow 24ae8f2ee8 Block: Make sure SizeX option is added for small sizes with blocks 2026-09-01 20:46:45 +01:00
Jon Shallow dbeedd59b4 OSCORE: Fix observe cancellation when doing Appendix B.2 2026-09-01 15:57:49 +01:00
Jon Shallow 9cb8f45f4f PSK: Support keys in hex notation in matching files
coap-server options
-i match_identiity_file
-s match_psk_sni_file

coap-client option
-h match_hint_file
2026-09-01 11:29:49 +01:00
Jon Shallow beb924545f OSCORE: Fix observe cancellation
Also remove unnecessary COAP_EVENT_XMIT_BLOCK_FAIL events being triggered.
2026-08-31 11:28:30 +01:00
Jon Shallow 44e02b8693 LwIP: Allow smaller initial PDU buffer allocations 2026-08-31 10:46:47 +01:00
Jon Shallow d0605cc5e7 Block: Check for ETag/RTag option size overflow
This is not network exploitable as any incoming packet will fail the
coap_pdu_parse() / coap_pdu_parse_opt_base() check when building the CoAP PDU.
2026-08-29 09:22:01 +01:00
Jon Shallow ee764d94b4 Q-Block: Check for required options
RFC9177 section-4.3.
Q-Block1: Size1 and RTag required.

RFC9177 section-4.4.
Q-Block2: Size2 and ETag required.
2026-08-25 07:49:16 +01:00
Michiel De WitteandClaude Fable 5 091f189e7a Restore the request's local address when a triggered async fires
Server sessions are keyed on (remote address, local port) only, and
session->addr_info.local is overwritten by the destination of every
received packet. When a unicast CON request is parked in a coap_async_t
for a separate response and a multicast packet from the same peer
arrives before the async fires, the re-invoked handle_request() sees a
multicast local address, drops the CON per RFC7252 8.1 ("Invalid
multicast packet received"), and coap_check_async() frees the async:
the response is silently never sent.

Snapshot the local address in coap_register_async() and restore it on
the session before the async fires, so the deferred request is handled
(and its response source selected) against the address it actually
arrived on.

Seen in the field with a CoAP remote control whose GET /endpoint was
answered via the async path while it also multicast periodic
announcements from the same source port: the device received the empty
ACK and then never got the response.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-24 16:35:51 +01:00
Jon Shallow 9d407dd083 Documentation: Updates 2026-08-22 17:42:40 +01:00
Jon Shallow f325f6a4b0 coap_net.c: Enforce response Content-Format matches request Accept option
Only if the request includes the Accept Option and it is not an empty ACK.
2026-08-22 15:09:26 +01:00
Jon Shallow dfe1cd2b93 coap_net.c: Check block options for invalid SZX = 7 2026-08-22 15:06:39 +01:00
Jon Shallow ea841dd0c7 coap_mutex_internal.h: Fix LwIP coap_mutex_destroy 2026-08-20 10:31:27 +01:00
Jon Shallow 850748ca14 Recovery: Support dropping incoming packets for testing 2026-08-20 09:56:09 +01:00
Jon Shallow dfd55459d7 NoTLS: Use SHA1 for digest computations
Removed:
include/coap3/coap_hashkey_internal.h
src/coap_hashkey.c
2026-08-15 15:20:12 +01:00
Jon Shallow 7c456246c9 coap_resource.c: Make Observe deregistration more rigorous 2026-08-15 15:18:46 +01:00
Jon Shallow 3c7742a2ee coap_block.c: Send 2.31 response if duplicate block received
Only happens if the MID is different and this is not the final block.
2026-08-15 15:09:24 +01:00
Jon Shallow d0fa34cf4f coap_resource.c: Update .well-known/core query matching
Support matching multiple, space separated, values, not limited to if=, rt= and rel=.

Fix OOB read if the last space separated value is shorter than the query.

Support matching against multiple queries.

Do not sent back empty 2.05 response if multicast.
2026-08-11 16:09:02 +01:00
Jon Shallow 230979ddba coap_mem.c: Support esp-idf SPIRAM memory allocations 2026-08-08 16:11:53 +01:00
ZT Winds 1c8c8bd3a7 oscore_cbor: fix infinite loop on large CBOR array/map counts
CBOR array and map counts can exceed UINT16_MAX. The uint16_t loop counters
then wrap and never reach the advertised count, causing a CWE-835 denial of
service.

Use size_t loop counters and reject counts that cannot fit in the remaining
buffer at the minimum encoding size of one byte per array element or two
bytes per map pair. Propagate malformed-value errors and cover large
malformed containers and valid values over 64 KiB with regression tests.
2026-08-08 16:11:20 +01:00
Jon Shallow a5803ff733 OSCORE: Boundary check OSCORE option creation 2026-08-08 13:27:40 +01:00
Jon Shallow 98805f70a5 Documentation tidy up
Add in codespell to pre-commit to help fix documentation errors.
2026-08-08 12:05:03 +01:00
Jon Shallow 1394e9833d CI: Cache Contiki/LwIP/Zephyr downloads 2026-08-06 09:55:09 +01:00
kkrentz eafc0230f5 coap_net.c: Avoid divsion by zero if COAP_TICKS_PER_SECOND < 1000 2026-08-01 10:45:44 +01:00
kkrentz bf7323d9a2 coap_net.c: Replace %d with PRIu32 2026-08-01 09:41:23 +01:00
Jon Shallow 7cdc58da69 RIOT: Update Makefile.ci for supported boards 2026-07-30 12:51:48 +01:00
Jon Shallow d4f78cd560 ICMP: Treat genuine ICMP diagnostic PDU for UDP as failure
Posix support only for unicast client requests.

ICMP disgnostic messages are ignored on server sessions.
2026-07-28 16:42:41 +01:00
Jon Shallow f52fadaa9a coap_net.c: For NON responses, use server generated message id 2026-07-25 17:23:48 +01:00
Jon Shallow 0121c25f63 LwIP: Properly seed random number generation 2026-07-25 15:48:45 +01:00
Jon Shallow 463fa7c533 CI: Update to action/cache@v5
Removes CI warnings. Also fix warning for Contiki MacOS build.
2026-07-25 14:31:17 +01:00
Jon Shallow 0014440160 OSS-FUZZ: Stop actual packet transmissions
Make sure all packets are dropped in persist_target.c.
2026-07-25 13:58:10 +01:00
Jon Shallow c056e91ddb tls_backend_testcases.sh: Fix 2.05 code matching time in error 2026-07-25 13:08:46 +01:00
Jon Shallow 54537a38c5 Typos: Fix documentation typos
Includes minor code tidy up.
2026-07-25 12:49:31 +01:00
Jon Shallow 0befa05f48 RIOT: Code tidy following review 2026-07-21 12:30:28 +01:00
94xhn 09e91a2e5c coap_resource.c: harden coap_print_wellknown_lkd() against short attribute values
In the "match attribute" branch of coap_print_wellknown_lkd(), an
attribute value shorter than 2 bytes (e.g. a lone " registered via
coap_add_attr()) causes attr->value->s[0] == '"' to read past the
value, and unquoted_val.length -= 2 to underflow the size_t length
to SIZE_MAX. The resulting bogus coap_str_const_t is then passed to
match(), which dereferences memory far outside the original buffer.

Guard the quote-check on length >= 2 before reading s[0], mirroring
the length && ... guard already used a few lines above for
query_pattern (added in #1977) and the trailing-'*' guard next to
it.

Reproduced with a standalone harness placing a 1-byte attribute
value at the end of a guard-paged region: pre-fix, unquoted_val.length
becomes SIZE_MAX and match() crashes on the guard page; post-fix,
length stays at the original value (no underflow) and match() safely
short-circuits. A normal quoted value ("foo", 5 bytes) still strips
to foo (3 bytes) unchanged, confirming no regression.
2026-07-17 15:24:27 +01:00