1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-23 03:22:50 +02: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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -88,12 +88,9 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
return
case "biometricUnlock":
var error: NSError?
let laContext = LAContext()
laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)
if let e = error, e.code != kLAErrorBiometryLockout {
if(!laContext.isBiometricsAvailable()){
response.userInfo = [
SFExtensionMessageKey: [
"message": [
@ -162,6 +159,20 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
}
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:
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 {
var fileName: String
var blobData: String?