mdoc M1: CBOR/COSE foundation - #573
Draft
DibranMulder wants to merge 1 commit into
Draft
Conversation
Add the low-level primitives for ISO/IEC 18013-5 mdoc support in a new self-contained package eudi/credentials/mdoc, per issue #563. - go.mod: add fxamacker/cbor/v2 (coexists with the existing v1) and veraison/go-cose. - cbor.go: canonical CBOR encode/decode modes (length-first map ordering, definite lengths, indefinite-length rejected on decode); the tag 24 EncodedCBOR wrapper (#6.24(bstr .cbor X)), tag 1004 FullDate and tag 0 DateTime (UTC, no fractional seconds) types. - cose.go: COSE_Key (EC2/P-256) <-> ecdsa <-> JWK conversion with coordinate zero-padding, and thin Sign1/Verify1/X5Chain wrappers around go-cose for the untagged COSE_Sign1 objects mdoc uses for issuerAuth/deviceSignature. - Test vectors ported verbatim from the multipaz reference implementation (ISO/IEC 18013-5 Annex D worked examples). - Tests: deterministic-encoding byte-equality, tagged-type round trips and byte-exact golden checks, COSE_Key <-> JWK <-> ecdsa round trips, COSE_Sign1 sign/verify, and cross-validation of the implementation against the Annex D issuerAuth signature + DS certificate. Includes a CBOR decode fuzz target. Co-Authored-By: Claude Opus 4.8 (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.
Implements M1 — CBOR/COSE foundation from the mdoc implementation plan (
docs/mdoc-implementation-plan.md).Closes #563. Part of #562.
What this adds
A new self-contained package
eudi/credentials/mdoc/, sibling ofsdjwtvc/, with the low-level primitives every later mdoc milestone builds on. No dependencies on the OpenID4VCI/VP packages.Dependencies (
go.mod)github.com/fxamacker/cbor/v2— different import path than the existing v1, so both coexist; v2 is required for proper tag-24 and deterministic encoding support.github.com/veraison/go-cose—COSE_Sign1.cbor.goEncodedCBOR— the tag 24#6.24(bstr .cbor X)wrapper, preserving embedded bytes verbatim for byte-exact digesting/signing.FullDate— tag 1004 (RFC 8943)YYYY-MM-DD.DateTime— tag 0 (RFC 8949 §3.4.1) RFC 3339, normalised to UTC with no fractional seconds.cose.goCOSE_Key(EC2/P-256) ⇄*ecdsa.PublicKey/PrivateKey⇄jwk.Key, with the RFC 9052 leading-zero coordinate padding.Sign1/Verify1— thin wrappers around go-cose for the untaggedCOSE_Sign1objects mdoc uses forissuerAuth/deviceSignature, withx5chain(label 33) support.X5Chain— extract and parse the certificate chain from aCOSE_Sign1.Test vectors
Ported verbatim from the multipaz reference implementation (
org.multipaz.mdoc.TestVectors), originally from ISO/IEC 18013-5:2021 Annex D, intotestvectors_test.go.Tests
validityInfosignedvalue).COSE_Key⇄ JWK ⇄ ecdsa round trips over many generated keys; coordinate padding; non-P-256 rejection.COSE_Sign1sign/verify, x5chain encode/extract, tamper/wrong-key negatives.issuerAuthCOSE_Sign1from the worked-example device response and verifies its signature against the Annex D document-signer certificate.FuzzCOSEKeyToECDSAPublicKey), exercised for ~850k execs with no panics.🤖 Generated with Claude Code