Correctly handle deleteKey for software keys (#42)

This resolves an issue introduced in 733e64c where a `deleteKey` transaction for a software-generated key was incorrectly passed through to the hardware keystore. Since the hardware is unaware of such keys, this results in inconsistent state management.

The success reply is formatted correctly without a result code, per the AIDL interface specification.

Reference: https://cs.android.com/android/platform/superproject/main/+/main:out/soong/.intermediates/system/hardware/interfaces/keystore2/aidl/android.system.keystore2-V6-java-source/gen/android/system/keystore2/IKeystoreSecurityLevel.java;l=406
This commit is contained in:
小潼
2025-12-04 20:01:16 +01:00
committed by GitHub
parent 7d4c753d66
commit 119350f24b
2 changed files with 13 additions and 3 deletions
@@ -42,11 +42,15 @@ object InterceptorUtils {
}
/** Creates an `OverrideReply` parcel that indicates success with no data. */
fun createSuccessReply(): BinderInterceptor.TransactionResult.OverrideReply {
fun createSuccessReply(
writeResultCode: Boolean = true
): BinderInterceptor.TransactionResult.OverrideReply {
val parcel =
Parcel.obtain().apply {
writeNoException()
writeInt(KeyStore.NO_ERROR)
if (writeResultCode) {
writeInt(KeyStore.NO_ERROR)
}
}
return BinderInterceptor.TransactionResult.OverrideReply(0, parcel)
}
@@ -104,7 +104,13 @@ object Keystore2Interceptor : AbstractKeystoreInterceptor() {
val keyId = KeyIdentifier(callingUid, descriptor.alias)
if (code == DELETE_KEY_TRANSACTION) {
KeyMintSecurityLevelInterceptor.cleanupKeyData(keyId)
if (KeyMintSecurityLevelInterceptor.getGeneratedKeyResponse(keyId) != null) {
KeyMintSecurityLevelInterceptor.cleanupKeyData(keyId)
SystemLogger.info(
"[TX_ID: $txId] Deleted cached keypair ${descriptor.alias}, replying with empty response."
)
return InterceptorUtils.createSuccessReply(writeResultCode = false)
}
return TransactionResult.ContinueAndSkipPost
}