1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-12011] Fix Unlock with biometrics on the Safari browser extension (#11040)

* Add biometricUnlockAvailable to SafariWebExtensionHandler
This commit is contained in:
Thomas Avery
2024-09-16 09:59:25 -05:00
committed by GitHub
parent 096a2563bb
commit 31a5aa9dd7

View File

@@ -88,12 +88,9 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
return return
case "biometricUnlock": case "biometricUnlock":
var error: NSError?
let laContext = LAContext() let laContext = LAContext()
laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) if(!laContext.isBiometricsAvailable()){
if let e = error, e.code != kLAErrorBiometryLockout {
response.userInfo = [ response.userInfo = [
SFExtensionMessageKey: [ SFExtensionMessageKey: [
"message": [ "message": [
@@ -162,6 +159,20 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
} }
return return
case "biometricUnlockAvailable":
let laContext = LAContext()
var isAvailable = laContext.isBiometricsAvailable();
response.userInfo = [
SFExtensionMessageKey: [
"message": [
"command": "biometricUnlockAvailable",
"response": isAvailable ? "available" : "not available",
"timestamp": Int64(NSDate().timeIntervalSince1970 * 1000),
],
],
]
break
default: default:
return return
} }
@@ -194,6 +205,20 @@ func jsonDeserialize<T: Decodable>(json: String?) -> T? {
} }
} }
extension LAContext {
func isBiometricsAvailable() -> Bool {
var error: NSError?
self.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)
if let e = error, e.code != kLAErrorBiometryLockout {
return false;
} else {
return true;
}
}
}
class DownloadFileMessage: Decodable, Encodable { class DownloadFileMessage: Decodable, Encodable {
var fileName: String var fileName: String
var blobData: String? var blobData: String?