diff --git a/Configuration/BuildNumber.xcconfig b/Configuration/BuildNumber.xcconfig index 79e38e6271..b71e1d4a29 100644 --- a/Configuration/BuildNumber.xcconfig +++ b/Configuration/BuildNumber.xcconfig @@ -1 +1 @@ -CURRENT_PROJECT_VERSION = 164 +CURRENT_PROJECT_VERSION = 165 diff --git a/DuckDuckGo/Common/Utilities/CertificateTrustEvaluator.swift b/DuckDuckGo/Common/Utilities/CertificateTrustEvaluator.swift index 541f61c95d..63ea3638cd 100644 --- a/DuckDuckGo/Common/Utilities/CertificateTrustEvaluator.swift +++ b/DuckDuckGo/Common/Utilities/CertificateTrustEvaluator.swift @@ -19,13 +19,13 @@ import Foundation protocol CertificateTrustEvaluating { - func evaluateCertificateTrust(trust: SecTrust?) -> Bool? + func evaluateCertificateTrust(trust: SecTrust?) async -> Bool? } struct CertificateTrustEvaluator: CertificateTrustEvaluating { - func evaluateCertificateTrust(trust: SecTrust?) -> Bool? { + func evaluateCertificateTrust(trust: SecTrust?) async -> Bool? { var error: CFError? - guard let trust else { return nil } + guard let trust = trust else { return nil } let result = SecTrustEvaluateWithError(trust, &error) return result } diff --git a/DuckDuckGo/Tab/Model/Tab.swift b/DuckDuckGo/Tab/Model/Tab.swift index 39b66c9daa..4b6667c15c 100644 --- a/DuckDuckGo/Tab/Model/Tab.swift +++ b/DuckDuckGo/Tab/Model/Tab.swift @@ -1224,12 +1224,9 @@ protocol NewWindowPolicyDecisionMaker { webView.publisher(for: \.serverTrust) .sink { [weak self] serverTrust in - guard let self else { return } - self.isCertificateValid = self.certificateTrustEvaluator.evaluateCertificateTrust(trust: serverTrust) - if self.isCertificateValid == true { - self.privacyInfo?.serverTrust = serverTrust - } else { - self.privacyInfo?.serverTrust = nil + Task { [weak self] in + guard let self = self else { return } + await self.updatePrivacyInfo(with: serverTrust) } } .store(in: &webViewCancellables) @@ -1244,6 +1241,18 @@ protocol NewWindowPolicyDecisionMaker { } } + private func updatePrivacyInfo(with trust: SecTrust?) async { + let isValid = await self.certificateTrustEvaluator.evaluateCertificateTrust(trust: trust) + await MainActor.run { + self.isCertificateValid = isValid + if isValid ?? false { + self.privacyInfo?.serverTrust = trust + } else { + self.privacyInfo?.serverTrust = nil + } + } + } + private func dismissPresentedAlert() { if let userInteractionDialog { switch userInteractionDialog.dialog { @@ -1489,15 +1498,17 @@ extension Tab/*: NavigationResponder*/ { // to be moved to Tab+Navigation.swift invalidateInteractionStateData() - if !error.isFrameLoadInterrupted, !error.isNavigationCancelled, error.errorCode != NSURLErrorServerCertificateUntrusted, + if !error.isFrameLoadInterrupted, !error.isNavigationCancelled, // don‘t show an error page if the error was already handled // (by SearchNonexistentDomainNavigationResponder) or another navigation was triggered by `setContent` self.content.urlForWebView == url { self.error = error // when already displaying the error page and reload navigation fails again: don‘t navigate, just update page HTML - let shouldPerformAlternateNavigation = navigation.url != webView.url || navigation.navigationAction.targetFrame?.url != .error - loadErrorHTML(error, header: UserText.errorPageHeader, forUnreachableURL: url, alternate: shouldPerformAlternateNavigation) + if error.errorCode != NSURLErrorServerCertificateUntrusted { + let shouldPerformAlternateNavigation = navigation.url != webView.url || navigation.navigationAction.targetFrame?.url != .error + loadErrorHTML(error, header: UserText.errorPageHeader, forUnreachableURL: url, alternate: shouldPerformAlternateNavigation) + } } }