Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Keychain: Use app group when dereferencing a password reference #201

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions TunnelKit/Sources/AppExtension/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,10 @@ public class Keychain {
- Returns: The password for the input username and reference.
- Throws: `KeychainError.notFound` if unable to find the password in the keychain.
**/
public static func password(for username: String, reference: Data, context: String? = nil) throws -> String {
public func password(for username: String, reference: Data, context: String? = nil) throws -> String {
var query = [String: Any]()
setScope(query: &query, context: context)
query[kSecClass as String] = kSecClassGenericPassword
if let context = context {
query[kSecAttrService as String] = context
}
query[kSecAttrAccount as String] = username
query[kSecMatchItemList as String] = [reference]
query[kSecReturnData as String] = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,12 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {

// optional credentials
let credentials: OpenVPN.Credentials?
if let username = protocolConfiguration.username, let passwordReference = protocolConfiguration.passwordReference,
let password = try? Keychain.password(for: username, reference: passwordReference) {

if let username = protocolConfiguration.username, let passwordReference = protocolConfiguration.passwordReference {
let keychain = Keychain(group: appGroup)
guard let password = try? keychain.password(for: username, reference: passwordReference) else {
completionHandler(ProviderConfigurationError.credentials(details: "keychain.password(for:, reference:)"))
return
}
credentials = OpenVPN.Credentials(username, password)
} else {
credentials = nil
Expand Down