Correctly handle deleteKey for software keys (#42)
This resolves an issue introduced in 6193da0 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:
@@ -42,12 +42,16 @@ 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()
|
||||
if (writeResultCode) {
|
||||
writeInt(KeyStore.NO_ERROR)
|
||||
}
|
||||
}
|
||||
return BinderInterceptor.TransactionResult.OverrideReply(0, parcel)
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -104,7 +104,13 @@ object Keystore2Interceptor : AbstractKeystoreInterceptor() {
|
||||
val keyId = KeyIdentifier(callingUid, descriptor.alias)
|
||||
|
||||
if (code == DELETE_KEY_TRANSACTION) {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user