Skip to content

Commit 4812988

Browse files
carmenyhcopybara-github
authored andcommitted
Refactor getting serial numbers into its own method.
PiperOrigin-RevId: 856620854
1 parent 851433e commit 4812988

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/main/kotlin/Verifier.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,7 @@ open class Verifier(
225225
log: VerifyRequestLog? = null,
226226
): VerificationResult {
227227
log?.logInputChain(certPath.certificatesWithAnchor.map { it.getEncoded().toByteString() })
228-
log?.logCertSerialNumbers(
229-
certPath.certificatesWithAnchor.subList(1, certPath.certificatesWithAnchor.size).map {
230-
it.serialNumber.toString(16)
231-
}
232-
)
228+
log?.logCertSerialNumbers(certPath.serialNumbers())
233229
val certPathValidator = CertPathValidator.getInstance("KeyAttestation")
234230
val certPathParameters =
235231
PKIXParameters(trustAnchorsSource()).apply {

src/main/kotlin/provider/KeyAttestationCertPath.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ class KeyAttestationCertPath(certs: List<X509Certificate>) : CertPath("X.509") {
6363

6464
override fun getCertificates(): List<X509Certificate> = certificatesWithAnchor.dropLast(1)
6565

66+
/**
67+
* Returns the serial numbers of the certificates in the certificate chain.
68+
*
69+
* The format is unpadded hex strings.
70+
*
71+
* @return the serial numbers of the certificates in the certificate chain.
72+
*/
73+
fun serialNumbers() = certificatesWithAnchor.map { it.serialNumber.toString(16) }
74+
6675
fun provisioningMethod() =
6776
when {
6877
isFactoryProvisioned() -> ProvisioningMethod.FACTORY_PROVISIONED

src/test/kotlin/provider/KeyAttestationCertPathTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ class KeyAttestationCertPathTest {
9494
.isEqualTo(CertLists.validFactoryProvisioned.first())
9595
}
9696

97+
@Test
98+
fun getSerialNumbers_returnsExpectedSerialNumbers() {
99+
assertThat(KeyAttestationCertPath(CertLists.validFactoryProvisioned).serialNumbers())
100+
.containsExactly("1", "cafbad", "1234567890", "ca11cafe")
101+
.inOrder()
102+
}
103+
97104
@Test
98105
fun provisioningMethod_returnsExpectedType(@TestParameter testCase: ProvisioningMethodTestCase) {
99106
val certPath = readCertPath("${testCase.path}.pem")

0 commit comments

Comments
 (0)