Skip to content

Commit

Permalink
Merge pull request #264 from ikarius/master
Browse files Browse the repository at this point in the history
issue #263 - proposed patch
  • Loading branch information
greenisus committed Oct 5, 2011
2 parents f7fe5c7 + 6600374 commit c27b8f5
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions Classes/ASIHTTPRequest.m
Expand Up @@ -1198,18 +1198,28 @@ - (void)startRequest
// Handle SSL certificate settings
//

if([[[[self url] scheme] lowercaseString] isEqualToString:@"https"]) {

NSMutableDictionary *sslProperties = [NSMutableDictionary dictionaryWithCapacity:1];

if([[[[self url] scheme] lowercaseString] isEqualToString:@"https"]) {

// Tell CFNetwork not to validate SSL certificates
if (![self validatesSecureCertificate]) {
[sslProperties setObject:(NSString *)kCFBooleanFalse forKey:(NSString *)kCFStreamSSLValidatesCertificateChain];
}

// see: http://iphonedevelopment.blogspot.com/2010/05/nsstream-tcp-and-ssl.html

NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates,
[NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot,
[NSNumber numberWithBool:NO], kCFStreamSSLValidatesCertificateChain,
kCFNull,kCFStreamSSLPeerName,
nil];

CFReadStreamSetProperty((CFReadStreamRef)[self readStream],
kCFStreamPropertySSLSettings,
(CFTypeRef)sslProperties);
}

// Tell CFNetwork to use a client certificate
if (clientCertificateIdentity) {

NSMutableDictionary *sslProperties = [NSMutableDictionary dictionaryWithCapacity:1];

NSMutableArray *certificates = [NSMutableArray arrayWithCapacity:[clientCertificates count]+1];

// The first object in the array is our SecIdentityRef
Expand All @@ -1219,10 +1229,12 @@ - (void)startRequest
for (id cert in clientCertificates) {
[certificates addObject:cert];
}

[sslProperties setObject:certificates forKey:(NSString *)kCFStreamSSLCertificates];

CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertySSLSettings, sslProperties);
}

CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertySSLSettings, sslProperties);

}

//
Expand Down

0 comments on commit c27b8f5

Please sign in to comment.