Joe
Joe

Reputation: 385

iOS How to do SSL handshake using ASyncSocket?

I have successfully connected my server with socket connection using ASyncSocket. Now I'm trying to do SSL handshake to connect server with SSL. Any idea how to proceed ?

Upvotes: 1

Views: 1446

Answers (1)

fshbn
fshbn

Reputation: 74

AsyncSocket's ConnectTest sample shows how to implement the security settings.

- (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];
    }

Upvotes: 2

Related Questions