ISO/IEC 18013-5 mobile documents and their presentation
README.md

mdoc #

ISO/IEC 18013-5 mobile documents and their presentation.

A mobile document (mdoc) is a set of data elements, by name space, that an
issuer signs for a holder's device key: the mobile driving licence
(org.iso.18013.5.1.mDL) and the mdoc credentials of the EUDI wallet, which
HAIP 1.0 and the EUDI Architecture and Reference Framework require beside
SD-JWT VC. The holder discloses the elements a reader asks for and no others,
and proves with its device key that it takes part in the session.

This library covers the three roles:

  • Issuer: salted issuer-signed items, the mobile security object (MSO)
    that digests them with the device key and the validity window, signed as a
    COSE_Sign1 by a document signer whose certificate chain travels in x5chain.
  • Reader (verifier): the session establishment over the holder's device
    engagement, a device request with optional reader authentication, and the
    verification of each returned document in the order of section 9.3.1: the
    document signer chain to an IACA root and its extended key usage, the issuer
    signature, every item's digest, the document type, the validity window, the
    device signature or MAC over the session transcript, and the MSO's
    authorization of every device-signed element.
  • Holder (the mdoc): the session keys from its ephemeral key, the check of
    the reader's authentication, and documents that carry the requested items
    only, with a device signature or a device MAC.

The session protocol of section 9.1.1 derives SKReader and SKDevice with HKDF
over the ECDH secret of the two ephemeral P-256 keys, salted with the SHA-256
of the session transcript, and encrypts each message with AES-256-GCM under a
counter IV. The transcript carries the QR and NFC handovers of ISO/IEC 18013-5
and, for ISO/IEC 18013-7 online presentation, the OpenID4VP handovers of
OpenID for Verifiable Presentations 1.0 Appendix B.2.6, redirect-based and
over the Digital Credentials API.

Every structure that is digested or signed is embedded CBOR (tag 24): a value
read keeps the exact bytes it came in, and a value built is encoded once in
the core deterministic encoding. Every function is pure: keys, trust anchors,
the transcript and the time are inputs.

Installation #

opam install mdoc

Usage #

A proximity session: the holder shows its engagement as a QR code, the reader
opens the session with a request, and the holder reads it.

let () = Crypto_rng_unix.use_default ()
let get = function Ok v -> v | Error e -> Fmt.failwith "%a" Mdoc.Error.pp e

(* The holder shows its engagement; the reader scans it. *)
let e_device = Mdoc.Ec_key.generate ()
let qr = Mdoc.Engagement.to_qr (Mdoc.Engagement.v (Mdoc.Ec_key.public e_device))
let engagement = get (Mdoc.Engagement.of_qr qr)

(* The reader opens the session with its ephemeral key and a request. *)
let e_reader = Mdoc.Ec_key.generate ()
let transcript = Mdoc.Reader.transcript ~engagement ~e_reader_key:e_reader Qr

let items =
  {
    Mdoc.Request.doc_type = "org.iso.18013.5.1.mDL";
    namespaces = [ ("org.iso.18013.5.1", [ ("age_over_18", false) ]) ];
    request_info = [];
  }

let _reader, establishment =
  get
    (Mdoc.Reader.establish ~e_reader_key:e_reader transcript
       (Mdoc.Request.v [ Mdoc.Request.doc_request items ]))

(* The holder derives the same keys and reads the request. *)
let _holder, received =
  get (Mdoc.Holder.establish ~e_device_key:e_device ~engagement establishment)

let () = assert (List.length received.doc_requests = 1)

The holder answers with Mdoc.Holder.document over the issuer-signed data
Mdoc.Issuer.issue made, and Mdoc.Holder.respond; the reader reads the
response with Mdoc.Reader.receive and checks each document with
Mdoc.Reader.verify ~anchors ~now ~transcript, the anchors being the IACA
roots it trusts.

For an online presentation the transcript carries no engagement and no reader
key, only the handover:

let online =
  {
    Mdoc.Transcript.engagement = None;
    e_reader_key = None;
    handover =
      Openid4vp_dc_api
        {
          origin = "https://verifier.example";
          nonce = "n-0S6_WzA2Mj";
          jwk_thumbprint = None;
        };
  }

Limits #

  • Cipher suite 1 (ECDH on P-256) is the one cipher suite ISO/IEC 18013-5
    defines and the one implemented.
  • The device retrieval options (BLE, NFC, Wi-Fi Aware) and the server
    retrieval methods are carried as CBOR for the transport layer to read.
  • The OpenID4VP handovers follow OpenID for Verifiable Presentations 1.0. The
    handovers of ISO/IEC TS 18013-7 annexes that predate it are built with
    Other, as the annex encodes them.
  • multipaz (Kotlin,
    Apache-2.0), the OpenWallet Foundation's identity credential library, holds
    the ISO/IEC 18013-5 Annex D examples as test vectors.
  • isomdl (Rust) implements the mDL
    holder and reader.

References #

Licence #

ISC. See LICENSE.md.