aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/PrivateDataConfirmation.swift
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-02-06 03:23:51 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-06 06:20:23 +0100
commitbebcaa012bfafb5ab1a8ee4db11feffd3843c52c (patch)
treeee89b91f60bd267c356b0931d72bde9a288c8771 /WireGuard/WireGuard/UI/PrivateDataConfirmation.swift
parentLegacyConfig: Remove and support plaintext for .mobileconfig (diff)
downloadwireguard-apple-bebcaa012bfafb5ab1a8ee4db11feffd3843c52c.tar.xz
wireguard-apple-bebcaa012bfafb5ab1a8ee4db11feffd3843c52c.zip
PrivateDataConfirmation: prompt with touch/face/pin/password ID for viewing/exporting keys
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/PrivateDataConfirmation.swift37
1 files changed, 37 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/PrivateDataConfirmation.swift b/WireGuard/WireGuard/UI/PrivateDataConfirmation.swift
new file mode 100644
index 00000000..c03e64a7
--- /dev/null
+++ b/WireGuard/WireGuard/UI/PrivateDataConfirmation.swift
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 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()
+ }
+ }
+ }
+ }
+}