在GCDAsyncSocket中实现安全性

时间:2016-01-26 22:04:58

标签: gcdasyncsocket

我正在尝试使用自签名证书在GCDAsyncSocket中实现安全性。在调用startTLS之后,没有调用didReceiveTrust方法。

SecIdentityRef identityRef = nil;
NSArray *certs = [[NSArray alloc] initWithObjects:(__bridge id)identityRef, nil];
NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithCapacity:3];

[settings setObject:[NSNumber numberWithInteger:0] forKey:GCDAsyncSocketSSLProtocolVersionMax];
[settings setObject:[NSNumber numberWithBool:YES] forKey:GCDAsyncSocketManuallyEvaluateTrust];
[settings setObject:certs forKey:GCDAsyncSocketSSLCertificates];

1 个答案:

答案 0 :(得分:0)

您没有显示正在使用settings的位置。

在致电startTLS时,您必须将GCDAsyncSocketManuallyEvaluateTrust设为@YES

[self.socket startTLS:@{GCDAsyncSocketManuallyEvaluateTrust: @YES}];

相关文档:http://cocoadocs.org/docsets/CocoaAsyncSocket/7.4.1/Classes/GCDAsyncSocket.html#//api/name/startTLS