我的 SSL 证书与 .html 文件完美配合。我遇到了 .manifest 和 .ipa 文件的问题。
我为 SSL 所做的是创建MyHTTPConnection
实现以下内容的类:
- (NSArray *)sslIdentityAndCertificates
{
SecIdentityRef identityRef = NULL;
SecCertificateRef certificateRef = NULL;
SecTrustRef trustRef = NULL;
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"server" ofType:@"pfx"];
NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath];
CFDataRef inPKCS12Data = (__bridge CFDataRef)PKCS12Data;
CFStringRef password = CFSTR("test123");
const void *keys[] = { kSecImportExportPassphrase };
const void *values[] = { password };
CFDictionaryRef optionsDictionary = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
OSStatus securityError = errSecSuccess;
securityError = SecPKCS12Import(inPKCS12Data, optionsDictionary, &items);
if (securityError == 0) {
CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex (items, 0);
const void *tempIdentity = NULL;
tempIdentity = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemIdentity);
identityRef = (SecIdentityRef)tempIdentity;
const void *tempTrust = NULL;
tempTrust = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemTrust);
trustRef = (SecTrustRef)tempTrust;
} else {
NSLog(@"Failed with error code %d",(int)securityError);
return nil;
}
SecIdentityCopyCertificate(identityRef, &certificateRef);
NSArray *result = [[NSArray alloc] initWithObjects:(__bridge id)identityRef, (__bridge id)certificateRef, nil];
return result;
}
然后在 App Delegate 中,我刚刚将此自定义连接类设置为httpServer
:
[httpServer setConnectionClass:[MyHTTPConnection class]];
您需要做的最后一件事是将server.pfx
证书添加到捆绑包中。我按照本教程创建了证书。我只是做了,直到你有 server.crt 文件。然后我将其转换为pfx12
in this website。我这样做是因为 p12 证书不起作用,我遇到了这个问题。
克里斯,你能否编辑你的条目,解释一下你是如何做清单的。我想做和你完全一样的事,但我遇到了你需要打开的 URL 的问题。