Skip to content

Commit

Permalink
Fix brave/brave-ios#5543: Relax SSL Certificate Validation to match a…
Browse files Browse the repository at this point in the history
…ll other browsers (brave/brave-ios#7588)

Relax SSL validation. Use Chromium validation over Apple's validation.
If Chromium returns a value indicating that the system should handle it, then we use Apple's validation.
However, we disable X509 validation and only validate it for SSL.

Signed-off-by: Brandon T <[email protected]>
  • Loading branch information
Brandon-T authored Jun 13, 2023
1 parent dc45078 commit e66e15c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
38 changes: 33 additions & 5 deletions Sources/Brave/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1722,17 +1722,45 @@ public class BrowserViewController: UIViewController {
break
}

let host = tab.webView?.url?.host
guard let scheme = tab.webView?.url?.scheme,
let host = tab.webView?.url?.host else {
tab.secureContentState = .insecure
self.updateURLBar()
return
}

Task {
let port: Int
if let urlPort = tab.webView?.url?.port {
port = urlPort
} else if scheme == "https" {
port = 443
} else {
port = 80
}

Task.detached {
do {
try await BraveCertificateUtils.evaluateTrust(serverTrust, for: host)
tab.secureContentState = .secure
let result = BraveCertificateUtility.verifyTrust(serverTrust,
host: host,
port: port)
// Cert is valid!
if result == 0 {
tab.secureContentState = .secure
} else if result == Int32.min {
// Cert is valid but should be validated by the system
// Let the system handle it and we'll show an error if the system cannot validate it
try await BraveCertificateUtils.evaluateTrust(serverTrust, for: host)
tab.secureContentState = .secure
} else {
tab.secureContentState = .insecure
}
} catch {
tab.secureContentState = .insecure
}

self.updateURLBar()
Task { @MainActor in
self.updateURLBar()
}
}
case ._sampledPageTopColor:
updateStatusBarOverlayColor()
Expand Down
1 change: 0 additions & 1 deletion Sources/CertificateUtilities/BraveCertificateUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ public extension BraveCertificateUtils {

static func evaluateTrust(_ trust: SecTrust, for host: String?) async throws {
let policies = [
SecPolicyCreateBasicX509(),
SecPolicyCreateSSL(true, host as CFString?),
]

Expand Down

0 comments on commit e66e15c

Please sign in to comment.