This is the correct way to do this. while doing this (setting the property after socket connection) is undocumented, this is code directly from my Monal xmpp client and apple has never given me any problems in the app store.
NSInputStream *iStream;
NSOutputStream *oStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)server, port, &iStream, &oStream);
[iStream open];
[oStream open];
Once the connection has been opened and you get NSStreamEventOpenCompleted and the startTLS command has been sent to the host from the client:
NSDictionary *settings = [ [NSDictionary alloc ]
initWithObjectsAndKeys:
[NSNumber numberWithBool:YES], @"kCFStreamSSLAllowsExpiredCertificates",
[NSNumber numberWithBool:YES], @"kCFStreamSSLAllowsExpiredRoots",
[NSNumber numberWithBool:YES], @"kCFStreamSSLAllowsAnyRoot",
[NSNumber numberWithBool:NO], @"kCFStreamSSLValidatesCertificateChain",
[NSNull null],@"kCFStreamSSLPeerName",
@"kCFStreamSocketSecurityLevelNegotiatedSSL",
@"kCFStreamSSLLevel",
nil ];
CFReadStreamSetProperty((CFReadStreamRef)iStream,
@"kCFStreamPropertySSLSettings", (CFTypeRef)settings);
CFWriteStreamSetProperty((CFWriteStreamRef)oStream,
@"kCFStreamPropertySSLSettings", (CFTypeRef)settings);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…