diff --git a/SoftU2FTool/UserPresence.swift b/SoftU2FTool/UserPresence.swift index 7beaf5e..92fb99a 100644 --- a/SoftU2FTool/UserPresence.swift +++ b/SoftU2FTool/UserPresence.swift @@ -7,6 +7,7 @@ // import Foundation +import LocalAuthentication class UserPresence: NSObject { enum Notification { @@ -63,6 +64,37 @@ class UserPresence: NSObject { // Send a notification popup to the user. func test(_ type: Notification) { + if #available(OSX 10.12.2, *) { + let ctx = LAContext() + + if ctx.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) { + ctx.localizedCancelTitle = "Cancel" + ctx.localizedFallbackTitle = "Skip TouchID" + + var prompt: String + switch type { + case let .Register(facet): + prompt = "register with " + (facet ?? "site") + case let .Authenticate(facet): + prompt = "authenticate with " + (facet ?? "site") + } + + ctx.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: prompt) { (success, err) in + guard let lerr = err as? LAError else { + self.complete(success) + return + } + + switch lerr.code { + case .userFallback: + self.sendNotification(type) + default: + self.complete(false) + } + } + return + } + } sendNotification(type) }