iOS - Load client certificate from local storage

This commit is contained in:
Lorenzo Pichilli 2022-10-13 17:44:07 +02:00
parent 0a49c7094f
commit 23d57ed807
1 changed files with 12 additions and 14 deletions

View File

@ -1993,21 +1993,19 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate,
let certificatePath = response.certificatePath
let certificatePassword = response.certificatePassword ?? "";
var path: String = certificatePath
do {
let path = try Util.getAbsPathAsset(assetFilePath: certificatePath)
let PKCS12Data = NSData(contentsOfFile: path)!
path = try Util.getAbsPathAsset(assetFilePath: certificatePath)
} catch {}
if let identityAndTrust: IdentityAndTrust = self.extractIdentity(PKCS12Data: PKCS12Data, password: certificatePassword) {
let urlCredential: URLCredential = URLCredential(
identity: identityAndTrust.identityRef,
certificates: identityAndTrust.certArray as? [AnyObject],
persistence: URLCredential.Persistence.forSession);
completionHandler(.useCredential, urlCredential)
} else {
completionHandler(.performDefaultHandling, nil)
}
} catch {
print(error.localizedDescription)
if let PKCS12Data = NSData(contentsOfFile: path),
let identityAndTrust: IdentityAndTrust = self.extractIdentity(PKCS12Data: PKCS12Data, password: certificatePassword) {
let urlCredential: URLCredential = URLCredential(
identity: identityAndTrust.identityRef,
certificates: identityAndTrust.certArray as? [AnyObject],
persistence: URLCredential.Persistence.forSession);
completionHandler(.useCredential, urlCredential)
} else {
completionHandler(.performDefaultHandling, nil)
}