Skip to content

Fix unsigned CoAP sizes and Observe deadlines; randomize automatic tokens - #38

Merged
maikebing merged 4 commits into
masterfrom
codex/coap-next-batch-20261113
Nov 13, 2026
Merged

maikebing merged 4 commits into
masterfrom
codex/coap-next-batch-20261113

Conversation

@maikebing

Copy link
Copy Markdown
Member

Large Size1/Size2 values could be read as negative numbers or truncated, and legal Observe Max-Age values could overflow the re-registration timer. This change preserves the complete UInt32 option range through typed APIs, Resource/MVC binding and blockwise assembly, and schedules Observe refreshes from a monotonic deadline with one bounded timer.

Automatic request tokens now use RandomNumberGenerator.GetBytes(8). Explicit tokens and existing retransmission, Block1/Block2 and Observe identities are retained. Actual DTLS session/traffic-key identity is not available in the channel/exchange contract, so RFC 9175 secure-context non-reuse remains UNKNOWN; #33 and its umbrella #23 stay open.

Compatibility: existing signed Size1/Size2/IntValue APIs and signatures retain their four-byte bit patterns. New callers can use UIntValue and Size1Unsigned/Size2Unsigned. Overlong raw typed values now throw OverflowException. Size estimates remain metadata; they do not control allocation or replace the Block M bit.

Validation on Windows Release with TreatWarningsAsErrors=true:

  • Full default CoAP.Test: 481/481, no failures or skips.
  • Full COAPALL: 491/491.
  • COAP03/08/12/13 focused legacy plus affected tests: 101/101 each.
  • Affected focused integration: 86/86.
  • Default Resource/MVC sample: 0 warnings, 0 errors.
  • Owned-path dotnet format and CRLF-aware staged whitespace check passed.

Original failing reproductions, exact commands and source hashes are recorded in docs/audits/coap-20261113/next-batch-validation.json and next-batch-execution.json. The first COAPALL failure exposed an old fixture using a string for integer Content-Format; it now uses MediaType.TextPlain. Independent review also corrected the host fixture to use request Size2=0 as RFC 7959 requires.

The pinned libcoap v4.3.5 / Californium 3.13.0 UDP/DTLS matrix is NOT_RUN: peer commands and images are unavailable in the checked environment. #26 stays open. NativeAOT execution, package publication and device/field qualification remain separate and NOT_RUN. No tag, NuGet publication or deployment is part of this PR.

Closes #34
Closes #35
Refs #23, #26, #33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues require resolution before approval.

No open issues 🎉

What changed in this PR

This PR fixes unsigned size handling and long Observe deadlines in CoAP.NET, while preserving existing signed APIs and request identities.

Changes:

  • Adds full-range unsigned option APIs, Resource/MVC binding, and size-hint preservation during blockwise assembly.
  • Uses monotonic Observe deadlines with bounded timer intervals and terminal-state cleanup.
  • Generates automatic eight-byte tokens with the platform cryptographic random generator, with regression tests and compatibility documentation.

DTLS traffic-key-context token non-reuse remains unresolved. External interoperability, NativeAOT execution, package publication, and field qualification remain outside the reported validation.

File Description
ROADMAP.md Summarizes implementation status and remaining validation gates.
README.md Introduces unsigned sizes, bounded deadlines, and token changes.
HANDOFF.md Records implementation details, validation, and follow-up work.
docs/​coap-standards-roadmap.md Updates standards issue status and interoperability limits.
docs/​coap-options-compatibility.md Documents API compatibility and remaining protocol work.
docs/​audits/​coap-20261113/​next-batch-validation.json Records validation results and unexecuted gates.
docs/​audits/​coap-20261113/​next-batch-execution.json Captures source hashes, commands, and execution receipts.
CoAP.Test/​UnsignedOptionTest.cs Tests unsigned boundaries, signed compatibility, and overflow rejection.
CoAP.Test/​UnsignedOptionHostingTest.cs Tests reflection and generated unsigned option binding.
CoAP.Test/​UnsignedBlockwiseSizeTest.cs Tests size-hint retention without size-driven allocation.
CoAP.Test/​TokenGenerationTest.cs Tests automatic tokens and preservation of existing identities.
CoAP.Test/​ObserveLongDeadlineTest.cs Tests deadline boundaries, updates, cancellation, and cleanup.
CoAP.Test/​EndpointOwnedExchangeTest.cs Updates Observe cleanup coverage for the new timer behavior.
CoAP.Test/​Codec/​MessageTest.cs Corrects Content-Format to use an integer media-type value.
CoAP.NET/​Stack/​TokenLayer.cs Replaces counter-based tokens with cryptographically random bytes.
CoAP.NET/​Stack/​ObserveLayer.cs Implements monotonic deadlines, bounded scheduling, and timer cleanup.
CoAP.NET/​Stack/​BlockwiseStatus.cs Stores unsigned size hints as scalar metadata.
CoAP.NET/​Stack/​BlockwiseLayer.cs Preserves size hints when assembling incoming blocks.
CoAP.NET/​Server/​Routing/​CoapGeneratedEndpointHelpers.cs Adds unsigned option conversion for generated endpoints.
CoAP.NET/​Server/​Routing/​CoapActionParameterBinder.cs Adds unsigned option conversion for reflection binding.
CoAP.NET/​Option.cs Adds unsigned access and typed integer-width validation.
CoAP.NET/​Message.cs Adds unsigned size properties and unsigned Max-Age reading.
CHANGELOG.md Summarizes behavior changes, compatibility, and validation limits.

Review effort: Balanced

@maikebing
maikebing merged commit 1d6fa2c into master Nov 13, 2026
5 checks passed
@maikebing

Copy link
Copy Markdown
Member Author

Delivery readback for this batch:

The checked-in HANDOFF/audit files record the pre-push candidate snapshot. This comment is the subsequent CI/merge/issue/worktree readback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants