Skip to content

cicdata-io/gmrtd

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

566 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Coverage Lines of Code Security Rating Maintainability Rating Reliability Rating Vulnerabilities Code Smells Technical Debt codecov Go Report Card

gmrtd

Go library for reading Machine Readable Travel Documents (MRTDs) such as passports and identity cards, as specified by ICAO Doc 9303.

This library focuses on NFC protocol handling, access control, LDS parsing, and cryptographic security checks, including passive authentication and chip authentication where supported.

Higher-level concerns such as OCR and UI are intentionally left to the integrator.

๐Ÿ”Ž Overview

gmrtd provides low-level building blocks for reading and authenticating eMRTDs:

  • Access Control (BAC and PACE)
  • Secure messaging and APDU handling
  • LDS parsing (EF.COM, EF.SOD, Data Groups)
  • Passive Authentication (SOD verification)
  • Chip Authentication (where supported)
  • Extended-length APDU support

The library is transport-agnostic and can be used with desktop, mobile, or embedded NFC stacks.

๐Ÿ” Access Control Support

Basic Access Control (BAC)

  • Legacy access control mechanism
  • MRZ-based key derivation only
  • Used by older passports and some current documents
  • Automatically selected when PACE is not available

Password Authenticated Connection Establishment (PACE)

  • Supported as specified in ICAO Doc 9303
  • Strong, modern access control mechanism
  • Supported password types:
    • MRZ (Machine Readable Zone)
    • CAN (Card Access Number), commonly used by modern ID cards
  • Supports multiple PACE variants:
    • ECDH (GM / CAM)
    • AES / 3DES
    • Brainpool and secp elliptic curves

The caller supplies either MRZ or CAN; gmrtd negotiates and executes the appropriate protocol automatically based on document capabilities.

๐Ÿ“ฆ Features

  • โœ… BAC (MRZ)
  • โœ… PACE-GM/CAM (MRZ and CAN)
  • โœ… Secure messaging
  • โœ… LDS parsing (EF.COM, EF.SOD, DGs)
  • โœ… Passive Authentication (SOD verification)
  • โœ… Chip Authentication (document-dependent)
  • โœ… Extended-length APDU support
  • โœ… Transport-agnostic design

โš ๏ธ Limitations

  • โŒ Terminal Authentication (TA) not implemented
  • โŒ PACE-IM not implemented
  • โŒ No OCR or MRZ extraction
  • โŒ Personal data handling and storage are the responsibility of the caller

๐Ÿงช Demo Application (PC/SC Reader)

A PC/SC demo reader is included in this repository as a Go command: cmd/gmrtd-reader.

It:

  • Connects to the first available PC/SC reader
  • Runs PACE by default (unless --skipPace is set)
  • Reads and verifies the document (including passive authentication)
  • Renders a HTML report (APDU logs + parsed LDS) and opens it in your browser

Build / run

go run ./cmd/gmrtd-reader --help

MRZ (BAC or PACE-MRZ)

go run ./cmd/gmrtd-reader --doc <DOCUMENT_NUMBER> --dob <YYMMDD> --exp <YYMMDD>

CAN (PACE-CAN)

go run ./cmd/gmrtd-reader --can <CAN>

Useful flags

# enable debug logging
--debug

# set/cap maximum Le / read size (bytes)
--maxRead 4096

# skip PACE negotiation (forces BAC where possible; mostly for debugging)
--skipPace

Notes:

  • --doc/--dob/--exp and --can are mutually exclusive.
  • Requires a PC/SC-compatible NFC reader and a working PC/SC stack.

๐Ÿ“Š Sample Documents

The following documents have been successfully read using gmrtd:

