OscoreClient
The OSCORE client side for the CoAP stack: protects requests with the context contexts picks and verifies the responses, including Observe notifications with their replay protection (RFC 8613 §4.1.3.5.2, §7.4.1).
Replay of responses (§7.4). A response is bound to its request, and a request takes one response, so a second response to the same request is rejected, with or without a Partial IV. Two kinds of request take several:
An Observe registration takes notifications: at most one without a Partial IV, which counts as the oldest (§4.1.3.5.2), and the others with a Partial IV above the Notification Number (§7.4.1, §8.4.2). A response without an Inner Observe option is verified as a non-Observe response (§4.1.3.5.2), so it takes one of those, which ends the observation.
A request carrying an Inner Q-Block1 or Q-Block2 option (RFC 9177 §4) takes the responses of its body: the blocks of a Q-Block2 set and the sets that follow on its token, or a 2.31, 4.08s and the final response on the token of a Q-Block1 block (§4.3, §4.4, §10). At most one of them may reuse the request's nonce, without a Partial IV (§8.3 step 3); every other one must carry a Partial IV the request has not seen, within SecurityContextParameters.replayWindowSize (32 by default, §3.2.2) of the highest it has seen. That is an RFC 6347 sliding window per request, like the server's per context, so the blocks of a set may arrive in any order. A replayed or too old block is dropped like a response that fails verification (§8.4 step 8), and its body asks for it again (RFC 9177 §4.4).
Notification bodies (RFC 9177 §4.5). A registration that carries Inner Q-Block gets its notifications as Q-Block2 bodies, and every block of a body is a notification with a Partial IV of its own (§4.1.3.5.2), so a block overtaken by a later one arrives below the Notification Number. §7.4.1 requires only that a Partial IV received before is refused; refusing everything at or below the Notification Number is a rule it lets an application choose, and for such a registration it would drop every block that arrives out of order. Its notifications are therefore checked against the request's window, like the other responses of a Q-Block body, and freshness, which §4.1.3.5.2 takes from the highest Partial IV whatever the order of arrival, is decided per body: the blocks of one body carry one ETag (RFC 9177 §4.4) and one Observe value (§4.5), which makes them one notification. A notification below the Notification Number passes only as a block of the body whose block holds the highest Partial IV so far; a block of an older body, an older notification of one message, or one without a Partial IV once a later one came, is stale and dropped. So the stack gets only notifications that are the freshest or part of the freshest body, as ProtectedRequest.unprotectResponse asks. A registration without Inner Q-Block keeps the strict order.
Several responses to one request fall outside RFC 8613's single-response model, so the CoAP stack uses Q-Block under OSCORE only where both sides opt in (QBlockClientConfig.withMessageSecurity and QBlockServerConfig.withMessageSecurity of kcoap-coap); otherwise protected bodies use Inner Block1 and Block2 (RFC 7959; RFC 8613 §4.1.3.4.1), one response per block.
Unprotected responses are not authenticated (UnprotectedResponses). The unprotected 4.xx and 5.xx errors of OSCORE and of intermediaries (§8.2) are handed on as ResponseVerification.Unverified, to every request alike, and the stack acts on nothing in them: it ends a request that has no verified response yet, and an established observation ignores them (ADR 0008). Any other unprotected response is dropped like one that fails verification.
No context. A request for which contexts returns null fails with MessageSecurityException before anything is sent, so a missing context never sends plaintext silently; kcoap-coap's client reports it as CoapException.Reason.SECURITY with it as cause, as it does any failure here. With allowUnprotected, null sends the request unprotected instead, for a client that talks OSCORE to some servers and plain CoAP to others.
Parameters
whether a request contexts finds no context for goes out unprotected; false by default, which fails it.
Constructors
Protects every request with context.