Skip to content

mdoc M1: CBOR/COSE foundation - #573

Draft
DibranMulder wants to merge 1 commit into
masterfrom
mdoc-m1-cbor-cose
Draft

mdoc M1: CBOR/COSE foundation#573
DibranMulder wants to merge 1 commit into
masterfrom
mdoc-m1-cbor-cose

Conversation

@DibranMulder

Copy link
Copy Markdown
Contributor

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 of sdjwtvc/, 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-coseCOSE_Sign1.

cbor.go

  • Fixed canonical CBOR encode mode (length-first map ordering, definite lengths, shortest-form ints) and a decode mode that rejects indefinite-length items, per ISO/IEC 18013-5 §9.1.2.
  • EncodedCBOR — 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.go

  • COSE_Key (EC2/P-256) ⇄ *ecdsa.PublicKey/PrivateKeyjwk.Key, with the RFC 9052 leading-zero coordinate padding.
  • Sign1 / Verify1 — thin wrappers around go-cose for the untagged COSE_Sign1 objects mdoc uses for issuerAuth/deviceSignature, with x5chain (label 33) support.
  • X5Chain — extract and parse the certificate chain from a COSE_Sign1.

Test vectors

Ported verbatim from the multipaz reference implementation (org.multipaz.mdoc.TestVectors), originally from ISO/IEC 18013-5:2021 Annex D, into testvectors_test.go.

Tests

  • Deterministic-encoding byte-equality; tagged-type round trips + byte-exact golden checks (incl. the Annex D validityInfo signed value).
  • COSE_Key ⇄ JWK ⇄ ecdsa round trips over many generated keys; coordinate padding; non-P-256 rejection.
  • COSE_Sign1 sign/verify, x5chain encode/extract, tamper/wrong-key negatives.
  • Cross-validation against ISO 18013-5 Annex D: extracts the issuerAuth COSE_Sign1 from the worked-example device response and verifies its signature against the Annex D document-signer certificate.
  • A CBOR decode fuzz target (FuzzCOSEKeyToECDSAPublicKey), exercised for ~850k execs with no panics.
ok  github.com/privacybydesign/irmago/eudi/credentials/mdoc

🤖 Generated with Claude Code

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>
Base automatically changed from openid4vci to master June 15, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant