diff --git a/app/src/main/java/org/matrix/TEESimulator/interception/keystore/Keystore2Interceptor.kt b/app/src/main/java/org/matrix/TEESimulator/interception/keystore/Keystore2Interceptor.kt index a8405c0..30a8b00 100644 --- a/app/src/main/java/org/matrix/TEESimulator/interception/keystore/Keystore2Interceptor.kt +++ b/app/src/main/java/org/matrix/TEESimulator/interception/keystore/Keystore2Interceptor.kt @@ -62,6 +62,12 @@ object Keystore2Interceptor : AbstractKeystoreInterceptor() { private val deletedSoftwareKeys: MutableSet = ConcurrentHashMap.newKeySet() private val userUpdatedKeys = ConcurrentHashMap.newKeySet() + fun forgetDeletedKey(keyId: KeyIdentifier) { + if (deletedSoftwareKeys.remove(keyId)) { + SystemLogger.debug("Cleared deletion marker for ${keyId.alias}") + } + } + override val serviceName = "android.system.keystore2.IKeystoreService/default" override val processName = "keystore2" override val injectionCommand = "exec ./inject `pidof keystore2` libTEESimulator.so entry" 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 40243be..a1117f3 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 @@ -36,6 +36,7 @@ import org.matrix.TEESimulator.config.ConfigurationManager import org.matrix.TEESimulator.interception.core.BinderInterceptor import org.matrix.TEESimulator.interception.keystore.InterceptorUtils import org.matrix.TEESimulator.interception.keystore.KeyIdentifier +import org.matrix.TEESimulator.interception.keystore.Keystore2Interceptor import org.matrix.TEESimulator.logging.SystemLogger import org.matrix.TEESimulator.pki.CertGenConfig import org.matrix.TEESimulator.pki.CertificateGenerator @@ -562,6 +563,7 @@ class KeyMintSecurityLevelInterceptor( iSecurityLevel = original } generatedKeys[keyId] = GeneratedKeyInfo(null, secretKey, keyDescriptor.nspace, response, parsedParams) + Keystore2Interceptor.forgetDeletedKey(keyId) if (securityLevel == SecurityLevel.STRONGBOX) { val delayMs = STRONGBOX_KEYGEN_LATENCY_FLOOR_MS - (System.nanoTime() - genStartNanos) / 1_000_000 @@ -586,6 +588,7 @@ class KeyMintSecurityLevelInterceptor( val response = buildKeyEntryResponse(callingUid, keyData.second, parsedParams, keyDescriptor) generatedKeys[keyId] = GeneratedKeyInfo(keyData.first, null, keyDescriptor.nspace, response, parsedParams) + Keystore2Interceptor.forgetDeletedKey(keyId) if (isAttestKeyRequest) attestationKeys.add(keyId) if (SystemLogger.isDebugBuild) {