Change biometric prompt to use the same logic as electron (#1805)

* Change biometric prompt to use the same logic as electron
This commit is contained in:
Oscar Hinton 2021-04-27 20:29:47 +02:00 committed by GitHub
parent cbe4be59d4
commit 5bf10376a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 4 deletions

View File

@ -85,7 +85,9 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
var error: NSError? var error: NSError?
let laContext = LAContext() let laContext = LAContext()
guard laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else { laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)
if let e = error, e.code != kLAErrorBiometryLockout {
response.userInfo = [ response.userInfo = [
SFExtensionMessageKey: [ SFExtensionMessageKey: [
"message": [ "message": [
@ -95,10 +97,22 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
], ],
], ],
] ]
break; break
} }
laContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Bitwarden Safari Extension") { (success, error) in guard let accessControl = SecAccessControlCreateWithFlags(nil, kSecAttrAccessibleWhenUnlockedThisDeviceOnly, [.privateKeyUsage, .userPresence], nil) else {
response.userInfo = [
SFExtensionMessageKey: [
"message": [
"command": "biometricUnlock",
"response": "not supported",
"timestamp": Int64(NSDate().timeIntervalSince1970 * 1000),
],
],
]
break
}
laContext.evaluateAccessControl(accessControl, operation: .useKeySign, localizedReason: "Bitwarden Safari Extension") { (success, error) in
if success { if success {
let passwordName = "key" let passwordName = "key"
var passwordLength: UInt32 = 0 var passwordLength: UInt32 = 0
@ -134,7 +148,7 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
context.completeRequest(returningItems: [response], completionHandler: nil) context.completeRequest(returningItems: [response], completionHandler: nil)
} }
return; return
default: default:
return return
} }