現在、iOS アプリケーションの WebSocket 実装として SocketRocket を使用しており、SR_SSLPinnedCertificates プロパティを使用して、サーバーの CA を信頼できる証明書として固定したいと考えています。SocketRocket に渡す 1 つ以上の証明書を読み込む良い例を探しています。次のコードが機能するようになりましたが、それが正しいかどうか、またはより簡単なアプローチがあるかどうかはわかりません。
CFArrayRef keyref = NULL;
NSString *path = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"p12"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
OSStatus status = SecPKCS12Import((__bridge CFDataRef)data, (__bridge CFDictionaryRef)[NSDictionary dictionaryWithObject:@"eftl_key_pass" forKey:(__bridge id)kSecImportExportPassphrase], &keyref);
if (status == noErr) {
CFDictionaryRef identityDict = CFArrayGetValueAtIndex(keyref, 0);
SecIdentityRef identityRef = (SecIdentityRef)CFDictionaryGetValue(identityDict, kSecImportItemIdentity);
SecCertificateRef certRef = NULL;
SecIdentityCopyCertificate(identityRef, &certRef);
}