Advertisement
Guest User

Untitled

a guest
May 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)URLSession:(NSURLSession *)session
  2.               task:(NSURLSessionTask *)task
  3. didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
  4.  completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
  5.     if (запинен ли хост) {
  6.         [[[TrustKit sharedInstance] pinningValidator] handleChallenge:challenge completionHandler:completionHandler];
  7.         return;
  8.     }
  9.    
  10.     if (self.allowInvalidCertificates) {
  11.         SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
  12.         NSString *domain = challenge.protectionSpace.host;
  13.         NSMutableArray *policies = [NSMutableArray array];
  14.         [policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)];
  15.         SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies);
  16.     }
  17.    
  18.     __block NSURLCredential *credential = nil;
  19.     NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
  20.     if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
  21.         disposition = NSURLSessionAuthChallengeUseCredential;
  22.         credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
  23.     }
  24.    
  25.     if (completionHandler) {
  26.         completionHandler(disposition, credential);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement