aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-12-02 18:16:41 +0100
committerAndrej Mihajlov <and@mullvad.net>2020-12-04 09:39:09 +0100
commitbcc34e0bb63caff1e9f3de04a60fd6ad33388f4b (patch)
tree6f03a8ba984ea809a9bc01e85ef8fab762eac16a
parentKeychain: Remove unnecessary cast to String in Keychain queries (diff)
downloadwireguard-apple-bcc34e0bb63caff1e9f3de04a60fd6ad33388f4b.tar.xz
wireguard-apple-bcc34e0bb63caff1e9f3de04a60fd6ad33388f4b.zip
Keychain: Avoid roundtrip via items when accessing item label (stored in kSecAttrLabel)
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
-rw-r--r--Sources/Shared/Keychain.swift7
1 files changed, 3 insertions, 4 deletions
diff --git a/Sources/Shared/Keychain.swift b/Sources/Shared/Keychain.swift
index 82acb86..52817c3 100644
--- a/Sources/Shared/Keychain.swift
+++ b/Sources/Shared/Keychain.swift
@@ -28,8 +28,9 @@ class Keychain {
if bundleIdentifier.hasSuffix(".network-extension") {
bundleIdentifier.removeLast(".network-extension".count)
}
+ let itemLabel = "WireGuard Tunnel: \(name)"
var items: [CFString: Any] = [kSecClass: kSecClassGenericPassword,
- kSecAttrLabel: "WireGuard Tunnel: " + name,
+ kSecAttrLabel: itemLabel,
kSecAttrAccount: name + ": " + UUID().uuidString,
kSecAttrDescription: "wg-quick(8) config",
kSecAttrService: bundleIdentifier,
@@ -60,9 +61,7 @@ class Keychain {
return nil
}
var access: SecAccess?
- ret = SecAccessCreate((items[kSecAttrLabel] as? String)! as CFString,
- [extensionApp!, mainApp!] as CFArray,
- &access)
+ ret = SecAccessCreate(itemLabel as CFString, [extensionApp!, mainApp!] as CFArray, &access)
if ret != errSecSuccess || access == nil {
wg_log(.error, message: "Unable to create keychain ACL object: \(ret)")
return nil