chiteroman / Reprogram-TEE-on-Qualcomm-devices

Guide to reprogram the TEE on Qualcomm devices to fix lost attestation keys
The Unlicense
341 stars 62 forks source link

Reprogram TEE on Qualcomm devices

Guide to reprogram the TEE on Qualcomm devices to fix lost attestation keys.

Why?

If you are here it is because your phone has lost the TEE attestation keys, possibly due to flashing the persist partition of your phone.

If opening Key Attestation Demo does not give you any error, do NOT follow this guide.

This guide will NOT provide instructions for passing Strong verdict.

WARNINGS:

You will need:

Instructions for Engineering ROM:

  1. Flash engineering ROM.
  2. Phone must be connected to PC, then execute these commands IN ORDER:
adb root
adb remount
adb reboot
adb shell mkdir -p /data/nativetest64/qti_keymaster_tests/
adb push keybox.xml /data/nativetest64/qti_keymaster_tests/
adb shell LD_LIBRARY_PATH=/vendor/lib64/hw KmInstallKeybox /data/nativetest64/qti_keymaster_tests/keybox.xml 0 true

If you are using different keybox, you must change few arguments:

adb shell LD_LIBRARY_PATH=/vendor/lib64/hw KmInstallKeybox /data/nativetest64/qti_keymaster_tests/{KEYBOX FILE} {DEVICE ID} {ATTEST PROPS?}

Instructions for Stock ROM:

(with KmInstallKeybox binaries)

  1. Flash Stock ROM.
  2. Root the device using Magisk or any Rooting method.
  3. Phone must be connected to PC, then execute these commands IN ORDER:
    adb shell su
  4. Grant Root Access to Shell when prompted on your phone.
    adb shell su -c mkdir -p /data/nativetest64/qti_keymaster_tests/
    adb push keybox.xml /sdcard/
    adb shell su -c cp keybox.xml /data/nativetest64/qti_keymaster_tests/
    adb shell su -c LD_LIBRARY_PATH=/vendor/lib64/hw KmInstallKeybox /data/nativetest64/qti_keymaster_tests/keybox.xml 0 true

If you are using different keybox, you must change few arguments:

adb shell su -c LD_LIBRARY_PATH=/vendor/lib64/hw KmInstallKeybox /data/nativetest64/qti_keymaster_tests/{KEYBOX FILE} {DEVICE ID} {ATTEST PROPS?}

Attest props must be true unless it gives some error.