From b8642e40be49a138cc8343527f4b69cd37d161a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sat, 15 Mar 2025 14:56:59 +0100 Subject: [PATCH 1/3] Fix spelling --- keymaster.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keymaster.swift b/keymaster.swift index 747297e..8a526b0 100644 --- a/keymaster.swift +++ b/keymaster.swift @@ -76,7 +76,7 @@ func main() { print("Error setting password") exit(EXIT_FAILURE) } - print("Key \(key) has been sucessfully set in the keychain") + print("Key \(key) has been successfully set in the keychain") exit(EXIT_SUCCESS) } dispatchMain() @@ -107,7 +107,7 @@ func main() { print("Error deleting password") exit(EXIT_FAILURE) } - print("Key \(key) has been sucessfully deleted from the keychain") + print("Key \(key) has been successfully deleted from the keychain") exit(EXIT_SUCCESS) } else { let errorDescription = error?.localizedDescription ?? "Unknown error" From 2a063bf999937494d9236e12435b08f9038d1d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sat, 15 Mar 2025 14:57:29 +0100 Subject: [PATCH 2/3] Include key name in TouchID dialog message --- keymaster.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keymaster.swift b/keymaster.swift index 8a526b0..de6e8e9 100644 --- a/keymaster.swift +++ b/keymaster.swift @@ -71,7 +71,7 @@ func main() { } if (action == "set") { - context.evaluatePolicy(policy, localizedReason: "set to your password") { success, error in + context.evaluatePolicy(policy, localizedReason: "set the password for \(key)") { success, error in guard setPassword(key: key, password: secret) else { print("Error setting password") exit(EXIT_FAILURE) @@ -83,7 +83,7 @@ func main() { } if (action == "get") { - context.evaluatePolicy(policy, localizedReason: "access to your password") { success, error in + context.evaluatePolicy(policy, localizedReason: "access the password for \(key)") { success, error in if success && error == nil { guard let password = getPassword(key: key) else { print("Error getting password") @@ -101,7 +101,7 @@ func main() { } if (action == "delete") { - context.evaluatePolicy(policy, localizedReason: "delete your password") { success, error in + context.evaluatePolicy(policy, localizedReason: "delete the password for \(key)") { success, error in if success && error == nil { guard deletePassword(key: key) else { print("Error deleting password") From a2736f0e829261d8f91e34ac111661daef0c7003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sat, 15 Mar 2025 15:01:08 +0100 Subject: [PATCH 3/3] Handle failure to authenticate when setting password --- keymaster.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/keymaster.swift b/keymaster.swift index de6e8e9..31b42a4 100644 --- a/keymaster.swift +++ b/keymaster.swift @@ -72,12 +72,18 @@ func main() { if (action == "set") { context.evaluatePolicy(policy, localizedReason: "set the password for \(key)") { success, error in - guard setPassword(key: key, password: secret) else { - print("Error setting password") + if success && error == nil { + guard setPassword(key: key, password: secret) else { + print("Error setting password") + exit(EXIT_FAILURE) + } + print("Key \(key) has been successfully set in the keychain") + exit(EXIT_SUCCESS) + } else { + let errorDescription = error?.localizedDescription ?? "Unknown error" + print("Error \(errorDescription)") exit(EXIT_FAILURE) } - print("Key \(key) has been successfully set in the keychain") - exit(EXIT_SUCCESS) } dispatchMain() }