From 568079359d9931691fc7ddc9bd5cf8990c857241 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Thu, 13 Oct 2022 17:43:38 +0200 Subject: [PATCH] iOS - Load client certificate from local storage --- CHANGELOG.md | 3 +++ ios/Classes/InAppWebView/InAppWebView.swift | 26 ++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45d36035..7a42bfc0 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ - Fixed iOS 14.0 crash when calling `callAsyncJavaScript` method - Merged "Android fix leaking MethodChannel through anonymous class" [#1201](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1201) (thanks to [emakar](https://github.com/emakar)) - Merged "Fix RangeError: Maximum call stack size exceeded" [#1208](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1208) (thanks to [liasica](https://github.com/liasica)) +- Merged "fix: try to open with Chrome if default browser app does not support custom tabs" [#1233](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1233) (thanks to [addie9000](https://github.com/addie9000)) +- Merged "fix: Prevent Android java.lang.NullPointerException in InAppWebViewCl…" [#1237](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1237) (thanks to [kamilpowalowski](https://github.com/kamilpowalowski)) +- Merged "Android - Load client certificate from local storage" [#1241](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1241) (thanks to [akioyamamoto1977](https://github.com/akioyamamoto1977)) ## 5.4.4+3 diff --git a/ios/Classes/InAppWebView/InAppWebView.swift b/ios/Classes/InAppWebView/InAppWebView.swift index 4e79f56b..69ecacab 100755 --- a/ios/Classes/InAppWebView/InAppWebView.swift +++ b/ios/Classes/InAppWebView/InAppWebView.swift @@ -1770,21 +1770,19 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi let certificatePath = response["certificatePath"] as! String; let certificatePassword = response["certificatePassword"] as? String ?? ""; + 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) }