Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASI support https ? #409

Open
cherish1 opened this issue Dec 22, 2016 · 1 comment
Open

ASI support https ? #409

cherish1 opened this issue Dec 22, 2016 · 1 comment

Comments

@cherish1
Copy link

ASI support https ?

@stone761220
Copy link

Of course, but need to modify the source code
Here are the changes I made to ASIHTTPRequest.m – (void)startRequest method:
//
// Handle SSL certificate settings
//
// kCFStreamSocketSecurityLevelTLSv1_0SSLv3 configures max TLS 1.0, min SSLv3
// kCFStreamSocketSecurityLevelTLSv1_0 configures to use only TLS 1.0.
// kCFStreamSocketSecurityLevelTLSv1_1 configures to use only TLS 1.1.
// kCFStreamSocketSecurityLevelTLSv1_2 configures to use only TLS 1.2.
if([[[[self url] scheme] lowercaseString] isEqualToString:@"https"]) {

    // Tell CFNetwork not to validate SSL certificates
    if (![self validatesSecureCertificate]) {
        // 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,
                                       @"kCFStreamSocketSecurityLevelTLSv1_2", kCFStreamSSLLevel,
                                       nil];
        
        CFReadStreamSetProperty((CFReadStreamRef)[self readStream],
                                kCFStreamPropertySSLSettings,
                                (CFTypeRef)sslProperties);
        [sslProperties release];
    }
    
    // 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
		[certificates addObject:(id)clientCertificateIdentity];

		// If we've added any additional certificates, add them too
		for (id cert in clientCertificates) {
			[certificates addObject:cert];
		}
        
        [sslProperties setObject:certificates forKey:(NSString *)kCFStreamSSLCertificates];
        [sslProperties setObject:@"kCFStreamSocketSecurityLevelTLSv1_2" forKey:(NSString *)kCFStreamSSLLevel];
        CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertySSLSettings, sslProperties);
    }
    
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants