mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2024-12-24 10:32:36 +00:00
13b720442d
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
38 lines
1.1 KiB
Swift
38 lines
1.1 KiB
Swift
// SPDX-License-Identifier: MIT
|
|
// Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.
|
|
|
|
import Foundation
|
|
import LocalAuthentication
|
|
#if os(macOS)
|
|
import AppKit
|
|
#endif
|
|
|
|
class PrivateDataConfirmation {
|
|
static func confirmAccess(to reason: String, _ after: @escaping () -> Void) {
|
|
let context = LAContext()
|
|
|
|
var error: NSError?
|
|
if !context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
|
|
guard let error = error as? LAError else { return }
|
|
if error.code == .passcodeNotSet {
|
|
// We give no protection to folks who just don't set a passcode.
|
|
after()
|
|
}
|
|
return
|
|
}
|
|
|
|
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { success, _ in
|
|
DispatchQueue.main.async {
|
|
#if os(macOS)
|
|
if !NSApp.isActive {
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
}
|
|
#endif
|
|
if success {
|
|
after()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|