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

Commit

Permalink
Pick tunnel password reference from existing item
Browse files Browse the repository at this point in the history
Assume that credentials already exist elsewhere for reuse as
password reference. Avoids a redundant keychain entry.
  • Loading branch information
keeshux committed Jan 27, 2021
1 parent 4b3f3de commit 4490f0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Handle `--data-ciphers` and `data-ciphers-fallback` from OpenVPN 2.5
- Support DNS over HTTPS (DoH) and TLS (DoT).

### Changed

- Pick tunnel password reference from an existing keychain item context.

### Fixed

- Do not override network DNS settings when not provided by VPN. [#197](https://github.com/passepartoutvpn/tunnelkit/issues/197)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,25 @@ extension OpenVPNTunnelProvider {
- Parameter bundleIdentifier: The provider bundle identifier required to locate the tunnel extension.
- Parameter appGroup: The name of the app group in which the tunnel extension lives in.
- Parameter credentials: The optional credentials to authenticate with.
- Parameter context: The keychain context where to look for the password reference.
- Parameter username: The username to authenticate with.
- Returns: The generated `NETunnelProviderProtocol` object.
- Throws: `ProviderError.credentials` if unable to store `credentials.password` to the `appGroup` keychain.
*/
public func generatedTunnelProtocol(withBundleIdentifier bundleIdentifier: String, appGroup: String, credentials: OpenVPN.Credentials? = nil) throws -> NETunnelProviderProtocol {
let protocolConfiguration = NETunnelProviderProtocol()
public func generatedTunnelProtocol(
withBundleIdentifier bundleIdentifier: String,
appGroup: String,
context: String,
username: String?) throws -> NETunnelProviderProtocol {

let protocolConfiguration = NETunnelProviderProtocol()
let keychain = Keychain(group: appGroup)

protocolConfiguration.providerBundleIdentifier = bundleIdentifier
protocolConfiguration.serverAddress = sessionConfiguration.hostname ?? resolvedAddresses?.first
if let username = credentials?.username, let password = credentials?.password {
let keychain = Keychain(group: appGroup)
do {
try keychain.set(password: password, for: username, context: bundleIdentifier)
} catch _ {
throw ProviderConfigurationError.credentials(details: "keychain.set()")
}
if let username = username {
protocolConfiguration.username = username
protocolConfiguration.passwordReference = try? keychain.passwordReference(for: username, context: bundleIdentifier)
protocolConfiguration.passwordReference = try? keychain.passwordReference(for: username, context: context)
}
protocolConfiguration.providerConfiguration = generatedProviderConfiguration(appGroup: appGroup)

Expand Down

0 comments on commit 4490f0c

Please sign in to comment.