我在iOS
申请中工作。
我尝试使用https
连接连接到NSStream
服务器。
使用NSURLConnection
,这项工作正常,我可以信任这样的挑战:
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
}
但我的问题是Stream中唯一可用的代理是:
- (void) stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
}
如何管理?
答案 0 :(得分:0)
我终于找到了解决方案。感谢Wireshark
[inStream setProperty:(id)kCFBooleanFalse forKey:(NSString *)kCFStreamPropertyShouldCloseNativeSocket];
[outStream setProperty:(id)kCFBooleanFalse forKey:(NSString *)kCFStreamPropertyShouldCloseNativeSocket];
NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithCapacity:1];
[settings setObject:_certificates forKey:(id)kCFStreamSSLCertificates];
[settings setObject:(NSString *)NSStreamSocketSecurityLevelNegotiatedSSL forKey:(NSString *)kCFStreamSSLLevel];
[settings setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];
[settings setObject:@"MY HOST" forKey:(NSString *)kCFStreamSSLPeerName];
CFReadStreamSetProperty((CFReadStreamRef)inStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);
CFWriteStreamSetProperty((CFWriteStreamRef)outStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);
最重要的是设置没有当前证书的证书。 您应该在链中设置当前标识和其他证书。 这应该由iOSX使用Identity设置,通常私有密钥将可用于流。
希望这个帮助