Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SSLPinningURLSessionDelegate: NSObject, URLSessionDelegate {
- private let md5Fingerprint: String
- init(md5Fingerprint: String) {
- print("inited")
- self.md5Fingerprint = md5Fingerprint
- }
- deinit {
- print("SSLPinningURLSessionDelegate deinited")
- }
- func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void) {
- if !Global.isSSLPinningEnabled || challenge.isTrusted(md5Fingerprint: md5Fingerprint) {
- let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
- completionHandler(.useCredential, credential)
- } else {
- completionHandler(.cancelAuthenticationChallenge, nil)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement