aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--WireGuard/Shared/NETunnelProviderProtocol+Extension.swift14
-rw-r--r--WireGuard/WireGuard/Base.lproj/Localizable.strings1
-rw-r--r--WireGuard/WireGuard/Tunnel/MockTunnels.swift2
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelErrors.swift12
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift8
-rw-r--r--WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift19
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift17
7 files changed, 19 insertions, 54 deletions
diff --git a/WireGuard/Shared/NETunnelProviderProtocol+Extension.swift b/WireGuard/Shared/NETunnelProviderProtocol+Extension.swift
index e5cfac88..3a9bc38b 100644
--- a/WireGuard/Shared/NETunnelProviderProtocol+Extension.swift
+++ b/WireGuard/Shared/NETunnelProviderProtocol+Extension.swift
@@ -10,7 +10,6 @@ extension NETunnelProviderProtocol {
enum Keys: String {
case tunnelConfiguration = "TunnelConfiguration"
case tunnelConfigurationVersion = "TunnelConfigurationVersion"
- case isActivateOnDemandEnabled = "IsActivateOnDemandEnabled"
}
var tunnelConfiguration: TunnelConfiguration? {
@@ -27,11 +26,7 @@ extension NETunnelProviderProtocol {
return try? JSONDecoder().decode(TunnelConfiguration.self, from: tunnelConfigurationData!)
}
- var isActivateOnDemandEnabled: Bool {
- return providerConfiguration?[Keys.isActivateOnDemandEnabled.rawValue] as? Bool ?? false
- }
-
- convenience init?(tunnelConfiguration: TunnelConfiguration, isActivateOnDemandEnabled: Bool) {
+ convenience init?(tunnelConfiguration: TunnelConfiguration) {
assert(!tunnelConfiguration.interface.name.isEmpty)
guard let tunnelConfigData = try? JSONEncoder().encode(tunnelConfiguration) else { return nil }
@@ -43,8 +38,7 @@ extension NETunnelProviderProtocol {
providerBundleIdentifier = "\(appId).network-extension"
providerConfiguration = [
Keys.tunnelConfiguration.rawValue: tunnelConfigDictionary,
- Keys.tunnelConfigurationVersion.rawValue: tunnelConfigurationVersion,
- Keys.isActivateOnDemandEnabled.rawValue: isActivateOnDemandEnabled
+ Keys.tunnelConfigurationVersion.rawValue: tunnelConfigurationVersion
]
let endpoints = tunnelConfiguration.peers.compactMap { $0.endpoint }
@@ -85,14 +79,12 @@ extension NETunnelProviderProtocol {
private func migrateFromConfigurationV1() {
guard let serializedTunnelConfiguration = providerConfiguration?["tunnelConfiguration"] as? Data else { return }
guard let configuration = try? JSONDecoder().decode(LegacyTunnelConfiguration.self, from: serializedTunnelConfiguration) else { return }
- guard let isActivateOnDemandEnabled = providerConfiguration?["isActivateOnDemandEnabled"] as? Bool else { return }
guard let tunnelConfigData = try? JSONEncoder().encode(configuration.migrated) else { return }
guard let tunnelConfigDictionary = try? JSONSerialization.jsonObject(with: tunnelConfigData, options: .allowFragments) else { return }
providerConfiguration = [
Keys.tunnelConfiguration.rawValue: tunnelConfigDictionary,
- Keys.tunnelConfigurationVersion.rawValue: tunnelConfigurationVersion,
- Keys.isActivateOnDemandEnabled.rawValue: isActivateOnDemandEnabled
+ Keys.tunnelConfigurationVersion.rawValue: tunnelConfigurationVersion
]
}
diff --git a/WireGuard/WireGuard/Base.lproj/Localizable.strings b/WireGuard/WireGuard/Base.lproj/Localizable.strings
index 524cfdc3..58eb9d48 100644
--- a/WireGuard/WireGuard/Base.lproj/Localizable.strings
+++ b/WireGuard/WireGuard/Base.lproj/Localizable.strings
@@ -177,6 +177,7 @@
"alertTunnelActivationFailureTitle" = "Activation failure";
"alertTunnelActivationFailureMessage" = "The tunnel could not be activated. Please ensure that you are connected to the Internet.";
+"alertTunnelActivationFailureOnDemandAddendum" = " This tunnel has Activate On Demand enabled, so this tunnel might be re-activated automatically by the OS. You may turn off Activate On Demand in this app by editing the tunnel configuration.";
"alertTunnelNameEmptyTitle" = "No name provided";
"alertTunnelNameEmptyMessage" = "Cannot create tunnel with an empty name";
diff --git a/WireGuard/WireGuard/Tunnel/MockTunnels.swift b/WireGuard/WireGuard/Tunnel/MockTunnels.swift
index 7be6f5ca..764d8607 100644
--- a/WireGuard/WireGuard/Tunnel/MockTunnels.swift
+++ b/WireGuard/WireGuard/Tunnel/MockTunnels.swift
@@ -37,7 +37,7 @@ class MockTunnels {
let tunnelConfiguration = TunnelConfiguration(interface: interface, peers: [peer])
let tunnelProviderManager = NETunnelProviderManager()
- tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, isActivateOnDemandEnabled: false)
+ tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration)
tunnelProviderManager.localizedDescription = tunnelName
tunnelProviderManager.isEnabled = true
diff --git a/WireGuard/WireGuard/Tunnel/TunnelErrors.swift b/WireGuard/WireGuard/Tunnel/TunnelErrors.swift
index c3d15b2b..9b2b5740 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelErrors.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelErrors.swift
@@ -51,15 +51,15 @@ enum TunnelsManagerActivationAttemptError: WireGuardAppError {
}
enum TunnelsManagerActivationError: WireGuardAppError {
- case activationFailed
- case activationFailedWithExtensionError(title: String, message: String)
+ case activationFailed(wasOnDemandEnabled: Bool)
+ case activationFailedWithExtensionError(title: String, message: String, wasOnDemandEnabled: Bool)
var alertText: AlertText {
switch self {
- case .activationFailed:
- return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFailureMessage"))
- case .activationFailedWithExtensionError(let title, let message):
- return (title, message)
+ case .activationFailed(let wasOnDemandEnabled):
+ return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFailureMessage") + (wasOnDemandEnabled ? tr("alertTunnelActivationFailureOnDemandAddendum") : ""))
+ case .activationFailedWithExtensionError(let title, let message, let wasOnDemandEnabled):
+ return (title, message + (wasOnDemandEnabled ? tr("alertTunnelActivationFailureOnDemandAddendum") : ""))
}
}
}
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index b56cb374..51f0d37c 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -66,7 +66,7 @@ class TunnelsManager {
}
let tunnelProviderManager = NETunnelProviderManager()
- tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, isActivateOnDemandEnabled: activateOnDemandSetting.isActivateOnDemandEnabled)
+ tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration)
tunnelProviderManager.localizedDescription = tunnelName
tunnelProviderManager.isEnabled = true
@@ -125,7 +125,7 @@ class TunnelsManager {
let shouldRestartIfActive = !((tunnelProviderManager.protocolConfiguration as? NETunnelProviderProtocol)?.hasTunnelConfiguration(tunnelConfiguration: tunnelConfiguration) ?? false)
- tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, isActivateOnDemandEnabled: activateOnDemandSetting.isActivateOnDemandEnabled)
+ tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration)
tunnelProviderManager.localizedDescription = tunnelName
tunnelProviderManager.isEnabled = true
@@ -277,9 +277,9 @@ class TunnelsManager {
} else if session.status == .disconnected {
tunnel.isAttemptingActivation = false
if let (title, message) = self.lastErrorTextFromNetworkExtension(for: tunnel) {
- self.activationDelegate?.tunnelActivationFailed(tunnel: tunnel, error: .activationFailedWithExtensionError(title: title, message: message))
+ self.activationDelegate?.tunnelActivationFailed(tunnel: tunnel, error: .activationFailedWithExtensionError(title: title, message: message, wasOnDemandEnabled: tunnelProvider.isOnDemandEnabled))
} else {
- self.activationDelegate?.tunnelActivationFailed(tunnel: tunnel, error: .activationFailed)
+ self.activationDelegate?.tunnelActivationFailed(tunnel: tunnel, error: .activationFailed(wasOnDemandEnabled: tunnelProvider.isOnDemandEnabled))
}
}
}
diff --git a/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift b/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
index 1b74d5d4..a9bcc144 100644
--- a/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
+++ b/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
@@ -9,7 +9,6 @@ class ErrorNotifier {
weak var tunnelProvider: NEPacketTunnelProvider?
var tunnelName: String?
- var isActivateOnDemandEnabled = false
init(activationAttemptId: String?, tunnelProvider: NEPacketTunnelProvider) {
self.activationAttemptId = activationAttemptId
@@ -31,21 +30,9 @@ class ErrorNotifier {
}
func notify(_ error: PacketTunnelProviderError) {
- guard let (title, message) = errorMessage(for: error) else { return }
- if let activationAttemptId = activationAttemptId, let lastErrorFilePath = FileManager.networkExtensionLastErrorFileURL?.path {
- // The tunnel was started from the app
- let onDemandMessage = isActivateOnDemandEnabled ? " This tunnel has Activate On Demand enabled, so this tunnel might be activated automatically. You may turn off Activate On Demand in the WireGuard app by navigating to: '\(tunnelName ?? "tunnel")' > Edit." : ""
- let errorMessageData = "\(activationAttemptId)\n\(title)\n\(message)\(onDemandMessage)".data(using: .utf8)
- FileManager.default.createFile(atPath: lastErrorFilePath, contents: errorMessageData, attributes: nil)
- } else {
- // The tunnel was probably started from iOS Settings app or activated on-demand
- if let tunnelProvider = self.tunnelProvider {
- // displayMessage() is deprecated, but there's no better alternative if invoked from iOS Settings
- if !isActivateOnDemandEnabled { // If using activate-on-demand, don't use displayMessage
- tunnelProvider.displayMessage("\(title): \(message)") { _ in }
- }
- }
- }
+ guard let (title, message) = errorMessage(for: error), let activationAttemptId = activationAttemptId, let lastErrorFilePath = FileManager.networkExtensionLastErrorFileURL?.path else { return }
+ let errorMessageData = "\(activationAttemptId)\n\(title)\n\(message)".data(using: .utf8)
+ FileManager.default.createFile(atPath: lastErrorFilePath, contents: errorMessageData, attributes: nil)
}
static func removeLastErrorFile() {
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
index f32a0044..27a42c5d 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
@@ -24,7 +24,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
networkMonitor?.cancel()
}
- //swiftlint:disable:next function_body_length
override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
let activationAttemptId = options?["activationAttemptId"] as? String
let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId, tunnelProvider: self)
@@ -39,22 +38,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
configureLogger()
let tunnelName = tunnelConfiguration.interface.name
- wg_log(.info, message: "Starting tunnel '\(tunnelName)'")
+ wg_log(.info, message: "Starting tunnel '\(tunnelName)' from the " + (activationAttemptId == nil ? "OS directly, rather than the app" : "app"))
- if activationAttemptId != nil {
- wg_log(.info, staticMessage: "Tunnel activated from the app")
- } else {
- wg_log(.info, staticMessage: "Tunnel not activated from the app")
- }
-
- let isActivateOnDemandEnabled = tunnelProviderProtocol.isActivateOnDemandEnabled
- if isActivateOnDemandEnabled {
- wg_log(.info, staticMessage: "Tunnel has Activate On Demand enabled")
- } else {
- wg_log(.info, staticMessage: "Tunnel has Activate On Demand disabled")
- }
-
- errorNotifier.isActivateOnDemandEnabled = isActivateOnDemandEnabled
errorNotifier.tunnelName = tunnelName
let endpoints = tunnelConfiguration.peers.map { $0.endpoint }