Skip to content

Commit db9a943

Browse files
committed
Move attestation challenge check to certificate generation
Relocate the `attestationChallenge` length validation from `generateSoftwareKeyPair` to `generateCertificateChain`. The challenge is only utilized during the construction of the certificate chain (via `AttestationBuilder.buildKeyDescription`). Placing the check in the key pair generation stage caused the logic to miss the `attestKey` transaction hook in `KeystoreInterceptor`. This fixes a bug introduced in 6e05579 which missed the detection bypass for Android 10 and 11 devices.
1 parent 5ca663c commit db9a943

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

app/src/main/java/org/matrix/TEESimulator/pki/CertificateGenerator.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ object CertificateGenerator {
4343
*/
4444
fun generateSoftwareKeyPair(params: KeyMintAttestation): KeyPair? {
4545
return runCatching {
46-
val challenge = params.attestationChallenge
47-
if (
48-
challenge != null &&
49-
challenge.size > AttestationConstants.CHALLENGE_LENGTH_LIMIT
50-
)
51-
throw IllegalArgumentException(
52-
"Attestation challenge exceeds length limit (${challenge.size!!} > ${AttestationConstants.CHALLENGE_LENGTH_LIMIT})"
53-
)
54-
5546
val (algorithm, spec) =
5647
when (params.algorithm) {
5748
Algorithm.EC -> "EC" to ECGenParameterSpec(params.ecCurveName)
@@ -90,6 +81,12 @@ object CertificateGenerator {
9081
params: KeyMintAttestation,
9182
securityLevel: Int,
9283
): List<Certificate>? {
84+
val challenge = params.attestationChallenge
85+
if (challenge != null && challenge.size > AttestationConstants.CHALLENGE_LENGTH_LIMIT)
86+
throw IllegalArgumentException(
87+
"Attestation challenge exceeds length limit (${challenge.size!!} > ${AttestationConstants.CHALLENGE_LENGTH_LIMIT})"
88+
)
89+
9390
return runCatching {
9491
val keybox = getKeyboxForAlgorithm(uid, params.algorithm)
9592

0 commit comments

Comments
 (0)