Commit Graph

4 Commits

Author SHA1 Message Date
Danny Lin
6e35ac2b6c
Shim the keystore service instead of replacing it
This method is more portable, does not require a different executable
for each Android version, and avoids breaking ROMs with heavy keystore
customizations. It works by injecting a shared library into the keystore
service and wrapping the Binder transaction handler in the generated
AIDL interface.

Because the actual attestKey implementation is statically linked into
the keystore service executable, we can't hijack it directly without
messy and error-prone code patching. Instead, we check each Binder
transaction handled by the AIDL stub and hijack transactions with the
TRANSACTION_attestKey code.

In order to keep key attestation working for apps, we only block Google
Play Services by checking the command line of the calling process
through Binder. This is not infallible and can be spoofed, but it's much
easier to do in C++ than looking up the calling UID's package name
through PackageManagerService. There are no negative security
implications as the only difference is a denied operation.

We can't set LD_PRELOAD for the keystore service because Magisk modules
start too late to modify its init.rc, so we inject the shim library as a
dependency instead using patchelf and build it with the DF_1_GLOBAL ELF
flag to make the dynamic linker prioritize it in symbol resolution.

TRANSACTION_attestKey values and AIDL stub names by Android version:
Android 10 - 11     (SDK 29-30): TX# 28, android::security::keystore::BnKeystoreService
Android 9           (SDK 28   ): TX# 35, android::security::BnKeystoreService
Android 7.0 - 8.1.0 (SDK 24-27): TX# 36, android::BnKeystoreService

Fixes #3, #6, #7, #8, #10, and #12.
2021-01-26 14:16:32 -08:00
Danny Lin
21d4d1d863
Remove security patch fixup script
This is causing more issues than it fixes.

Fixes #1.
2021-01-16 01:18:23 -08:00
Danny Lin
7df5188942
post-fs-data: Ignore empty vendor security patch levels 2021-01-14 00:05:36 -08:00
Danny Lin
4ba7ac5da3
Fix mismatching vendor and system security patch levels 2021-01-13 19:29:04 -08:00