From 23d57ed807aac2b9d93ed4000d52a3821fe479a1 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Thu, 13 Oct 2022 17:44:07 +0200 Subject: [PATCH] iOS - Load client certificate from local storage --- ios/Classes/InAppWebView/InAppWebView.swift | 26 ++++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/ios/Classes/InAppWebView/InAppWebView.swift b/ios/Classes/InAppWebView/InAppWebView.swift index 38bea13e..b8c02f74 100755 --- a/ios/Classes/InAppWebView/InAppWebView.swift +++ b/ios/Classes/InAppWebView/InAppWebView.swift @@ -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)! - - 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) + path = try Util.getAbsPathAsset(assetFilePath: certificatePath) + } catch {} + + 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) }