我尝试通过CFSocket连接在NSStream中使用SSL。所以我写了这段代码:
[self.input setProperty:NSStreamSocketSecurityLevelTLSv1 forKey:NSStreamSocketSecurityLevelKey];
[self.output setProperty:NSStreamSocketSecurityLevelTLSv1 forKey:NSStreamSocketSecurityLevelKey];
[self.input scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.output scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.input open];
[self.output open];但是如果我从curl或浏览器向我的服务器发送请求,我会得到这个错误:
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol当我使用这个解决方案NSStream SSL on used socket时,我仍然有相同的错误。
如何配置流以使用ssl?
发布于 2014-03-26 18:41:28
SSL/TLS有不同的版本。可能您正在连接的服务器无法使用TLS版本1进行通信。请尝试forKey:NSStreamSocketSecurityLevelKey的值NSStreamSocketSecurityLevelNegotiatedSSL,以获取您的连接的最高版本。
此外,尝试以这种方式设置SSL/TLS连接的属性
// Setting properties. Atm every certificate is accepted and no hostname will be checked
NSDictionary *settings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates,
[NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot,
[NSNumber numberWithBool:NO], kCFStreamSSLValidatesCertificateChain,
kCFNull,kCFStreamSSLPeerName,
nil];
CFReadStreamSetProperty((CFReadStreamRef)_inputStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);
CFWriteStreamSetProperty((CFWriteStreamRef)_outputStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);但请记住,当您以这种方式使用它时,没有太多的身份验证和防止中间人的保护。尝试使用设置来处理其他问题。
此外,发布更多代码并尝试连接到另一台使用https的服务器。
https://stackoverflow.com/questions/16618690
复制相似问题