fix: use proper COSE_Sign1 in identity assertion test + add validation checking#52
Open
marmarko wants to merge 1 commit intocontentauth:mainfrom
Open
Conversation
…n checking
The IdentityAssertion.spec.ts test had two issues:
1. The credential holder callback returned a raw DER signature, but
sig_type "cawg.x509.cose" requires a complete COSE_Sign1 envelope
(RFC 9052). The verifier parses the signature field as COSE_Sign1
and fails with "extraneous data in CBOR input" on raw DER bytes.
Fix: implement CoseCawgSigner that builds a proper COSE_Sign1:
- Protected header { 1: -7 } (ES256) encoded as CBOR bstr
- Sig_structure = ["Signature1", protected, external_aad, payload]
- Sign CBOR(Sig_structure) with IEEE P1363 format
- Return Tag(18, [protected, {}, nil, signature])
IMPORTANT: Use Uint8Array (not Buffer) for byte strings in cbor2
to prevent CBOR content unwrapping.
2. The test only checked that Reader.fromAsset() didn't throw — it
never inspected validation_status. This masked the
claimSignature.mismatch error that occurred on every run.
Fix: add assertions for cawg.identity presence and zero integrity
errors in validation_status.
Note: this test also requires the save_to_stream JUMBF regeneration
fix in c2pa-rs (see contentauth/c2pa-rs#1944) to pass without
claimSignature.mismatch.
Refs: contentauth#51
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
The
IdentityAssertion.spec.tstest had two issues that masked a broken identity assertion signing protocol.Issue 1: Raw signature instead of COSE_Sign1
The
TestCawgSignercredential holder callback returned a raw DER signature:But
sig_type: "cawg.x509.cose"requires thesignaturefield in the identity assertion to be a complete COSE_Sign1 envelope (RFC 9052). The verifier callsCoseSign1::from_tagged_slice()on this field and fails with"extraneous data in CBOR input"on raw DER bytes.Fix
New
CoseCawgSignerclass that builds a proper COSE_Sign1:SignerPayload→ detached payload{ 1: -7 }(ES256) as CBOR bstrSig_structure = ["Signature1", protected, b"", payload]per RFC 9052 §4.4CBOR(Sig_structure)with IEEE P1363 formatCBOR(Tag(18, [protected, {}, nil, signature]))Important: byte strings must be
Uint8Array, notBuffer. Thecbor2library unwrapsBuffercontent (treating it as pre-encoded CBOR) instead of encoding it as a raw bstr, which causes"got map, expected bstr"parse errors.Issue 2: No validation checking
The test only verified that
Reader.fromAsset()didn't throw — it never inspectedvalidation_status. This masked theclaimSignature.mismatcherror that occurred on every run.Fix
Added assertions for:
cawg.identityassertion is present in the signed manifestvalidation_status(trust warnings from self-signed certs are expected and filtered)Dependencies
This test also requires the
save_to_streamJUMBF regeneration fix in c2pa-rs (see contentauth/c2pa-rs#1944) to pass. Without that fix, dynamic assertions produce stale JUMBF →claimSignature.mismatch.References