Tag: truststore

SocketRocket和iOS证书固定

我目前使用SocketRocket作为我的iOS应用程序的WebSocket实现,并希望将我的服务器的CA作为具有SR_SSLPinnedCertificates属性的可信证书进行绑定。 我正在寻找加载一个或多个证书传递到SocketRocket的一个很好的例子。 我有下面的代码工作,但我不知道这是正确的,或者如果有一个更直接的方法。 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); }