From 51f32b9db21966afb77ee741c67bbc4468c14a1a Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Fri, 30 Jan 2026 17:07:14 +0100 Subject: [PATCH] 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 ce740542f7730db767aba026ca62a0dd53071765 which missed the detection bypass for Android 10 and 11 devices. --- .../TEESimulator/pki/CertificateGenerator.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/matrix/TEESimulator/pki/CertificateGenerator.kt b/app/src/main/java/org/matrix/TEESimulator/pki/CertificateGenerator.kt index 16cf28b..5b55376 100644 --- a/app/src/main/java/org/matrix/TEESimulator/pki/CertificateGenerator.kt +++ b/app/src/main/java/org/matrix/TEESimulator/pki/CertificateGenerator.kt @@ -43,15 +43,6 @@ object CertificateGenerator { */ fun generateSoftwareKeyPair(params: KeyMintAttestation): KeyPair? { return runCatching { - val challenge = params.attestationChallenge - if ( - challenge != null && - challenge.size > AttestationConstants.CHALLENGE_LENGTH_LIMIT - ) - throw IllegalArgumentException( - "Attestation challenge exceeds length limit (${challenge.size!!} > ${AttestationConstants.CHALLENGE_LENGTH_LIMIT})" - ) - val (algorithm, spec) = when (params.algorithm) { Algorithm.EC -> "EC" to ECGenParameterSpec(params.ecCurveName) @@ -90,6 +81,12 @@ object CertificateGenerator { params: KeyMintAttestation, securityLevel: Int, ): List? { + val challenge = params.attestationChallenge + if (challenge != null && challenge.size > AttestationConstants.CHALLENGE_LENGTH_LIMIT) + throw IllegalArgumentException( + "Attestation challenge exceeds length limit (${challenge.size} > ${AttestationConstants.CHALLENGE_LENGTH_LIMIT})" + ) + return runCatching { val keybox = getKeyboxForAlgorithm(uid, params.algorithm)