Country
(Type,Year)
PACE Chip Authentication Ext
Len
LDS
Ver
๐Ÿ‡ฆ๐Ÿ‡บ Australia
(P,2016)
n/a (BAC) AA-rsaEncryption Yes 0107
๐Ÿ‡ฆ๐Ÿ‡น Austria
(P,2023)
PACE-ECDH-GM-AES-CBC-CMAC-128
brainpoolP256r1
CA-ECDH-AES-CBC-CMAC-128
brainpoolP256r1
Yes 0107
๐Ÿ‡จ๐Ÿ‡ฆ Canada
(PP,2023)
PACE-ECDH-GM-AES-CBC-CMAC-128
secp384r1
CA-ECDH-AES-CBC-CMAC-128
secp384r1
No 0108
๐Ÿ‡จ๐Ÿ‡ณ China
(PO,2018)
n/a (BAC) AA-rsaEncryption No 0107
๐Ÿ‡ซ๐Ÿ‡ฎ Finland
(I,2023)
PACE-ECDH-GM-AES-CBC-CMAC-256
brainpoolP384r1
PACE-ECDH-CAM-AES-CBC-CMAC-256
brainpoolP384r1
Yes 0108
๐Ÿ‡ซ๐Ÿ‡ฎ Finland
(P,2024)
PACE-ECDH-GM-AES-CBC-CMAC-256
brainpoolP384r1
PACE-ECDH-CAM-AES-CBC-CMAC-256
brainpoolP384r1
Yes 0108
๐Ÿ‡ซ๐Ÿ‡ท France
(P,2017)
PACE-ECDH-GM-AES-CBC-CMAC-256
secp256r1
CA-ECDH-3DES-CBC-CBC
secp256r1
Yes 0107
๐Ÿ‡ซ๐Ÿ‡ท France
(ID,2024)
PACE-ECDH-GM-AES-CBC-CMAC-256
brainpoolP256r1
PACE-ECDH-IM-AES-CBC-CMAC-256
brainpoolP256r1
(PACE-IM not supported)
CA-ECDH-AES-CBC-CMAC-256
brainpoolP256r1
Yes 0108
๐Ÿ‡ฉ๐Ÿ‡ช Germany
(P,2023)
PACE-ECDH-GM-AES-CBC-CMAC-128
brainpoolP256r1
PACE-ECDH-CAM-AES-CBC-CMAC-128
brainpoolP256r1
CA-ECDH-AES-CBC-CMAC-128
brainpoolP256r1
Yes 0108
๐Ÿ‡ฎ๐Ÿ‡ฉ Indonesia
(P,2025)
โ„น๏ธ 2010 CSCA Series
PACE-ECDH-GM-AES-CBC-CMAC-256
brainpoolP256r1
CA-ECDH-AES-CBC-CMAC-256
brainpoolP256r1
Yes 0107
๐Ÿ‡ฒ๐Ÿ‡พ Malaysia
(P,2023)
n/a (BAC) CA-ECDH-3DES-CBC-CBC
brainpoolP256r1
Yes 0107
๐Ÿ‡ณ๐Ÿ‡ฑ Netherlands
(PP,2025)
PACE-ECDH-GM-AES-CBC-CMAC-256
brainpoolP320r1
CA-ECDH-AES-CBC-CMAC-256
brainpoolP512r1
Yes 0108
๐Ÿ‡ณ๐Ÿ‡ฟ New Zealand
(P,2017)
PACE-ECDH-GM-3DES-CBC-CBC
brainpoolP256r1
AA-rsaEncryption No 0107
๐Ÿ‡ต๐Ÿ‡ญ Philippines
(P,2020)
n/a (BAC) AA-rsaEncryption Yes 0107
๐Ÿ‡ท๐Ÿ‡บ Russia
(P,2020)
n/a (BAC) CA-ECDH-3DES-CBC-CBC
secp192
Yes 0107
๐Ÿ‡ธ๐Ÿ‡ฌ Singapore
(PA,2023)
PACE-ECDH-GM-AES-CBC-CMAC-256
brainpoolP256r1
โš ๏ธ Cloneable Yes 0108
๐Ÿ‡น๐Ÿ‡ผ Taiwan
(P,2024)
PACE-ECDH-GM-AES-CBC-CMAC-256
secp256r1
โš ๏ธ Cloneable Yes 0107
๐Ÿ‡ฌ๐Ÿ‡ง United Kingdom
(P,2021)
PACE-ECDH-GM-AES-CBC-CMAC-256
secp256r1
CA-ECDH-AES-CBC-CMAC-256
secp256r1
Yes 0108
๐Ÿ‡บ๐Ÿ‡ธ United States
(P,2021)
n/a (BAC) โš ๏ธ Cloneable ? 0107

Notes:

  • PACE entries may use MRZ or CAN depending on document type.
  • Cloneable reflects the documentโ€™s chip feature set, not a gmrtd vulnerability.

๐Ÿ” Why Some Documents Are โ€œCloneableโ€

Some MRTDs do not implement strong cryptographic anti-cloning mechanisms (notably Chip Authentication (CA) or Active Authentication (AA)). In these cases:

  • Chip data is protected only by access control (BAC or PACE) and secure messaging
  • If the access secret (MRZ/CAN) is obtained and the chip is read once, data can be copied and replayed
  • This is a document issuer design choice, not a vulnerability in gmrtd

Cloneability does not imply that the physical document can be trivially forged.

๐Ÿ›ก CSCA Trust Stores

For convenience and interoperability testing, gmrtd includes built-in CSCA trust anchors as standard for:

These defaults can be replaced, extended, or disabled depending on your trust model.

๐Ÿ“Œ Compatibility

  • Go: 1.19+
  • Transports: PC/SC, Core NFC, Android NFC, custom APDU transceivers
  • Platforms: Desktop, mobile, embedded

๐Ÿ“š Specifications

๐Ÿ”’ Security & Responsible Use

This library is intended for legitimate, consent-based MRTD reading.

Handle personal data in accordance with applicable laws and regulations.

๐Ÿค Contributing

Issues and pull requests are welcome.

When reporting document compatibility issues:

  • Do not upload personal data
  • Include document type/year, protocol used, and anonymised logs

โค๏ธ Contributors

Made with contrib.rocks.

About

gmrtd: Machine Readable Travel Document library (Go/golang)

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 97.6%
  • Go Template 2.0%
  • Makefile 0.4%