AsyncSocket startTLS: CFNetwork SSLHandshake error (-9806) on iOS8.0
My application uses a self signed ssl certificate to connect to a tcp server. It worked up to iOS7.1, after iOS8.0 it had a problem disconnecting net weight assuming: CFNetwork SSLHandshake failed (-9806) and cannot reconnect.
I am using method: startTLS to install ssl, code as below:
// Configure SSL/TLS settings
NSMutableDictionary *sslSettings = [[NSMutableDictionary alloc] init];
NSData *pkcs12data = [[NSData alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:certificate ofType:@"p12"]];
CFDataRef inPKCS12Data = (CFDataRef)CFBridgingRetain(pkcs12data);
CFStringRef password = CFSTR("123456");
const void *keys[] = { kSecImportExportPassphrase };
const void *values[] = { password };
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
OSStatus securityError = SecPKCS12Import(inPKCS12Data, options, &items);
CFRelease(options);
CFRelease(password);
[pkcs12data release];
if(securityError == errSecSuccess) {
NSLog(@"Success opening p12 certificate.");
}
CFDictionaryRef identityDict = CFArrayGetValueAtIndex(items, 0);
SecIdentityRef myIdent = (SecIdentityRef)CFDictionaryGetValue(identityDict,
kSecImportItemIdentity);
SecIdentityRef certArray[1] = { myIdent };
CFArrayRef myCerts = CFArrayCreate(NULL, (void *)certArray, 1, NULL);
[sslSettings setObject:(id)CFBridgingRelease(myCerts) forKey:(NSString *)kCFStreamSSLCertificates];
[sslSettings setObject:NSStreamSocketSecurityLevelSSLv2 forKey:(NSString *)kCFStreamSSLLevel];
[sslSettings setObject:(id)kCFBooleanFalse forKey:(NSString *)kCFStreamSSLValidatesCertificateChain];
+3
source to share
No one has answered this question yet
Check out similar questions: