Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)URLSession:(NSURLSession *)session
- task:(NSURLSessionTask *)task
- didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
- completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
- if (запинен ли хост) {
- [[[TrustKit sharedInstance] pinningValidator] handleChallenge:challenge completionHandler:completionHandler];
- return;
- }
- if (self.allowInvalidCertificates) {
- SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
- NSString *domain = challenge.protectionSpace.host;
- NSMutableArray *policies = [NSMutableArray array];
- [policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)];
- SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies);
- }
- __block NSURLCredential *credential = nil;
- NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
- if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
- disposition = NSURLSessionAuthChallengeUseCredential;
- credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
- }
- if (completionHandler) {
- completionHandler(disposition, credential);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement