Repository navigation
feat(headers): X.509 header parameters x5bag, x5chain, x5t, x5u (RFC 9360) (#196) - #212
Merged
Merged
Conversation
15 tasks done
Every earlier release verifies a certificate signature over a re-encoded tbsCertificate, so a certificate that is not strict DER -- the cose-wg x509-examples, whose keyUsage BIT STRING carries a spare byte -- fails path validation with "Certificate signature doesn't match". 1.6.2 verifies the bytes as carried, and is the only supported line: its release notes close 27 advisories affecting <= 1.6.1 and declare 1.0.x to 1.5.x end of life. Fixes the lowest-deps job of the CI.
5 of 8 tasks
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 #196 (Closes #196)
Part of #202
What
The X.509 header parameters of RFC 9360:
x5bag(32),x5chain(33),x5t(34) andx5u(35), with the*-senderlabels of §3 declared. Everything is additive: new classes, new constants, new methods, no existing public signature changes.Cose\Structure\X509CoseX509bstr / [ 2*certs: bstr ]fromCBOR()/toCBOR(),certificates(): non-empty-list<string>(DER, as carried),toCertificates(): Certificate[](parsed on demand),find(CoseCertHash, FilterOnlyHash): ?string. An array of length one is rejected on decode with a message naming the rule, and never produced on encode.X5BagCOSE_X509toCertificateBundle()for pki-framework's path building.X5ChainCOSE_X509endEntityCertificate(),toCertificateChain()(→CertificationPath::fromCertificateChain()),fromCertificateChain().CoseCertHash[ hashAlg: (int / tstr), hashValue: bstr ]hashAlgorithm(Manager): FilterOnlyHashresolves through the RFC 9054 registry of #195 — SHA-1 and SHA-256/64 accepted, this being the filtering use; a text-string identifier, an unregistered one or one registered with a non-hash is refused.matches(string $der, FilterOnlyHash)compares withhash_equals()and throws if the hash given is not the one the thumbprint names.compute()makes one.CoseHeadersgetX5Bag(): ?X5Bag,getX5Chain(): ?X5Chain,getX5T(): ?CoseCertHash,getX5U(): ?string— protected bucket first,nullwhen absent, as the issue asks. Each of the four "can be in either the protected or unprotected header bucket" (§2), so unliketypneither bucket is refused; the docs say why the bucket still matters ("The end-entity certificate MUST be integrity protected by COSE").LABEL_X5BAG,LABEL_X5CHAIN,LABEL_X5T,LABEL_X5U, andLABEL_X5T_SENDER(-27),LABEL_X5U_SENDER(-28),LABEL_X5CHAIN_SENDER(-29) — the last three without accessors until ECDH-SS (feat(key management): direct, AES-KW, HKDF, ECDH-ES/SS recipient algorithms (RFC 9053 §5–6) #201), per the issue.HeaderMapHelper::assertUriValue(): RFC 9360 says the value "contains a CBOR text string" while the CDDL typeuriis#6.32(tstr), so both a bare text string and one under tag 32 are read (the default decoder yieldsUriTag; a decoder without it yields aGenericTag, both handled). The text must start with a scheme (RFC 3986 §3); nothing else is checked, nothing is fetched.CertificateSignatureVerifier::verifyWithX5Chain()verifyWithX5Chain(int $alg, X5Chain $chain, string $data, string $signature): bool— the "verify with the leaf certificate of the chain" path in one call. Only the end-entity certificate is looked at; the rest of the chain is the application's to validate.One design point the issue did not anticipate: thumbprints are computed over the bytes as carried
CoseCertHash::compute()andmatches()take the DER string, not a parsedCertificate. The certificates of cose-wg/Examples are not strict DER (their keyUsage BIT STRING carries a spare byte), soCertificate::fromDER($alice)->toDER() !== $alice, and the SHA-256 of the re-encoding is not thex5tthat signed-05 carries. A receiver hashing a re-encoded certificate would never match a sender's thumbprint.CoseCertHashTest::theThumbprintIsComputedOverTheBytesAsCarriedNotOverAReEncodingpins this;CoseX509::fromCertificates()(sender side) keeps accepting parsed certificates, documented.Dependency:
spomky-labs/pki-frameworkfloor raised to^1.6.2(was^1.0)The first CI run failed on the lowest-deps job only: pki-framework
1.0.0rejects the cose-wg chain in the path-validation demonstration ofX5ChainTestand of the example ("Certificate signature doesn't match"). Bisected: every release≤ 1.6.1verifies a certificate signature over a re-encodedtbsCertificate, so a certificate that is not strict DER (the cose-wg ones, over-longkeyUsageBIT STRING) never validates;1.6.2verifies the bytes as carried.1.6.2(2026-09-08) is also the only supported line — its release notes close 27 advisories affecting≤ 1.6.1, among them GHSA-gjx8-fvx6-qg7q (that very BIT STRING), and declare1.0.x–1.5.xend of life. The API this library uses is unchanged across the range; the lowest-deps job now resolves pki-framework 1.6.2 + cbor-php 3.4.0 and passes (2428 tests on 8.2, reproduced locally). Documented inRELEASES.md.Acceptance criteria of #196
CoseHeaders, protected and unprotected —CoseHeadersTest, on all six message types, encoded to bytes and decoded againCOSE_X509array of length one is rejected on decode with an explicit message —CoseX509Test,X5ChainTest,X5BagTest,CoseHeadersTest::anX5ChainArrayOfOneIsRejected; never produced on encodex5twith SHA-256 and with SHA-1 matches the right certificate of a chain and no other —CoseCertHashTest,CoseX509Test,X5ChainTest,X5BagTest## X.509 Header Parametersanddoc/Usage.md### X.509 Header Parametersboth open with a[!IMPORTANT]block saying exactly thatTests
tests/CoseWg/X509FixtureTest.php— the fivex509-examplesfixtures, read through the accessors: the certificates on the wire are the input's, byte for byte, and encode back to the wire form; signed-03/04 verify withverifyWithX5Chain()(and not with the CA that follows); in signed-01/02 exactly one certificate of the bag verifies; thex5tof signed-05 resolves through theManager, selects Alice out of a two-certificate store, and that certificate verifies the signature.CoseX509Test,CoseCertHashTest,X5ChainTest,X5BagTest(tests/Structure/X509/): wire forms incl. indefinite-length, every malformed shape with its message, identifier forms (negative, unsigned, text, 2⁶⁴−1 refused), registry resolution and its three refusals, wrong-algorithm comparison refused, path validation of the chain with pki-framework againstca.crtas trust anchor (in the test, where it belongs).CoseHeadersTest(+9),HeaderMapHelperTest(URI values: bare, indefinite,UriTag,GenericTag32, tag 33 refused, byte string, relative reference, empty),CertificateSignatureVerifierTest(+2 over every algorithm of the provider).RfcReferencesTestknows RFC 9360;ExamplesTestrunsexamples/13-x509-header-parameters.php.Docs and examples
README (This library implements, Features, Documentation, new X.509 Header Parameters section),
doc/Usage.md(new section under Reading Headers, TOC, Common Header Parameters rows 15/16/32–35, examples table, References; Verifying a Signature Made by a Certificate points atverifyWithX5Chain()),RELEASES.md,composer.jsonkeywordRFC9360,examples/13-x509-header-parameters.php+ index (13, since #197 took 12).Checks
Rebased on
4.9.xafter #211 (COSE Key Thumbprint) landed. CI: every job green after the pki-framework floor bump (the first run failed on lowest-deps only, see above).phpstan(level max, no baseline change),ecs,rector,deptrac,parallel-lint,composer validate --strict: clean. PHPUnit: 2434 tests on the 8.4 image (194 skipped, the key-management fixtures of #201, unchanged); 2346 on 8.2.Not in this PR
Accessors for
x5t-sender/x5u-sender/x5chain-sender(#201), C509 (draft), any form of chain validation or URI retrieval — by design.