Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/kotlin/provider/KeyAttestationCertPathValidator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ class KeyAttestationCertPathValidator : CertPathValidatorSpi() {
sigProvider: String?,
): CertPathValidatorResult {
val certList = certPath.toCertList()
val selector = X509CertSelector().apply { issuer = certList.first().issuerX500Principal }
val expectedIssuer = certList.first().issuerX500Principal
val selector =
X509CertSelector().apply {
subject = expectedIssuer
issuer = expectedIssuer
}

var lastException: CertPathValidatorException? = null
for (anchor in trustAnchors) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/testing/Certs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ object Certs {
val factoryIntermediate = certFactory.factoryIntermediate
val remoteIntermediate = certFactory.remoteIntermediate
val factoryAttestation = certFactory.factoryAttestation
val notSelfIssuedAnchor =
TrustAnchor(
certFactory.generateIntermediateCertificate(
publicKey = certFactory.rootKey.public,
signingKey = certFactory.rootKey.private,
issuer = X500Name("SERIALNUMBER=badc0de"),
),
null,
)
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/test/kotlin/provider/KeyAttestationCertPathValidatorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.android.keyattestation.verifier.provider

import com.android.keyattestation.verifier.KeyAttestationReason
import com.android.keyattestation.verifier.testing.CertLists
import com.android.keyattestation.verifier.testing.Certs.notSelfIssuedAnchor
import com.android.keyattestation.verifier.testing.Certs.rootAnchor as testAnchor
import com.android.keyattestation.verifier.testing.Chains
import com.android.keyattestation.verifier.testing.FakeCalendar
Expand Down Expand Up @@ -167,6 +168,17 @@ class KeyAttestationCertPathValidatorTest {
assertThat(exception.reason).isEqualTo(PKIXReason.NO_TRUST_ANCHOR)
}

@Test
fun wrongAnchor_notSelfIssued_throwsCertPathValidatorException() {
val params =
PKIXParameters(setOf(notSelfIssuedAnchor)).apply { date = FakeCalendar.DEFAULT.today() }
val exception =
assertFailsWith<CertPathValidatorException> {
certPathValidator.validate(Chains.validFactoryProvisioned, params)
}
assertThat(exception.reason).isEqualTo(PKIXReason.NO_TRUST_ANCHOR)
}

@Test
fun wrongIssuer_throwsCertPathValidatorException() {
val certPath = Chains.wrongIssuer
Expand Down
Loading