When an app reads an eID chip, getting the data off the chip is the easy part. The harder question is whether to trust it. Passive Authentication (PA) answers that. It checks what you read against a signed manifest the issuing state wrote to the chip during personalisation: the Document Security Object (SOD). If every data group you read hashes to the value the SOD lists, and the SOD's signature chains up to a national authority you trust, the data is what that authority issued and has not been changed since.
What PA does not tell you is whether the chip in front of you is the original. That limit is easy to miss, so it gets its own section below.
Everything here is public. PA is specified in ICAO Doc 9303 Part 11, the data structures are in Part 10 and the PKI is in Part 12. I stay at the level of those documents and of public APIs.
Where Passive Authentication sits in the read flow
In my walk-through of reading an eID chip on Android, I split the job into four stages: NFC discovery, access control (BAC or PACE), reading the data groups over APDUs, and verification. PA is the last stage. When it starts, the secure channel is already open and the raw files are in memory: DG1 (the MRZ), DG2 (the face image) and EF.SOD.
Keep reading and trusting as separate steps. A successful READ BINARY under secure messaging tells you the bytes came from the chip and were not changed in transit. It does not tell you that a real authority issued them for a real person.
Inside the SOD: a signed list of hashes
The SOD is not a custom format. EF.SOD wraps (under the application tag 0x77) a CMS SignedData structure as defined in RFC 5652; older editions of 9303 refer to RFC 3369, an earlier version of CMS. CMS is the same envelope S/MIME uses for signed email, so Bouncy Castle can already parse and verify it.
What makes it an eID SOD is the signed content. encapContentInfo.eContent holds a DER-encoded LDSSecurityObject with:
- a version,
- the hash algorithm used for the data groups (SHA-256 or another SHA-2 variant on current documents; older documents may use SHA-1),
- a list of
DataGroupHashentries, each pairing a data group number with the hash of that data group.
So the SOD does not contain your name or your photo. It contains the hash of the file that holds your name, the hash of the file that holds your photo, and so on, and it signs that list. Change one byte of DG1 and its hash no longer matches. Swap the photo and DG2's hash fails. The signature makes the list itself tamper-evident.
The CMS certificates field normally carries the Document Signer (DS) certificate, whose public key verifies the SOD signature. (If a document doesn't include it, you look it up, for example in the PKD, by the signer identifier in the SignerInfo.) The DS certificate is issued by the state's Country Signing CA (CSCA), and the whole trust decision rests on that two-level PKI.
The three checks
PA comes down to three checks, and the document is trusted only if all of them pass:
- the SOD signature verifies under the DS certificate,
- the DS certificate chains up to a CSCA you trust and has not been revoked,
- each data group you read hashes to the value stored in the SOD.
The order of the first two doesn't really matter. What matters is that the third one only counts after both: until the signature and the chain hold, the stored hashes are just bytes anyone could have written. You can compute data group hashes while reading if that suits your flow, but don't act on the comparison until the SOD itself is trusted. I verify the signature first because it needs nothing but the SOD and the DS certificate, and it fails fast on a malformed SOD.
1. Verify the SOD signature
First we confirm that the SOD was signed with the DS key and that the signed content was not swapped. In CMS terms, the messageDigest signed attribute must equal a fresh hash of eContent (the LDSSecurityObject), and the signature over the signed attributes must verify under the DS public key. Bouncy Castle does both in one call:
import org.bouncycastle.cms.CMSSignedData
import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder
import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.security.cert.X509Certificate
/**
* Step 1: the SOD's SignedData must verify under the Document Signer certificate.
* [contentInfo] is the CMS ContentInfo from EF.SOD, without the 0x77 wrapper.
*/
fun verifySodSignature(
contentInfo: ByteArray,
docSigner: X509Certificate,
): Boolean = try {
val signedData = CMSSignedData(contentInfo)
val verifier = JcaSimpleSignerInfoVerifierBuilder()
.setProvider(BouncyCastleProvider())
.build(docSigner)
val signers = signedData.signerInfos.signers
// 9303 recommends a single SignerInfo; anything else is suspect.
// verify() checks messageDigest against eContent and the signature over signedAttrs.
signers.size == 1 && signers.first().verify(verifier)
} catch (e: Exception) {
false
}
Passing the Bouncy Castle provider explicitly is deliberate. Issuers sign with RSA, RSA-PSS or ECDSA, and some ECDSA signers use Brainpool curves, which the providers that ship with Android don't reliably cover. Bundling the full Bouncy Castle and passing its provider instance here avoids a signature failure that is really a missing algorithm. Pass the instance, not the name "BC": on Android that name can resolve to the platform's own trimmed-down copy.
This step shows that the hash list is intact and was signed with the DS key. It doesn't yet say whether that key belongs to anyone you trust.
2. Validate the DS certificate up to a trusted CSCA
The DS certificate counts for something only if it chains to a CSCA you already trust. CSCA certificates reach you by bilateral exchange between states, or through master lists: signed collections of CSCA certificates that a state has checked and republishes. Master lists are also distributed through the ICAO Public Key Directory (PKD), together with DS certificates and CRLs. Using someone else's master list means relying on that state's checks, so decide which lists you accept. You ship the CSCA certificates as trust anchors and keep them current. Standard java.security path validation does the rest:
import java.security.cert.CertPathValidator
import java.security.cert.CertStore
import java.security.cert.CertificateFactory
import java.security.cert.CollectionCertStoreParameters
import java.security.cert.PKIXParameters
import java.security.cert.TrustAnchor
import java.security.cert.X509CRL
import java.security.cert.X509Certificate
/**
* Step 2: the Document Signer certificate must chain up to a CSCA we trust
* and must not appear on that CSCA's CRL.
*/
fun verifyDocumentSignerTrust(
docSigner: X509Certificate,
cscaTrustAnchors: Set<X509Certificate>,
cscaCrls: Collection<X509CRL>,
): Boolean = try {
val path = CertificateFactory.getInstance("X.509")
.generateCertPath(listOf(docSigner))
val anchors = cscaTrustAnchors.map { TrustAnchor(it, null) }.toSet()
val params = PKIXParameters(anchors).apply {
addCertStore(
CertStore.getInstance("Collection", CollectionCertStoreParameters(cscaCrls)),
)
isRevocationEnabled = true
}
CertPathValidator.getInstance("PKIX").validate(path, params)
true
} catch (e: Exception) {
false
}
The code is short, but three things around it are not.
Revocation. Each CSCA publishes a CRL, and 9303 Part 12 requires a new one at least every 90 days. A revoked DS certificate is exactly the case you want to catch. 9303 builds revocation on CRLs, not OCSP, and the CRLs come from the PKD or bilateral exchange. With revocation enabled, PKIX validation fails when it finds no usable CRL for the issuing CSCA. That is the right default, but it makes CRL updates part of your release and update process. Revocation handling also differs between providers, so test it with real CRLs, including an expired one.
Validity periods. By default, PKIX checks validity against the current time. Under 9303 Part 12, a DS key signs documents for only a short period (up to about three months), but the DS certificate stays valid for as long as the documents it signed, around ten years. CSCA certificates are valid longer still. So a valid document normally passes. An expired document may come with an expired DS certificate, and whether to accept it is a product decision. If you accept it, set date on PKIXParameters to the time you want to validate at instead of switching the checks off.
Trust anchor rollover. CSCA keys are replaced every few years. Documents signed under the old key stay valid for years, so keep the old and the new CSCA certificates side by side. A stale anchor set rejects new documents that are perfectly valid.
3. Recompute the data group hashes
Only now does the data you read come in. For each data group pulled off the chip, compute its hash with the algorithm the SOD names and compare it with the stored value. A single mismatch fails the whole document. Hash the complete file as you read it (tag, length and value), not the parsed fields.
Note the direction: we go over the groups we actually read and look each one up in the SOD. A group the SOD covers but you never read stays unverified. That is common, since a typical flow reads DG1 and DG2 while the SOD may also cover DG11, DG14 or DG15. Never trust a group you did not read and hash.
import org.jmrtd.lds.SODFile
import java.security.MessageDigest
/**
* Step 3: every data group we read must hash to exactly the value
* the SOD committed to. One mismatch fails the whole document.
*/
fun dataGroupsMatchSod(
sod: SODFile,
readDataGroups: Map<Int, ByteArray>, // DG number -> full file bytes as read
): Boolean {
// all() on an empty map is true; nothing read means nothing verified.
if (readDataGroups.isEmpty()) return false
val expected: Map<Int, ByteArray> = sod.dataGroupHashes
val digest = MessageDigest.getInstance(sod.digestAlgorithm) // e.g. "SHA-256"
return readDataGroups.all { (dgNumber, bytes) ->
// If the SOD doesn't list this group, there is no stored hash to check it against.
val storedHash = expected[dgNumber] ?: return@all false
MessageDigest.isEqual(digest.digest(bytes), storedHash)
}
}
Here I use jMRTD's SODFile, an open-source implementation that is worth reading even if you parse the SOD yourself. getDataGroupHashes() returns the stored hashes keyed by data group number, getDigestAlgorithm() names the algorithm, and getDocSigningCertificate() gives you the embedded DS certificate for steps 1 and 2.
I compare with MessageDigest.isEqual rather than Arrays.equals. Neither hash is secret here, so timing is not a real attack vector in this step. It is a habit: isEqual doesn't stop at the first differing byte, and I'd rather have every security-relevant comparison behave the same way, in the same spirit as SecureCheck.
If all three checks pass, you have shown something specific: the data was issued by an authority whose CSCA you trust, and it has not been modified since.
What Passive Authentication does not prove
PA validates the data. It says nothing about the chip.
Suppose someone reads a genuine document, copies every data group and the SOD, and writes those exact bytes onto a blank chip. The copy carries the same signed hash list and the same valid DS certificate, so it passes all three checks. PA has no way to ask the chip whether it is the original silicon or a copy.
To detect a clone, the chip has to prove that it holds a secret that cannot be read out of it. ICAO Doc 9303 defines two mechanisms for this, and both are active protocols rather than passive checks:
- Active Authentication (AA): the chip holds a private key that never leaves it, and the matching public key is in DG15. The reader sends a random challenge, the chip signs it, and the reader verifies the signature with the DG15 key. A clone can't produce that signature because it never had the private key.
- Chip Authentication (CA): the chip's public key is in DG14. CA comes from BSI TR-03110 (Extended Access Control) and is also specified in 9303 Part 11. The reader runs a key agreement with the chip's static key, and secure messaging restarts with keys derived from it. Only a chip that holds the matching private key can continue the session, so a successful read afterwards shows the chip is genuine, and the new channel is stronger than the one BAC set up. PACE with Chip Authentication Mapping (PACE-CAM) folds the same proof into PACE.
Both are optional in 9303, and older documents may support neither, so whether a document can prove it isn't a clone is something you check per document by looking at which of these it offers. The dependency doesn't change: AA and CA only mean something after PA has verified DG15 or DG14. You verify the key with PA, then use the key to catch the clone. Skip PA and an attacker simply writes their own DG15.
PA also doesn't tell you that the person presenting the document is its holder (that takes a face match against DG2), or that the document hasn't been reported lost or stolen.
Make the failure reason visible
A verifier that only returns true or false hides why it failed. A missing CSCA certificate, a revoked signer and altered data need completely different responses, and "verification failed" doesn't tell anyone which one it was. So I make the failing stage part of the result:
sealed interface PassiveAuthResult {
data object Trusted : PassiveAuthResult
data class Failed(val stage: Stage, val detail: String) : PassiveAuthResult
enum class Stage { SOD_SIGNATURE, TRUST_CHAIN, DATA_GROUP_HASH }
}
A TRUST_CHAIN failure usually points at configuration: a missing or outdated CSCA certificate, a missing CRL, or a DS certificate that really was revoked. A DATA_GROUP_HASH failure is the serious one, because the data doesn't match its signed manifest. A SOD_SIGNATURE failure on an SOD that parsed cleanly deserves a close look: it may be an algorithm your crypto provider doesn't support, or an SOD that was tampered with. Put the stage and the underlying exception message into detail and into your diagnostics, and "it doesn't work" becomes something you can act on.
Frequently asked questions
- What does Passive Authentication actually prove?
- That the data you read is what the issuing state signed and has not changed since: each data group hashes to the value in the signed SOD, and the SOD's Document Signer certificate chains up to a CSCA you trust and has not been revoked.
- Can Passive Authentication detect a cloned eID chip?
- No. A byte-for-byte copy of a genuine chip carries the same signed SOD and the same valid Document Signer certificate, so it passes every PA check. Detecting a clone needs Active Authentication (key in DG15) or Chip Authentication (key in DG14), and those keys are only trustworthy after PA has verified DG15 or DG14.
- What are the three Passive Authentication checks, and does the order matter?
- Verify the SOD signature with the Document Signer certificate, validate that certificate up to a trusted CSCA including revocation, and compare each read data group's hash with the SOD. All three must pass. The first two can run in either order, but the hash comparison only counts once the SOD itself is trusted.
- Why compare data group hashes with MessageDigest.isEqual instead of Arrays.equals?
- Neither hash is secret here, so timing is not a real attack vector in this step. MessageDigest.isEqual is a habit: it does not stop at the first differing byte, so security-relevant comparisons behave the same way everywhere in the code.