Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/ios.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarino Faggiana <marino@marinofaggiana.com>2022-11-04 19:50:00 +0300
committerMarino Faggiana <marino@marinofaggiana.com>2022-11-04 19:50:00 +0300
commit0a6b49dc9f660a33603f081128ae4145163a05c4 (patch)
tree830620d31f96dde28d4e8f54b6d5d2c03b7859f4
parent18203c2974a1fd64990966afcd4a09247a7bed47 (diff)
fix URLAuthenticationChallenge
Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
-rw-r--r--iOSClient/BrowserWeb/NCBrowserWeb.swift10
-rw-r--r--iOSClient/Networking/NCNetworking.swift28
-rw-r--r--iOSClient/RichWorkspace/NCViewerRichWorkspaceWebView.swift10
-rw-r--r--iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift10
-rw-r--r--iOSClient/Viewer/NCViewerRichdocument/NCViewerRichdocument.swift10
5 files changed, 36 insertions, 32 deletions
diff --git a/iOSClient/BrowserWeb/NCBrowserWeb.swift b/iOSClient/BrowserWeb/NCBrowserWeb.swift
index ae1b4d714..6bb4ed479 100644
--- a/iOSClient/BrowserWeb/NCBrowserWeb.swift
+++ b/iOSClient/BrowserWeb/NCBrowserWeb.swift
@@ -110,10 +110,12 @@ class NCBrowserWeb: UIViewController {
extension NCBrowserWeb: WKNavigationDelegate {
public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- if let serverTrust = challenge.protectionSpace.serverTrust {
- completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
- } else {
- completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil)
+ DispatchQueue.global().async {
+ if let serverTrust = challenge.protectionSpace.serverTrust {
+ completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
+ } else {
+ completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil)
+ }
}
}
diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift
index 576c5f956..61a6a9e1d 100644
--- a/iOSClient/Networking/NCNetworking.swift
+++ b/iOSClient/Networking/NCNetworking.swift
@@ -129,11 +129,8 @@ import Photos
}
func authenticationChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
-
- if checkTrustedChallenge(session, didReceive: challenge) {
- completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
- } else {
- completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)
+ DispatchQueue.global().async {
+ self.checkTrustedChallenge(session, didReceive: challenge, completionHandler: completionHandler)
}
}
@@ -158,7 +155,7 @@ import Photos
// MARK: - Pinning check
- private func checkTrustedChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge) -> Bool {
+ private func checkTrustedChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
let protectionSpace: URLProtectionSpace = challenge.protectionSpace
let directoryCertificate = CCUtility.getDirectoryCerificates()!
@@ -166,14 +163,6 @@ import Photos
let certificateSavedPath = directoryCertificate + "/" + host + ".der"
var isTrusted: Bool
- #if !EXTENSION
- defer {
- if !isTrusted {
- DispatchQueue.main.async { (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host) }
- }
- }
- #endif
-
if let serverTrust: SecTrust = protectionSpace.serverTrust, let certificate = SecTrustGetCertificateAtIndex(serverTrust, 0) {
// extarct certificate txt
@@ -197,8 +186,15 @@ import Photos
} else {
isTrusted = false
}
-
- return isTrusted
+
+ if isTrusted {
+ completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
+ } else {
+ #if !EXTENSION
+ DispatchQueue.main.async { (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host) }
+ #endif
+ completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)
+ }
}
func writeCertificate(host: String) {
diff --git a/iOSClient/RichWorkspace/NCViewerRichWorkspaceWebView.swift b/iOSClient/RichWorkspace/NCViewerRichWorkspaceWebView.swift
index 6e6e177e2..9e9b6a1d5 100644
--- a/iOSClient/RichWorkspace/NCViewerRichWorkspaceWebView.swift
+++ b/iOSClient/RichWorkspace/NCViewerRichWorkspaceWebView.swift
@@ -103,10 +103,12 @@ class NCViewerRichWorkspaceWebView: UIViewController, WKNavigationDelegate, WKSc
// MARK: -
public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- if let serverTrust = challenge.protectionSpace.serverTrust {
- completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
- } else {
- completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil)
+ DispatchQueue.global().async {
+ if let serverTrust = challenge.protectionSpace.serverTrust {
+ completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
+ } else {
+ completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil)
+ }
}
}
diff --git a/iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift b/iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift
index 9b7335c57..28c862cb7 100644
--- a/iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift
+++ b/iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift
@@ -178,10 +178,12 @@ class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMes
// MARK: -
public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- if let serverTrust = challenge.protectionSpace.serverTrust {
- completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
- } else {
- completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil)
+ DispatchQueue.global().async {
+ if let serverTrust = challenge.protectionSpace.serverTrust {
+ completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
+ } else {
+ completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil)
+ }
}
}
diff --git a/iOSClient/Viewer/NCViewerRichdocument/NCViewerRichdocument.swift b/iOSClient/Viewer/NCViewerRichdocument/NCViewerRichdocument.swift
index 22e818863..77d765165 100644
--- a/iOSClient/Viewer/NCViewerRichdocument/NCViewerRichdocument.swift
+++ b/iOSClient/Viewer/NCViewerRichdocument/NCViewerRichdocument.swift
@@ -316,10 +316,12 @@ class NCViewerRichdocument: UIViewController, WKNavigationDelegate, WKScriptMess
// MARK: -
public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- if let serverTrust = challenge.protectionSpace.serverTrust {
- completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
- } else {
- completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil)
+ DispatchQueue.global().async {
+ if let serverTrust = challenge.protectionSpace.serverTrust {
+ completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
+ } else {
+ completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil)
+ }
}
}