Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malware protection 5: Refactor Special Error Types #3642

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1705,20 +1705,16 @@ extension TabViewController: WKNavigationDelegate {

private func loadSpecialErrorPageIfNeeded(error: NSError) {
guard featureFlagger.isFeatureOn(.sslCertificatesBypass),
error.code == NSURLErrorServerCertificateUntrusted,
let errorCode = error.userInfo["_kCFStreamErrorCodeKey"] as? Int32,
let failedURL = error.failedUrl else {
return
}
error.isServerCertificateUntrusted,
let errorType = error.sslErrorType,
let failedURL = error.failedUrl,
let host = failedURL.host else { return }

let tld = storageCache.tld
let errorType = SSLErrorType.forErrorCode(Int(errorCode))
self.failedURL = failedURL
errorData = SpecialErrorData(kind: .ssl,
errorType: errorType.rawValue,
domain: failedURL.host,
eTldPlus1: tld.eTLDplus1(failedURL.host))
errorData = SpecialErrorData.ssl(type: errorType, domain: host, eTldPlus1: tld.eTLDplus1(host))
loadSpecialErrorPage(url: failedURL)
Pixel.fire(pixel: .certificateWarningDisplayed(errorType.rawParameter))
Pixel.fire(pixel: .certificateWarningDisplayed(errorType.pixelParameter))
}

private func loadSpecialErrorPage(url: URL) {
Expand Down Expand Up @@ -3138,7 +3134,7 @@ extension UserContentController {

extension TabViewController: SpecialErrorPageUserScriptDelegate {

func leaveSite() {
func leaveSiteAction() {
Pixel.fire(pixel: .certificateWarningLeaveClicked)
guard webView?.canGoBack == true else {
delegate?.tabDidRequestClose(self)
Expand All @@ -3147,7 +3143,7 @@ extension TabViewController: SpecialErrorPageUserScriptDelegate {
_ = webView?.goBack()
}

func visitSite() {
func visitSiteAction() {
Pixel.fire(pixel: .certificateWarningProceedClicked)
isSpecialErrorPageVisible = false
shouldBypassSSLError = true
Expand Down
Loading