Bypass KeyMint hooks for certain UIDs

Adds a check using `ConfigurationManager.shouldSkipUid` at the start of the `onPreTransact` handlers for key generation and import.

If a UID is configured to be skipped, the transaction is forwarded directly to the hardware, and the post-transaction hook is bypassed. This prevents certificate patching and other modifications for trusted or problematic apps, improving compatibility.
This commit is contained in:
JingMatrix
2025-12-04 02:02:28 +01:00
parent a30459628f
commit a0ac3f71bb
@@ -44,11 +44,15 @@ class KeyMintSecurityLevelInterceptor(
if (code == GENERATE_KEY_TRANSACTION) { if (code == GENERATE_KEY_TRANSACTION) {
logTransaction(txId, transactionNames[code]!!, callingUid, callingPid) logTransaction(txId, transactionNames[code]!!, callingUid, callingPid)
if (ConfigurationManager.shouldSkipUid(callingUid))
return TransactionResult.ContinueAndSkipPost
data.enforceInterface(IKeystoreSecurityLevel.DESCRIPTOR) data.enforceInterface(IKeystoreSecurityLevel.DESCRIPTOR)
return handleGenerateKey(callingUid, data) return handleGenerateKey(callingUid, data)
} else if (code == IMPORT_KEY_TRANSACTION) { } else if (code == IMPORT_KEY_TRANSACTION) {
logTransaction(txId, transactionNames[code]!!, callingUid, callingPid) logTransaction(txId, transactionNames[code]!!, callingUid, callingPid)
if (ConfigurationManager.shouldSkipUid(callingUid))
return TransactionResult.ContinueAndSkipPost
data.enforceInterface(IKeystoreSecurityLevel.DESCRIPTOR) data.enforceInterface(IKeystoreSecurityLevel.DESCRIPTOR)
val alias = val alias =
data.readTypedObject(KeyDescriptor.CREATOR)?.alias data.readTypedObject(KeyDescriptor.CREATOR)?.alias