Will SecKeyCopyPublicKey always produce the same public key also for
secure enclave ECC generated private key?
I don’t really understand what you mean by “the same” here. However, I can confirm that
SecKeyCopyPublicKey will produce a public key for a private key even if that private key is an ECC key protected by the SE.
Could you provide some of the examples on the issues that you
mentioned that could happen if we store public key in the keychain
There’s a bug in
SecKeyGeneratePair that causes it to mark both keys as private (r. 15615260). This causes trouble later on when you import the certificate and form an identity, because the identity formation code looks for the matching private key and, on occasion, finds the public key. Needless to say, that doesn’t end well.
The good news here is that the workaround,
don’t only store the private key by switching to
SecKeyCreateRandomKey, is also the best solution because:
SecKeyCreateRandomKey is a nicer API.
SecKeyCopyPublicKey lets you easily get the public key.
You don’t waste space in the keychain (OK, so it’s a trivial amount of space but still…).
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"