From e5d24c390790e9b73d728029e538e196d63ec20c Mon Sep 17 00:00:00 2001 From: Enginex0 Date: Wed, 17 Jun 2026 20:28:28 +0100 Subject: [PATCH] fix(keystore): drop algo-split key on restore A persisted record whose private-key algorithm disagrees with its served leaf public key (EC private under an RSA leaf) makes every signature fail as DATA_TOO_LARGE_FOR_MODULUS: the A16 EC two-root. Require the two to match on restore and drop the record otherwise, so the next generateKey rebirths a coherent key. Awaiting an EC device capture to confirm the red originates from a restored record. Bucket a16-ec-attestkey-red, task T01. --- .../keystore/shim/KeyMintSecurityLevelInterceptor.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/org/matrix/TEESimulator/interception/keystore/shim/KeyMintSecurityLevelInterceptor.kt b/app/src/main/java/org/matrix/TEESimulator/interception/keystore/shim/KeyMintSecurityLevelInterceptor.kt index 7c4204f..4a1b5cf 100644 --- a/app/src/main/java/org/matrix/TEESimulator/interception/keystore/shim/KeyMintSecurityLevelInterceptor.kt +++ b/app/src/main/java/org/matrix/TEESimulator/interception/keystore/shim/KeyMintSecurityLevelInterceptor.kt @@ -1222,6 +1222,15 @@ class KeyMintSecurityLevelInterceptor( require(certChain.isNotEmpty()) { "Persisted key has empty certificate chain" } val publicKey = certChain[0].publicKey + // The private key ($algorithmName) signs leaves that callers verify against this + // served chain's leaf public key. If the two disagree (EC private under an RSA + // served leaf) every signature this key makes fails as DATA_TOO_LARGE_FOR_MODULUS + // -- the A16 EC two-root. A split record is corrupt: drop it so the next + // generateKey rebirths a coherent one rather than serve a key that cannot sign. + require(publicKey.algorithm == algorithmName) { + "Persisted key ${record.alias} splits private=$algorithmName " + + "vs served leaf=${publicKey.algorithm}; dropping" + } val keyPair = KeyPair(publicKey, privateKey) val descriptor =