From e4842fb1cac31471823ef75f257a34a2ce2cd823 Mon Sep 17 00:00:00 2001 From: Soner YUKSEL Date: Fri, 1 Sep 2023 11:10:19 -0400 Subject: [PATCH] Ref #7980: [Follow up to #7952] Opening in private from home screen will bypass biometrics (#8011) --- Sources/Brave/Frontend/Browser/NavigationRouter.swift | 2 +- Sources/Brave/Frontend/Browser/QuickActions.swift | 2 +- Sources/Brave/Frontend/Passcode/WindowProtection.swift | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/NavigationRouter.swift b/Sources/Brave/Frontend/Browser/NavigationRouter.swift index 93c678c8b85..62f607d26da 100644 --- a/Sources/Brave/Frontend/Browser/NavigationRouter.swift +++ b/Sources/Brave/Frontend/Browser/NavigationRouter.swift @@ -115,7 +115,7 @@ public enum NavigationPath: Equatable { bvc.openBlankNewTab(attemptLocationFieldFocus: false, isPrivate: true) } else { if Preferences.Privacy.privateBrowsingLock.value { - bvc.askForLocalAuthentication(viewType: .widget) { [weak bvc] success, _ in + bvc.askForLocalAuthentication(viewType: .external) { [weak bvc] success, _ in if success { bvc?.openBlankNewTab(attemptLocationFieldFocus: false, isPrivate: true) } diff --git a/Sources/Brave/Frontend/Browser/QuickActions.swift b/Sources/Brave/Frontend/Browser/QuickActions.swift index 26aa7a732ed..96184595225 100644 --- a/Sources/Brave/Frontend/Browser/QuickActions.swift +++ b/Sources/Brave/Frontend/Browser/QuickActions.swift @@ -64,7 +64,7 @@ public class QuickActions: NSObject { handleOpenNewTab(withBrowserViewController: browserViewController, isPrivate: true) } else { if Preferences.Privacy.privateBrowsingLock.value { - browserViewController.askForLocalAuthentication(viewType: .widget) { [weak self] success, _ in + browserViewController.askForLocalAuthentication(viewType: .external) { [weak self] success, _ in if success { self?.handleOpenNewTab(withBrowserViewController: browserViewController, isPrivate: true) } diff --git a/Sources/Brave/Frontend/Passcode/WindowProtection.swift b/Sources/Brave/Frontend/Passcode/WindowProtection.swift index 101d25acc08..2f9b03cf9be 100644 --- a/Sources/Brave/Frontend/Passcode/WindowProtection.swift +++ b/Sources/Brave/Frontend/Passcode/WindowProtection.swift @@ -14,7 +14,7 @@ import SwiftKeychainWrapper import os.log public enum AuthViewType { - case general, widget, sync, tabTray, passwords + case external, general, sync, tabTray, passwords } public class WindowProtection { @@ -165,7 +165,7 @@ public class WindowProtection { .sink(receiveValue: { [weak self] _ in guard let self = self else { return } self.context = LAContext() // Reset context for new session - self.updateVisibleStatusForForeground() + self.updateVisibleStatusForForeground(viewType: .external) }) .store(in: &cancellables) } @@ -211,13 +211,15 @@ public class WindowProtection { } private func presentLocalAuthentication(viewType: AuthViewType, completion: ((Bool, LAError.Code?) -> Void)? = nil) { + self.viewType = viewType + if !context.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil) { completion?(false, .passcodeNotSet) return } lockedViewController.unlockButton.isHidden = true - if viewType == .widget { + if viewType == .external { isCancellable = false } @@ -235,7 +237,7 @@ public class WindowProtection { completion?(true, nil) }) } else { - lockedViewController.unlockButton.isHidden = viewType == .general || viewType == .widget + lockedViewController.unlockButton.isHidden = viewType == .general let errorPolicy = error as? LAError completion?(false, errorPolicy?.code)