interceptors: keystore2: Handle missing keys error properly

Signed-off-by: Dakkshesh <beakthoven@gmail.com>
This commit is contained in:
Dakkshesh
2025-09-04 12:35:17 +05:30
parent 7d371dd766
commit ff980f59fc
@@ -77,14 +77,20 @@ object Keystore2Interceptor : BaseKeystoreInterceptor() {
if (code == getKeyEntryTransaction) {
if (KeyBoxUtils.hasKeyboxes()) {
Logger.d("intercept pre $target uid=$callingUid pid=$callingPid dataSz=${data.dataSize()}")
kotlin.runCatching {
try {
data.enforceInterface(IKeystoreService.DESCRIPTOR)
val descriptor = data.readTypedObject(KeyDescriptor.CREATOR) ?: return@runCatching
val descriptor = data.readTypedObject(KeyDescriptor.CREATOR) ?: return Skip
if (PkgConfig.needGenerate(callingUid)) {
val response = SecurityLevelInterceptor.getKeyResponse(callingUid, descriptor.alias)
?: return@runCatching
Logger.i("Generate key for uid=$callingUid alias=${descriptor.alias}")
return createTypedObjectReply(response)
if (response != null) {
Logger.i("Found generated response for uid=$callingUid alias=${descriptor.alias}")
return createTypedObjectReply(response)
} else {
Logger.e("No generated response found for uid=$callingUid alias=${descriptor.alias}")
val nullParcel = Parcel.obtain()
nullParcel.writeTypedObject(null as KeyEntryResponse?, 0)
return OverrideReply(0, nullParcel)
}
} else if (PkgConfig.needHack(callingUid)) {
if (SecurityLevelInterceptor.shouldSkipLeafHack(callingUid, descriptor.alias)) {
Logger.i("skip leaf hack for uid=$callingUid alias=${descriptor.alias}")
@@ -94,7 +100,9 @@ object Keystore2Interceptor : BaseKeystoreInterceptor() {
return createTypedObjectReply(response)
} else {
Logger.e("No generated response found for uid=$callingUid alias=${descriptor.alias}")
return@runCatching
val nullParcel = Parcel.obtain()
nullParcel.writeTypedObject(null as KeyEntryResponse?, 0)
return OverrideReply(0, nullParcel)
}
} else {
Logger.i("proceeding with leaf hack for uid=$callingUid alias=${descriptor.alias}")
@@ -102,8 +110,11 @@ object Keystore2Interceptor : BaseKeystoreInterceptor() {
}
}
return Skip
}
} catch (e: Exception) {
Logger.e("Exception in onPreTransact uid=$callingUid pid=$callingPid!", e)
return Skip
}
}
}
return Skip
}