1

我已经使用 ASyncSocket 成功地将我的服务器与套接字连接连接起来。现在我正在尝试进行 SSL 握手以将服务器与 SSL 连接。知道如何进行吗?

4

1 回答 1

2

AsyncSocket 的 ConnectTest 示例展示了如何实现安全设置。

- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port {
    NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithCapacity:3];
     [settings setObject:@"www.paypal.com" forKey:(NSString *)kCFStreamSSLPeerName];
    [sock startTLS:settings];

// To connect to a test server, with a self-signed certificate, use settings similar to this:

//  // Allow expired certificates
    //  [settings setObject:[NSNumber numberWithBool:YES]
    //               forKey:(NSString *)kCFStreamSSLAllowsExpiredCertificates];
    //  
    //  // Allow self-signed certificates
    //  [settings setObject:[NSNumber numberWithBool:YES]
    //               forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];
    //  
    //  // In fact, don't even validate the certificate chain
    //  [settings setObject:[NSNumber numberWithBool:NO]
    //               forKey:(NSString *)kCFStreamSSLValidatesCertificateChain];
    }
于 2013-01-04T16:02:30.147 回答