OK, to answer my own question:
On iOS the keychain will automatically bound the certificate to the private key. That means you only need to:
- Generate the key pair
- Get a certificate that matches the private key
- Insert the certificate into the keychain.
After this you should be able to get a SecIdentityRef for the certificate / private key.
IMPORTANT:
SecItemAdd function allows you to insert the certificate data directly (NSData of the DER representation). This way you will be able to get a valid certificate reference, but not an identity ref.
The right way to insert the certificate is to first use the SecCertificateCreateWithData function over the DER bytes of the certificate. This will return a SecCertificateRef object which then should be used to persist the certificate into the keychain using the SecItemAdd function.
I hope this will make someone's life easier ;-)
Regards,
Pece
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…