Hello,
I am experiencing an issue with the SecItemDelete() function using iPhone 13Pro with iOS 15.1.
A call to SecItemDelete() crashes with EXC_BREAKPOINT under certain conditions outlined below:
- Make sure Iphone has a passcode set.
- Call SecKeyGeneratePair() to create an EC key pair with kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly and kSecAttrTokenIDSecureEnclave.
- Remove passcode from iPhone
- Set a new passcode for iPhone.
- Call SecItemDelete() to delete private key from SecureEnclave. This call fails with -26275 (errSecInvalidKey) which is expected as the key is destroyed already
- Call SecItemDelete() to delete public key from KeyChain.
- SecItemDelete causes a trace trap and app crashes.
I can not see any obvious problems in the code that should generate this behaviour. I am in urgent need to fix this problem and would really appreciate some help or pointers.
The backtrace for the crashing thread below.
More info can be provided if necessary.
To me it seems to be related to situations where SecItemDelete() has returned an error (where secure enclave is involved) and that the next call generates the trap.
Kind regards, Steffen
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x18067911c)
frame #0: 0x000000018067911c CoreFoundation`CFRelease + 88
frame #1: 0x00000001894420f0 Security`SetLastError + 76
frame #2: 0x000000018943ee18 Security`SecOSStatusWith + 140
frame #3: 0x00000001894436d4 Security`SecItemDelete + 524
* frame #4: 0x000000010076d3bc TheApp`-[TheAppCrypto deleteKey:isRSA:useSecureEnclave:keychainGroup:error:](self=0x00000002833ec160