Advertisement
KY1VSTAR

#3

May 25th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.85 KB | None | 0 0
  1. class SSLPinningURLSessionDelegate: NSObject, URLSessionDelegate {
  2.    
  3.     private let md5Fingerprint: String
  4.    
  5.     init(md5Fingerprint: String) {
  6.         print("inited")
  7.         self.md5Fingerprint = md5Fingerprint
  8.     }
  9.    
  10.     deinit {
  11.         print("SSLPinningURLSessionDelegate deinited")
  12.     }
  13.    
  14.     func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void) {
  15.         if !Global.isSSLPinningEnabled || challenge.isTrusted(md5Fingerprint: md5Fingerprint) {
  16.             let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
  17.             completionHandler(.useCredential, credential)
  18.         } else {
  19.             completionHandler(.cancelAuthenticationChallenge, nil)
  20.         }
  21.     }
  22.    
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement