[Sony Xperia XZ1 Compact Questions & Answers] j4nn:
Could this be a way to truly test for the attestation key?

AndroidHardening Auditor

https://github.com/AndroidHardening/Auditor/releases

The Auditor app uses hardware security features on supported devices to validate the integrity of the operating system from another Android device. It will verify that the device is running the stock operating system with the bootloader locked and that no tampering with the operating system has occurred. It will also detect downgrades to a previous version. Supported devices (among others):

Sony Xperia XZ1 / XZ1 Compact (G8342 and G8441 models)

It cannot be bypassed by modifying or tampering with the operating system (OS) because it receives signed device information from the device's Trusted Execution Environment (TEE) including the verified boot state, operating system variant and operating system version.

https://play.google.com/store/apps/details?id=app.attestation.auditor&hl=en_US

https://github.com/AndroidHardening/Auditor

It would be interesting to see some results here, for example from following devices:

never downgraded still locked device having the attestation key (together with the other two) provisioned

just downgraded (without flashing persist.sin) still locked device (claims to have the attestation key together with the other two)

never downgraded still locked device but flashed persist.sin followed by a factory reset (not sure how is the attestation key, imho persist could be regenerated from TZ and the key still provisioned)

never downgraded, unlocked device, TA not restored

never downgraded, unlocked device, TA restored from backup before unlock

downgraded device, unlocked, TA restored from backup before unlock

downgraded device with persist.sin flashed, still locked (attest key missing, the two somc provisioned)

Just tested the "downgraded device with persist.sin flashed, still locked (attest key missing, the two somc provisioned)" case and I get the Auditor app crashed on my xz1c right after scanning the initial qr code displayed on the second device:

E KeyMasterHalDevice: Attest key send cmd failed
E KeyMasterHalDevice: ret: 0
E KeyMasterHalDevice: resp->status: -10003
I keystore: del USRPKEY_persistent_attestation_key_B6E2C9BB477F2ABC2187C6F2B0F69B85A18ABF3354BD4E3817E8629F7DD8D0EA 10188
I keystore: del USRSKEY_persistent_attestation_key_B6E2C9BB477F2ABC2187C6F2B0F69B85A18ABF3354BD4E3817E8629F7DD8D0EA 10188
I keystore: del USRCERT_persistent_attestation_key_B6E2C9BB477F2ABC2187C6F2B0F69B85A18ABF3354BD4E3817E8629F7DD8D0EA 10188
I keystore: del CACERT_persistent_attestation_key_B6E2C9BB477F2ABC2187C6F2B0F69B85A18ABF3354BD4E3817E8629F7DD8D0EA 10188
E AndroidRuntime: FATAL EXCEPTION: IntentService[GenerateAttestationService]
E AndroidRuntime: Process: app.attestation.auditor, PID: 22276
E AndroidRuntime: java.security.ProviderException: Failed to generate attestation certificate chain
E AndroidRuntime: at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.getAttestationChain(AndroidKeyStoreKeyPairGeneratorSpi.java:604)
E AndroidRuntime: at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.createCertificateChain(AndroidKeyStoreKeyPairGeneratorSpi.java:491)
E AndroidRuntime: at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:474)
E AndroidRuntime: at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:728)
E AndroidRuntime: at app.attestation.auditor.a.a(Unknown Source:9)
E AndroidRuntime: at app.attestation.auditor.a.a(Unknown Source:208)
E AndroidRuntime: at app.attestation.auditor.GenerateAttestationService.onHandleIntent(Unknown Source:55)
E AndroidRuntime: at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:68)
E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105)
E AndroidRuntime: at android.os.Looper.loop(Looper.java:251)
E AndroidRuntime: at android.os.HandlerThread.run(HandlerThread.java:65)
E AndroidRuntime: Caused by: android.security.KeyStoreException: -10003
E AndroidRuntime: at android.security.KeyStore.getKeyStoreException(KeyStore.java:695)
E AndroidRuntime: at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.getAttestationChain(AndroidKeyStoreKeyPairGeneratorSpi.java:605)
E AndroidRuntime: ... 10 more

My personal guess:

- whoever downgraded would not have the attestation key working regardless the security screen claims otherwise (in case persist.sin was skipped)

- whoever unlocked without TA restore (and even never flashed persist.sin) would not have the attestation key working regardless the security screen claims otherwise

- what would be very interesting is TA restored after unlock on never downgraded device (that could have the attest key recovered and possibly working)

Please try to test this app and post some results. Maybe we can finally resolve this attestation key presence and loosing behaviour.

Thanks.