0

我正在iOS应用程序中工作。我正在尝试通过连接连接到https服务器NSStream。有了NSURLConnection,这项工作很好,我可以相信这样的挑战:

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

}

但我的问题是 Stream 中唯一可用的委托是:

- (void) stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {

} 

如何管理这个?

4

1 回答 1

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 设置,并且通常私钥可用于流。

希望这有帮助

于 2013-04-10T08:49:35.387 回答