How to establish a SecIdentityRef in an iPhone keychain ? (Without a .p12)

北战南征 提交于 2019-11-28 07:40:14

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:

  1. Generate the key pair
  2. Get a certificate that matches the private key
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!