SecKeyCreateRandomKey for SecureEnclave crash on iOS 13 simulator

I've encountered strange crash while using SecKeyCreateRandomKey on iOS 13.4 and 13.5 simulators.

I've used that to generate a private key that will stored in Secure Enclave. I think the crash happen on this attribute (needed to store the key to the Secure Enclave).

kSecAttrTokenID as String: kSecAttrTokenIDSecureEnclave,

I've tried enabling Swift Error Breakpoint, Exception Breakpoint, Symbolic Breakpoint, activating address sanitizer and zombie objects but I don't still get any useful information.

This is the repo to reproduce the crash (Make sure you choose iOS 13 simulators) https://github.com/jeffersonsetiawan/SecureEnclaveCrash/

Thank you.

Answered by DTS Engineer in 714594022

It work on ios 15 simulator

OK, then my answer is “Don’t do that.” (-:

Normally I’d suggest that you file a bug against the simulator but that’s not going to get any traction for the iOS 13 simulator.

If the crash is causing you grief — perhaps you rely on the simulator for iOS 13 compatibility testing — add code to your app that, in the simulator build only, disables the Secure Enclave code when running on older versions of iOS.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Here is the crash Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)

I've encountered strange crash while using SecKeyCreateRandomKey on iOS 13.4 and 13.5 simulators.

So, does that mean that things work on newer simulators?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

If running on the simulator the MacBook must be equipped with a touch bar or touch id otherwise should be supported on an A7 or later A-series CPU. To prevent the crash on a sim with a touch bar or touch id remove kSecAttrTokenID as String: kSecAttrTokenIDSecureEnclave, or exclude it from sim builds.

https://developer.apple.com/documentation/security/certificate_key_and_trust_services/keys/storing_keys_in_the_secure_enclave

Accepted Answer

It work on ios 15 simulator

OK, then my answer is “Don’t do that.” (-:

Normally I’d suggest that you file a bug against the simulator but that’s not going to get any traction for the iOS 13 simulator.

If the crash is causing you grief — perhaps you rely on the simulator for iOS 13 compatibility testing — add code to your app that, in the simulator build only, disables the Secure Enclave code when running on older versions of iOS.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

SecKeyCreateRandomKey for SecureEnclave crash on iOS 13 simulator
 
 
Q