aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-02-04 07:37:26 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-06 06:20:23 +0100
commit8c3557a90723c20329cbdc7eff676787bfcd5872 (patch)
tree2dd57fd59c1621adcc8784cbf9dd6dbe60793b60 /WireGuard/WireGuard/Tunnel/TunnelsManager.swift
parentTunnelsManager: cache access to configuration object (diff)
downloadwireguard-apple-8c3557a90723c20329cbdc7eff676787bfcd5872.tar.xz
wireguard-apple-8c3557a90723c20329cbdc7eff676787bfcd5872.zip
Keychain: store configurations in keychain instead of providerConfig
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuard/WireGuard/Tunnel/TunnelsManager.swift')
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift20
1 files changed, 16 insertions, 4 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index 6bcf6f7..e10ba77 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -44,12 +44,21 @@ class TunnelsManager {
return
}
- let tunnelManagers = managers ?? []
- tunnelManagers.forEach { tunnelManager in
- if (tunnelManager.protocolConfiguration as? NETunnelProviderProtocol)?.migrateConfigurationIfNeeded() == true {
+ var tunnelManagers = managers ?? []
+ var refs: Set<Data> = []
+ for (index, tunnelManager) in tunnelManagers.enumerated().reversed() {
+ let proto = tunnelManager.protocolConfiguration as? NETunnelProviderProtocol
+ if proto?.migrateConfigurationIfNeeded(called: tunnelManager.localizedDescription ?? "unknown") ?? false {
tunnelManager.saveToPreferences { _ in }
}
+ if let ref = proto?.verifyConfigurationReference() {
+ refs.insert(ref)
+ } else {
+ tunnelManager.removeFromPreferences { _ in }
+ tunnelManagers.remove(at: index)
+ }
}
+ Keychain.deleteReferences(except: refs)
completionHandler(.success(TunnelsManager(tunnelProviders: tunnelManagers)))
}
#endif
@@ -105,6 +114,7 @@ class TunnelsManager {
tunnelProviderManager.saveToPreferences { [weak self] error in
guard error == nil else {
wg_log(.error, message: "Add: Saving configuration failed: \(error!)")
+ (tunnelProviderManager.protocolConfiguration as? NETunnelProviderProtocol)?.destroyConfigurationReference()
completionHandler(.failure(TunnelsManagerError.systemErrorOnAddTunnel(systemError: error!)))
return
}
@@ -153,7 +163,7 @@ class TunnelsManager {
tunnel.name = tunnelName
}
- tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration)
+ tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, previouslyFrom: tunnelProviderManager.protocolConfiguration)
tunnelProviderManager.localizedDescription = tunnelConfiguration.name
tunnelProviderManager.isEnabled = true
@@ -162,6 +172,7 @@ class TunnelsManager {
tunnelProviderManager.saveToPreferences { [weak self] error in
guard error == nil else {
+ //TODO: the passwordReference for the old one has already been removed at this point and we can't easily roll back!
wg_log(.error, message: "Modify: Saving configuration failed: \(error!)")
completionHandler(TunnelsManagerError.systemErrorOnModifyTunnel(systemError: error!))
return
@@ -202,6 +213,7 @@ class TunnelsManager {
func remove(tunnel: TunnelContainer, completionHandler: @escaping (TunnelsManagerError?) -> Void) {
let tunnelProviderManager = tunnel.tunnelProvider
+ (tunnelProviderManager.protocolConfiguration as? NETunnelProviderProtocol)?.destroyConfigurationReference()
tunnelProviderManager.removeFromPreferences { [weak self] error in
guard error == nil else {