Repository navigation
feat(headers): receipts, vds, vdp and RFC9162_SHA256 inclusion proofs (RFC 9942) (#218) - #221
Merged
Merged
Conversation
15 tasks done
Spomky
added a commit
that referenced
this pull request
Sep 13, 2026
doc/Usage.md (2600 lines) becomes fourteen chapters under doc/, with doc/README.md as the index: Installation, Messages, Signing, Countersignatures, Mac, Encryption, KeyManagement, Cwt, X509, HashEnvelope, Receipts, Algorithms, Keys and Upgrading. README.md keeps the introduction, the list of RFCs, the chapter table and the points to know before relying on the library; the algorithm and key tables live in doc/Algorithms.md and doc/Keys.md only, and RfcReferencesTest now checks them there — and checks that no other document carries a copy. The chapters cover everything merged since the split was started: RFC 9995 (hash envelope, #220), RFC 9338 (countersignatures, #222), RFC 9964 (ML-DSA and AKP keys, #223) and RFC 9942 (receipts, #221), each on its own page or in the Algorithms and Keys chapters, with the header table, the structures table, the doc index and the platform-gate table updated accordingly. RELEASES.md links point at the new chapters and its support matrix lists the 4.9.x line only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Target branch: 4.9.x
Resolves issue #218 (Closes #218)
Part of #202
What
The COSE receipts of RFC 9942: the
receipts(394),vds(395) andvdp(396) header parameters, and the one registered verifiable data structure,RFC9162_SHA256(vds= 1), with its inclusion and consistency proofs — the consistency verification fitted in the same class without contortion, so it is in (the issue left it optional). Everything is additive: new classes, new constants, new methods, two formerly private helpers made public; no existing public signature changes, no new dependency.CoseHeadersgetReceipts(): list<CBOR\Tag\CoseSign1Tag>— protected bucket first (§4.3 registers the parameter "in the protected and unprotected headers"), an empty list when absent so the caller can iterate without a check. Each entry isbstr .cbor Receipt: an empty byte string or trailing bytes after the item make it malformed, and "Receipts MUST be tagged as COSE_Sign1" — an untagged array, aCOSE_Mac0(17) or a CWT (61) around the message are rejected by name. AGenericTag18 (decoder without the class) is rebuilt asCoseSign1Tag.getVds(): ?int— protected bucket only, as §5.2.1/§5.3.1 require ("The VDS in the protected header is necessary to understand the inclusion proof structure"); an unprotected copy is ignored, not refused. Handed back as carried; the registry check happens where the proofs are read.getVdp(): ?MapObject— the proof map as it travels, keys checked to be labels. The CDDL puts it in the unprotected header; a protected one is read too, first (a proof gains nothing from the signature — the root it leads to is what is signed).LABEL_RECEIPTS,LABEL_VDS,LABEL_VDP.Cose\Structure\VerifiableDataStructureRfc9162Sha256IDENTIFIER1,NAME,LABEL_INCLUSION_PROOF-1,LABEL_CONSISTENCY_PROOF-2,HASH_SIZE).leafHash(),nodeHash(),emptyTreeHash(),treeHash(...$entries)(RFC 9162 §2.1.1–2.1.2, stack algorithm).inclusionProofs(CoseHeaders)/consistencyProofs(CoseHeaders)read the proofs of a receipt after checkingvds === 1and everyvdpkey against the proof registry — §4.3: "the verifier MUST confirm that the associated VDS and VDPs match entries present in the registries". An unregisteredvds(0 reserved, 2, …) or proof label (-3, 0,"inclusion") is anInvalidArgumentExceptionnaming the value, never skipped.Rfc9162Sha256InclusionProof[ tree-size: uint, leaf-index: uint, inclusion-path: [ + bstr ] ]wrapped in a byte string (§5.2).root($entry): ?stringapplies RFC 9162 §2.1.3.2 and returns the tree head ornull(leaf-index ≥ tree-size — the RFC's own guard —, path of the wrong length);verify($entry, $root)withhash_equals();rootFromLeafHash()/verifyLeafHash()for callers holding the leaf hash. Nodes are checked to be 32 bytes;uintbeyondPHP_INT_MAXrefused.Rfc9162Sha256ConsistencyProof[ tree-size-1, tree-size-2, consistency-path: [ + bstr ] ](§5.3).newerRoot($olderRoot): ?stringapplies RFC 9162 §2.1.4.2 and returns the newer tree head the proof binds the older one to (the payload of a receipt of consistency, §5.3.1) ornull;verify($older, $newer). Defined for0 < first < secondonly; an empty path is refused on decode and on construction (CDDL+, and step 1 of the algorithm).ReceiptVerifiercreate(Manager, ?Decoder),verifyInclusion(CoseSign1Tag, string $entry, Key, ?ByteStringObject $externalAad): bool,verifyConsistency(CoseSign1Tag, string $olderRoot, Key, ...). The two steps of §5.2 as one boolean (§5.3.1: "It is recommended that implementations return a single boolean result"): proof → tree head →Signature1over it →Signature::verify(), the algorithm resolved from the receipt'salgthrough the operator'sManager(same reasoning asCertificateSignatureVerifier:algcomes from the wire and cannot select an unregistered verifier; HS256 registered under 5 is refused as "not a signature algorithm"). Several proofs in one receipt: verifies as soon as one leads to a signed root. An attached payload (§4.4 says SHOULD be detached) has to be the tree head the proof leads to, else the receipt fails.HeaderMapHelpergainsdecodeEmbedded()(abstr .cborvalue under the rulesdecodeProtected()already applied: one item, no trailing bytes, no empty string;decodeProtected()now delegates to the same private routine) andtagNumber()goes public (was private) to recognize aGenericTag18.Three decisions the issue did not settle
inclusion-pathis accepted. RFC 9942 §5.2 writes[ + bstr ], but points to RFC 9162 §2.1.3.1 for "a complete description of this VDS Proof Type", and that section definesPATH(0, {d[0]}) = {}— the only leaf of a one-entry tree has an empty proof. The reference implementation (transmute-industries/cose) encodes whatever the log gives it and would emit[]for the first entry of any log. Rejecting it would refuse the first receipt every log issues, for no security gain: the RFC 9162 walk then succeeds for tree size 1 and nothing else (theEmptyProofOfASingleLeafTreeVerifies). Documented in the class, indoc/Usage.mdand inRELEASES.md; a one-line change if you want the CDDL applied literally. The consistency path, by contrast, is never empty (RFC 9162 §2.1.4.2 step 1 agrees with the CDDL) and is refused.tree-sizeis not bound by the signature. RFC 9942 signs the tree head alone. A proof for leaf 5 of 8 also "verifies" under tree size 7 (6 and 7 shift to the same bits): the size steers the walk and is otherwise the issuer's word. Documented (theTreeSizeSteersTheWalkAndIsNotOtherwiseBound), since a reader could take it for a bug.root()/newerRoot()returnnullwhen the proof leads nowhere andverify*()returnfalse, likeSignature::verify(); an argument that makes the walk meaningless (a leaf hash or an older tree head that is not 32 bytes) throws, like the rest of the library.ReceiptVerifierthrows when the receipt is not a receipt of the requested kind for a registered structure, and returnsfalsefor every cryptographic or proof failure.Acceptance criteria of #218
h'fc9f050f...221c92cb'), so the examples cannot be pasted; the tests rebuild them with the exact shapes the RFC prints — Figure 2: a message with two receipts, size 9 / leaf 8 / one node and size 6 / leaf 5 / two nodes, detached payloads, ES256,vds1 in the protected header,vdpin the unprotected one (CoseHeadersTest::theReceiptsOfTheRfc9942ExampleAreReadFromEveryMessageType, on all six message types, through the bytes); §5.2: size 20 / leaf 17 / three nodes; §5.3.1: old 20 / new 104 / six nodes — and check thatPATH/PROOFof RFC 9162 give exactly that many nodes for those parameters (they do).testdata/, commita09734c, Apache-2.0, LICENSE + README vendored undertests/fixtures/rfc9162/) run inRfc9162FixtureTest: everywantErrprobe is refused or fails, every happy path verifies. Two probes rely on the upstream extensionfirst == secondwith an empty path (an equality check, outside RFC 9162's0 < first < secondand the CDDL) and are asserted as refused, with the reason in the fixtures README. The eight CT tree heads (6e340b9c…, …,5dc9da79…) are reproduced bytreeHash(), and the seven-leaf example tree of RFC 9162 §2.1.5 gives the proofs the RFC spells out by node name (d0 → [b, h, l],PROOF(3, D[7]) = [c, d, g, l], …).leaf-index,leaf-index >= tree-sizefail —Rfc9162Sha256InclusionProofTest, plus every leaf of every tree size up to 40 against proofs produced by the recursive definitions (test helperMerkleTree, which implementsMTH/PATH/PROOFof RFC 9162 independently of the stack algorithm of the library), and every pair0 < older < newer ≤ 40for consistency.vdsis rejected —Rfc9162Sha256Test(0, 2, 1000, -1),ReceiptVerifierTest, and the example.doc/Usage.md([!IMPORTANT]block plus "four points that follow from the RFC"),ReceiptVerifierandRfc9162Sha256docblocks.Tests
tests/Structure/VerifiableDataStructure/:Rfc9162Sha256Test,Rfc9162Sha256InclusionProofTest,Rfc9162Sha256ConsistencyProofTest(wire forms incl. indefinite-length, every malformed CDDL shape with its message, 2⁶⁴−1 refused, the failures above),Rfc9162FixtureTest(186 probes),ReceiptVerifierTest(detached/attached/mismatching payload, tampered proof, other entry, other key,external_aad, several proofs, consistency, a receipt read out of a message, unregisteredvds/label, missing/text/unregistered/non-signaturealg).CoseHeadersTest(+11: Figure 2 on six message types, protected bucket,GenericTag18, nine invalidreceiptsshapes,vdsbucket rules and range,vdpbucket rules and labels),HeaderMapHelperTest(+6),RfcReferencesTestknows RFC 9942,ExamplesTestrunsexamples/17-receipts.php.Docs and examples
README (This library implements, Features, Documentation, new COSE Receipts section),
doc/Usage.md(new COSE Receipts section under Reading Headers, TOC, Common Header Parameters rows 394–396, examples table, References incl. RFC 9162),RELEASES.md,composer.jsonkeywordRFC9942,examples/17-receipts.php(issues and verifies a receipt of inclusion and a receipt of consistency over the eight-leaf CT tree, shows a tampered proof, an unregistered structure and where the library stops) + index.