JingMatrix/TEESimulator
소개
Android 하드웨어 지원 키 쌍과 키 인증을 소프트웨어로 시뮬레이션
기타 프로젝트측정된 스타 증가
- in 24h
- +3
- in 7 days
- +25
- in 15 days
- +53
- in 1 month
- +126
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalTEESimulator
TEESimulator defeats hardware-backed Key Attestation by serving selected apps from a software KeyMint that runs inside the real keystore daemon, while every other key stays on the device's real hardware.
Rather than patch certificates after the fact, it embeds AOSP's own reference KeyMint trusted application (kmr-ta) and signs attestations with a user-provided keybox. The certificates are generated the same way a real TEE generates them, so they are internally consistent by construction.
How it works
A privileged control daemon owns the configuration and the real device identity; the injected native library is a pure crypto-and-routing engine. The daemon launches at boot, harvests the device's real attestation parameters (verified-boot state, patch levels, OS version) from a throwaway hardware key, resolves the configured profiles against the live device, injects the interceptor into the keystore daemon, and pushes the resolved configuration over a local socket. Editing the configuration re-pushes without a reboot.
The daemon that guards keys — and the way apps reach it — changed across Android versions, so the module hooks each generation at the point that suits it, and both paths lead to the same reference TA and keybox:
- Android 12 and newer use
keystore2, which reaches the KeyMint HAL over Binder. The module injects a native library intokeystore2and PLT-hooksAIBinder_transact; a KeyMint transaction for a targeted app (or a key the module created) is redirected to a local, in-processIKeyMintDevicethat wraps the TA, and everything else is forwarded to the real hardware. - Android 10 and 11 use the legacy
keystoredaemon, which apps reach overIKeystoreService. The module injects intokeystore, hooksioctlon libbinder, and redirects that service to a local stub handled in-process. For a targeted app it generates the key itself, hands back its public key, and at attestation time imports that key into the TA with the app's challenge, so the TA issues a keybox-signed chain over it. Other callers pass through.
Keys the simulator creates are tagged (Android 12+) or tracked by caller (Android 10/11) so only they are served; real hardware keys are never intercepted. If no keybox is loaded the interceptor stays a no-op, so a misconfigured module is inert rather than a hazard.
Profiles and device identity
Configuration is organised into profiles: a named bundle of a keybox, an operation mode, patch and OS levels, and optional device-identity values (brand, model, IMEI, …), assigned to a set of apps. Each targeted app belongs to exactly one profile, and its attestations are signed and shaped by that profile.
The root of trust — verified-boot key, verified-boot state, device-locked flag — is deliberately not configurable. The daemon harvests the device's real values once and freezes them: they make the attested root of trust authentic, and because those fields also seed KeyMint's key-encryption-key derivation, freezing them gives a stable per-device key that keeps stored keys decryptable across reboots.
Requirements
- Android 10 or newer
- A 64-bit device — arm64-v8a or x86_64 (the keystore daemon is 64-bit)
- Root (Magisk, KernelSU, or APatch)
Installation
- Flash the module with the root manager and reboot.
- Place a hardware-backed
keybox.xmlat/data/adb/teesim/keybox.xml. - List the apps to simulate under a profile in
/data/adb/teesim/config.json, or edit the profile in the WebUI. - Save. The daemon watches the configuration and applies changes live; no reboot is needed.
The module ships a default config.json that targets Google Play services and the Play Store. The keybox is private and is never shipped with the module, so until one is placed the interceptor does nothing.
Killing the keystore daemon (su -c 'kill $(pidof keystore2)' on Android 12+, keystore on 10/11) is the recovery path: a fresh daemon starts clean, with no interception, until the module re-injects it.
Without a reboot
Nothing the module installs waits for a boot stage — it mounts no partition and ships no system.prop, and the daemon injects whatever keystore process it finds — so an install can take effect on the system that is already running. Which path a device has depends on its root manager:
A KernelSU whose
ksudsupports hot install installs it in place. The installer asks for a hot install,ksudswaps the module directory and runshotinstall.sh, and the daemon takes over from there.Magisk, APatch, and a KernelSU without that path stage the new build in
modules_updateuntil the next boot, and arm it with one command — the installer prints the exact path:su -c /data/adb/modules_update/teesim/late-load.shOnce the module has been through a boot it lives in
/data/adb/modules/teesim, and the script is run from there.ksud late-loadruns the same script by itself.--stopis the reverse: it stops the daemon, puts back the system properties a profile wrote, and restarts the keystore service, leaving the system carrying no interceptor at all.
Both arm the running system, and both have one thing a reboot does not: the keystore process in front of them may already carry an interceptor, which no library is ever unloaded from or injected over. When that one is this build's — a daemon that crashed and respawned, or a second late-load.sh — the daemon adopts it and nothing restarts. When it is an older build's, as after an update, the daemon restarts the keystore service and injects the new one into the fresh process, and apps may see a transient keystore error as it goes down. The stage prints which of the two happened, into the install log on a hot install — and when ksud late-load runs it at boot there is nothing to print to, so the same lines also go to the device log and show up in the daemon's log and the WebUI's Logs panel.
A reboot is still needed for one case the installer reports: a TrickyStore that was active on this boot keeps its own keystore hook until the keystore daemon restarts, so the installer disables it and asks for the reboot rather than hot-installing over it.
Configuration
Everything lives in /data/adb/teesim/, owned and validated by the daemon. The keybox files carry private keys and are never shipped with the module.
config.json
A schema version and a map of named profiles. Each targeted package must appear in exactly one profile:
{
"version": 1,
"profiles": {
"default": {
"keybox": "keybox.xml", // relative to /data/adb/teesim; must parse (rsa and/or ecdsa, chains >= 2)
"patchLevel": { "system": "", "vendor": "YYYY-MM-05", "boot": "YYYY-MM-05" },
"osVersion": "", // empty = harvested | system_property | "16" | "16.0.0" | 160000
"brand": "", "device": "", "product": "",
"manufacturer": "", "model": "",
"serial": "", "imei": "", "meid": "", "imei2": "",
"verifiedBootHash": "", // empty = the keybox's, else this device's; or 64 hex characters
"applyProperties": false, // opt-in: also write what this profile attests into the system properties
"apps": ["com.google.android.gms", "com.android.vending"]
}
}
}
Patch and OS levels accept a small mini-language the daemon resolves against the device. harvested reuses the value captured from the real TEE at harvest time; system_property reads the matching build property from getprop and nothing else. Both report nothing when their source has no value — the tag is omitted rather than sent as a made-up default. today is the current month for the system level and today's date for vendor and boot; YYYY-MM-DD / YYYY-MM an explicit date; no suppresses the level. A date may also use the tokens YYYY / MM / DD, resolved to today, so YYYY-MM-05 means the 5th of the current month (the shipped default for the vendor and boot patch levels, which tracks the calendar). Every other field states what this profile attests, and what it leaves empty takes a default from one of two places. An RKP keybox records the device it was provisioned for — its verified boot hash, its manufacturer, and a build fingerprint, which spells out the brand, product and device names — and that comes first, because attesting this device's own values under such a keybox contradicts the keybox signing the chain. Everything it does not state falls back to the harvest: the value captured from the real TEE, or the one read from the OS when the attested leaf carried none, so an app asking the keystore to attest the device's real ids gets a matching answer. A field with neither is omitted rather than sent as a made-up default, and the editor's hint under each empty field names the value and which of the two sources it came from.
verifiedBootHash is the hash the profile's root of trust attests. Only the attestation carries it: the key-encryption key the simulator's TA derives comes from the boot key, state and lock flag above, so changing the hash leaves every stored key readable.
applyProperties (opt-in, off unless stated) decides whether what a profile attests is also what getprop says. With the flag set, every id, patch level and OS version the profile presents that differs from the harvest is written into the system properties it is read from, and ro.boot.vbmeta.digest follows the hash the profile attests; without it, the daemon writes only the harvested ro.boot.vbmeta.* values, as it always has. A property is written only where this device already carries it and it says what the harvest says: a name the device does not have is one nothing on it reads, and one that legitimately differs — the system image's own generic device name, a frozen vendor image's older release — describes something else. There is a single set of properties, so at most one profile may claim them (the daemon rejects a second).
Nothing written this way is permanent. resetprop lives in memory, so a reboot restores every property on its own, and the daemon records what each one read before it first wrote it (props.json, scoped to one boot) so it can put them back — when a profile stops claiming a value, when late-load.sh --stop disarms the module, and before it harvests, which is what keeps the capture a reading of this device even when the daemon is restarted into a system it has already spoofed.
keybox.xml
A keybox carries the private keys and certificate chains the simulator signs with. It must contain at least one of an RSA and an ECDSA key (the EC key on NIST P-256), each with a PEM PrivateKey — SEC1 (EC PRIVATE KEY) or PKCS#1 (RSA PRIVATE KEY), the encodings the TA signs with; the WebUI's keybox inspector flags a PKCS#8 one — and a CertificateChain of two certificates or more — a factory keybox carries both, while one extracted from RKP carries only the EC key. An attested key is signed by the batch key of its own algorithm where the keybox has it, and by the other one where it does not:
<?xml version="1.0"?>
<AndroidAttestation>
<Keybox DeviceID="...">
<Key algorithm="rsa">
<PrivateKey format="pem">-----BEGIN RSA PRIVATE KEY-----...</PrivateKey>
<CertificateChain>
<Certificate format="pem">-----BEGIN CERTIFICATE-----...</Certificate>
<!-- ...intermediate and root... -->
</CertificateChain>
</Key>
<Key algorithm="ecdsa">
<PrivateKey format="pem">-----BEGIN EC PRIVATE KEY-----...</PrivateKey>
<CertificateChain>
<Certificate format="pem">-----BEGIN CERTIFICATE-----...</Certificate>
</CertificateChain>
</Key>
</Keybox>
</AndroidAttestation>
A profile names its keybox by relative path, so several profiles can sign with different keyboxes. An app that is in no profile is transparent to the module — its keys go straight to the real hardware.
WebUI
Where the root manager supports it (KernelSU, APatch), the module ships a WebUI that edits profiles without a text editor: create and assign profiles, import and rename keyboxes, choose the operation mode, and set the patch/OS levels and device identity. It also manages the keys the simulator has stored — list, inspect the attestation record, and delete — surfaces the harvest and injection status and live daemon logs, and can download and flash a newer canary build in place.
Building from source
The build depends on no device: libbinder_ndk and liblog come from the NDK, and BoringSSL is either resolved at runtime (Android 12+) or built as a static library from the submodule (Android 10/11). It needs only the SDK (for aidl) and the NDK.
git clone --recurse-submodules <repo> TEESimulator
cd TEESimulator
export ANDROID_HOME=/path/to/android/sdk # SDK: aidl, cmake, the daemon's AGP build
export ANDROID_NDK_HOME=/path/to/android/ndk # or the newest NDK under $ANDROID_HOME/ndk
./gradlew zipRelease # -> out/TEESimulator-<version>-<count>-<hash>-Release.zip
The whole build is one Gradle graph. zipRelease (or zipDebug, which bundles extra logging) builds the Rust TA, both native interceptors for arm64-v8a and x86_64 (via CMake externalNativeBuild), and the control daemon's dex, then assembles the flashable module. With a device attached, ./gradlew installMagisk (or installKsu / installApatch) pushes and installs it; append AndReboot to reboot after, and set ANDROID_SERIAL=<serial> to pick a device when several are connected.
Project layout
| Path | What it is |
|---|---|
app/ |
The Kotlin control daemon: harvests the real device parameters, resolves profiles, injects the interceptor, serves the WebUI, and pushes configuration over the control socket. |
injector/ |
A ptrace-based tool that loads an interceptor into a running process. |
keymint/ |
The Android 12+ interceptor: the AIBinder_transact hook and the router that decides, per request, whether to simulate or forward. |
keystore/ |
The Android 10/11 interceptor: the libbinder ioctl hook and the IKeystoreService handler that serves a target's key lifecycle from the TA. |
rust/teesim-km/ |
The in-process TA — the reference KeyMint TA wired to BoringSSL and keybox-based attestation, behind a small C ABI. |
module/ |
The flashable module: the stage scripts (service.sh at boot, late-load.sh and hotinstall.sh on a running system, all forwarding to stage.sh), installer, sepolicy.rule, the default configuration, and the WebUI. |
third_party/ |
Submodules: the reference KeyMint, the AIDL interfaces, frameworks/native, BoringSSL, and LSPlt. |
License
TEESimulator is free software, licensed under the GNU General Public License v3.0 or any later version. The third-party code it builds on — the AOSP submodules, BoringSSL, LSPlt and the vendored platform headers — is listed with its own terms in NOTICE.
관련 프로젝트 살펴보기
불러오는 중…