Skip to content

Commit

Permalink
Merge release/1.84.0 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
daxmobile authored Apr 17, 2024
2 parents 416ec6d + bc50da6 commit 9436645
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Configuration/BuildNumber.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 164
CURRENT_PROJECT_VERSION = 165
6 changes: 3 additions & 3 deletions DuckDuckGo/Common/Utilities/CertificateTrustEvaluator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
29 changes: 20 additions & 9 deletions DuckDuckGo/Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 9436645

Please sign in to comment.