Created
May 25, 2021 12:23
-
-
Save kalyaganov/25708e03de6a0f52afd22b76bb6d9acf to your computer and use it in GitHub Desktop.
Ktor self signed certs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let skipSessionDelegate = SkipSSLSessionDelegate() | |
SDK( | |
// .... | |
challengeHandler: { (session, task, authenticationChallenge, completionHandler) in | |
skipSessionDelegate.urlSession?(session, didReceive: authenticationChallenge) { | |
(authChallengeDisposition, urlCredentials) in | |
completionHandler(KotlinLong(integerLiteral: authChallengeDisposition.rawValue), urlCredentials) | |
} | |
} | |
// .... | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun createHttpEngine(challengeHandler: ChallengeHandler? = null): HttpClientEngine { | |
return Ios.create { | |
challengeHandler?.let { handleChallenge(it) } | |
} | |
} | |
// create SDK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
open class SkipSSLSessionDelegate: NSObject, URLSessionDelegate { | |
public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> ()) { | |
NSLog("URLAuthenticationChallenge auth method %@", challenge.protectionSpace.authenticationMethod) | |
if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) { | |
guard let serverTrust = challenge.protectionSpace.serverTrust else { | |
completionHandler(.cancelAuthenticationChallenge, nil) | |
return | |
} | |
completionHandler(.useCredential, URLCredential(trust: serverTrust)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment