From d977c3317ca0638d40112b2b301f1da9e5d3fa8d Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Tue, 2 Nov 2021 22:22:04 +0100 Subject: [PATCH] Fix macOS demo not connecting Missing keychain sharing capabilities. --- Demo/Demo/iOS/ViewController.swift | 38 ++++++++++++------------- Demo/Demo/macOS/Demo.entitlements | 4 +++ Demo/Demo/macOS/DemoTunnel.entitlements | 4 +++ Demo/Demo/macOS/ViewController.swift | 38 ++++++++++++------------- 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/Demo/Demo/iOS/ViewController.swift b/Demo/Demo/iOS/ViewController.swift index d51ae75..88cc676 100644 --- a/Demo/Demo/iOS/ViewController.swift +++ b/Demo/Demo/iOS/ViewController.swift @@ -143,24 +143,24 @@ class ViewController: UIViewController, URLSessionDataDelegate { } private func testFetchRef() { -// let keychain = Keychain(group: ViewController.APP_GROUP) -// let username = "foo" -// let password = "bar" -// -// guard let _ = try? keychain.set(password: password, for: username) else { -// print("Couldn't set password") -// return -// } -// guard let passwordReference = try? keychain.passwordReference(for: username) else { -// print("Couldn't get password reference") -// return -// } -// guard let fetchedPassword = try? Keychain.password(for: username, reference: passwordReference) else { -// print("Couldn't fetch password") -// return -// } -// -// print("\(username) -> \(password)") -// print("\(username) -> \(fetchedPassword)") + let keychain = Keychain(group: appGroup) + let username = "foo" + let password = "bar" + + guard let _ = try? keychain.set(password: password, for: username, context: tunnelIdentifier) else { + print("Couldn't set password") + return + } + guard let passwordReference = try? keychain.passwordReference(for: username, context: tunnelIdentifier) else { + print("Couldn't get password reference") + return + } + guard let fetchedPassword = try? keychain.password(for: username, reference: passwordReference, context: tunnelIdentifier) else { + print("Couldn't fetch password") + return + } + + print("\(username) -> \(password)") + print("\(username) -> \(fetchedPassword)") } } diff --git a/Demo/Demo/macOS/Demo.entitlements b/Demo/Demo/macOS/Demo.entitlements index 4c9f5da..7336b16 100644 --- a/Demo/Demo/macOS/Demo.entitlements +++ b/Demo/Demo/macOS/Demo.entitlements @@ -14,5 +14,9 @@ com.apple.security.network.client + keychain-access-groups + + $(AppIdentifierPrefix)group.com.algoritmico.TunnelKit.Demo + diff --git a/Demo/Demo/macOS/DemoTunnel.entitlements b/Demo/Demo/macOS/DemoTunnel.entitlements index 4c9f5da..7336b16 100644 --- a/Demo/Demo/macOS/DemoTunnel.entitlements +++ b/Demo/Demo/macOS/DemoTunnel.entitlements @@ -14,5 +14,9 @@ com.apple.security.network.client + keychain-access-groups + + $(AppIdentifierPrefix)group.com.algoritmico.TunnelKit.Demo + diff --git a/Demo/Demo/macOS/ViewController.swift b/Demo/Demo/macOS/ViewController.swift index 5ef1c91..a77aed8 100644 --- a/Demo/Demo/macOS/ViewController.swift +++ b/Demo/Demo/macOS/ViewController.swift @@ -128,25 +128,25 @@ class ViewController: NSViewController { } private func testFetchRef() { -// let keychain = Keychain(group: ViewController.APP_GROUP) -// let username = "foo" -// let password = "bar" -// -// guard let _ = try? keychain.set(password: password, for: username) else { -// print("Couldn't set password") -// return -// } -// guard let passwordReference = try? keychain.passwordReference(for: username) else { -// print("Couldn't get password reference") -// return -// } -// guard let fetchedPassword = try? Keychain.password(for: username, reference: passwordReference) else { -// print("Couldn't fetch password") -// return -// } -// -// print("\(username) -> \(password)") -// print("\(username) -> \(fetchedPassword)") + let keychain = Keychain(group: appGroup) + let username = "foo" + let password = "bar" + + guard let _ = try? keychain.set(password: password, for: username, context: tunnelIdentifier) else { + print("Couldn't set password") + return + } + guard let passwordReference = try? keychain.passwordReference(for: username, context: tunnelIdentifier) else { + print("Couldn't get password reference") + return + } + guard let fetchedPassword = try? keychain.password(for: username, reference: passwordReference, context: tunnelIdentifier) else { + print("Couldn't fetch password") + return + } + + print("\(username) -> \(password)") + print("\(username) -> \(fetchedPassword)") } }