NE: When there's an error starting the tunnel, show it to the user using displayMessage()
This commit is contained in:
parent
fffaba451a
commit
c9c58f3755
|
@ -48,6 +48,7 @@
|
||||||
6FFA5D9321943BC90001E2F7 /* DNSResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5D0C1421832391000F85AD /* DNSResolver.swift */; };
|
6FFA5D9321943BC90001E2F7 /* DNSResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5D0C1421832391000F85AD /* DNSResolver.swift */; };
|
||||||
6FFA5D952194454A0001E2F7 /* NETunnelProviderProtocol+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FFA5D942194454A0001E2F7 /* NETunnelProviderProtocol+Extension.swift */; };
|
6FFA5D952194454A0001E2F7 /* NETunnelProviderProtocol+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FFA5D942194454A0001E2F7 /* NETunnelProviderProtocol+Extension.swift */; };
|
||||||
6FFA5D96219446380001E2F7 /* NETunnelProviderProtocol+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FFA5D942194454A0001E2F7 /* NETunnelProviderProtocol+Extension.swift */; };
|
6FFA5D96219446380001E2F7 /* NETunnelProviderProtocol+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FFA5D942194454A0001E2F7 /* NETunnelProviderProtocol+Extension.swift */; };
|
||||||
|
6FFA5DA021958ECC0001E2F7 /* ErrorNotifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FFA5D9F21958ECC0001E2F7 /* ErrorNotifier.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
@ -131,6 +132,7 @@
|
||||||
6FF4AC462120B9E0002C96EB /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; };
|
6FF4AC462120B9E0002C96EB /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; };
|
||||||
6FF4AC482120B9E0002C96EB /* WireGuard.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = WireGuard.entitlements; sourceTree = "<group>"; };
|
6FF4AC482120B9E0002C96EB /* WireGuard.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = WireGuard.entitlements; sourceTree = "<group>"; };
|
||||||
6FFA5D942194454A0001E2F7 /* NETunnelProviderProtocol+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NETunnelProviderProtocol+Extension.swift"; sourceTree = "<group>"; };
|
6FFA5D942194454A0001E2F7 /* NETunnelProviderProtocol+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NETunnelProviderProtocol+Extension.swift"; sourceTree = "<group>"; };
|
||||||
|
6FFA5D9F21958ECC0001E2F7 /* ErrorNotifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorNotifier.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
@ -161,6 +163,7 @@
|
||||||
6F5D0C1E218352EF000F85AD /* Info.plist */,
|
6F5D0C1E218352EF000F85AD /* Info.plist */,
|
||||||
6F5D0C1F218352EF000F85AD /* WireGuardNetworkExtension.entitlements */,
|
6F5D0C1F218352EF000F85AD /* WireGuardNetworkExtension.entitlements */,
|
||||||
6F5D0C3421839E37000F85AD /* WireGuardNetworkExtension-Bridging-Header.h */,
|
6F5D0C3421839E37000F85AD /* WireGuardNetworkExtension-Bridging-Header.h */,
|
||||||
|
6FFA5D9F21958ECC0001E2F7 /* ErrorNotifier.swift */,
|
||||||
);
|
);
|
||||||
path = WireGuardNetworkExtension;
|
path = WireGuardNetworkExtension;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -491,6 +494,7 @@
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
6FFA5DA021958ECC0001E2F7 /* ErrorNotifier.swift in Sources */,
|
||||||
6FFA5D96219446380001E2F7 /* NETunnelProviderProtocol+Extension.swift in Sources */,
|
6FFA5D96219446380001E2F7 /* NETunnelProviderProtocol+Extension.swift in Sources */,
|
||||||
6FFA5D8E2194370D0001E2F7 /* Configuration.swift in Sources */,
|
6FFA5D8E2194370D0001E2F7 /* Configuration.swift in Sources */,
|
||||||
6FFA5D8F2194370D0001E2F7 /* IPAddressRange.swift in Sources */,
|
6FFA5D8F2194370D0001E2F7 /* IPAddressRange.swift in Sources */,
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import MobileCoreServices
|
import MobileCoreServices
|
||||||
|
import UserNotifications
|
||||||
|
|
||||||
class TunnelsListTableViewController: UIViewController {
|
class TunnelsListTableViewController: UIViewController {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
|
import NetworkExtension
|
||||||
|
|
||||||
|
class ErrorNotifier {
|
||||||
|
static func errorMessage(for error: PacketTunnelProviderError) -> (String, String)? {
|
||||||
|
switch (error) {
|
||||||
|
case .savedProtocolConfigurationIsInvalid:
|
||||||
|
return ("Activation failure", "Could not retrieve tunnel information from the saved configuration")
|
||||||
|
case .dnsResolutionFailure(_):
|
||||||
|
return ("DNS resolution failure", "One or more endpoint domains could not be resolved")
|
||||||
|
case .couldNotStartWireGuard:
|
||||||
|
return ("Activation failure", "WireGuard backend could not be started")
|
||||||
|
case .coultNotSetNetworkSettings:
|
||||||
|
return ("Activation failure", "Error applying network settings on the tunnel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static func notify(_ error: PacketTunnelProviderError, from tunnelProvider: NEPacketTunnelProvider) {
|
||||||
|
guard let (title, message) = ErrorNotifier.errorMessage(for: error) else { return }
|
||||||
|
// displayMessage() is deprecated, but there's no better alternative to show the error to the user
|
||||||
|
tunnelProvider.displayMessage("\(title): \(message)", completionHandler: { (_) in })
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,6 @@ import NetworkExtension
|
||||||
import os.log
|
import os.log
|
||||||
|
|
||||||
enum PacketTunnelProviderError: Error {
|
enum PacketTunnelProviderError: Error {
|
||||||
case invalidOptions
|
|
||||||
case savedProtocolConfigurationIsInvalid
|
case savedProtocolConfigurationIsInvalid
|
||||||
case dnsResolutionFailure(hostnames: [String])
|
case dnsResolutionFailure(hostnames: [String])
|
||||||
case couldNotStartWireGuard
|
case couldNotStartWireGuard
|
||||||
|
@ -28,6 +27,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
|
|
||||||
guard let tunnelProviderProtocol = self.protocolConfiguration as? NETunnelProviderProtocol,
|
guard let tunnelProviderProtocol = self.protocolConfiguration as? NETunnelProviderProtocol,
|
||||||
let tunnelConfiguration = tunnelProviderProtocol.tunnelConfiguration() else {
|
let tunnelConfiguration = tunnelProviderProtocol.tunnelConfiguration() else {
|
||||||
|
ErrorNotifier.notify(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid, from: self)
|
||||||
startTunnelCompletionHandler(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
|
startTunnelCompletionHandler(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
} catch DNSResolverError.dnsResolutionFailed(let hostnames) {
|
} catch DNSResolverError.dnsResolutionFailed(let hostnames) {
|
||||||
os_log("Starting tunnel failed: DNS resolution failure for %{public}d hostnames (%{public}s)", log: OSLog.default,
|
os_log("Starting tunnel failed: DNS resolution failure for %{public}d hostnames (%{public}s)", log: OSLog.default,
|
||||||
type: .error, hostnames.count, hostnames.joined(separator: ", "))
|
type: .error, hostnames.count, hostnames.joined(separator: ", "))
|
||||||
|
ErrorNotifier.notify(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames), from: self)
|
||||||
startTunnelCompletionHandler(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames))
|
startTunnelCompletionHandler(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames))
|
||||||
return
|
return
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -61,6 +62,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
let fd = packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32
|
let fd = packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32
|
||||||
if fd < 0 {
|
if fd < 0 {
|
||||||
os_log("Starting tunnel failed: Could not determine file descriptor", log: OSLog.default, type: .error)
|
os_log("Starting tunnel failed: Could not determine file descriptor", log: OSLog.default, type: .error)
|
||||||
|
ErrorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard, from: self)
|
||||||
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
|
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -70,6 +72,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
|
|
||||||
if handle < 0 {
|
if handle < 0 {
|
||||||
os_log("Starting tunnel failed: Could not start WireGuard", log: OSLog.default, type: .error)
|
os_log("Starting tunnel failed: Could not start WireGuard", log: OSLog.default, type: .error)
|
||||||
|
ErrorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard, from: self)
|
||||||
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
|
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -82,6 +85,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
setTunnelNetworkSettings(networkSettings) { (error) in
|
setTunnelNetworkSettings(networkSettings) { (error) in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
os_log("Starting tunnel failed: Error setting network settings: %s", log: OSLog.default, type: .error, error.localizedDescription)
|
os_log("Starting tunnel failed: Error setting network settings: %s", log: OSLog.default, type: .error, error.localizedDescription)
|
||||||
|
ErrorNotifier.notify(PacketTunnelProviderError.coultNotSetNetworkSettings, from: self)
|
||||||
startTunnelCompletionHandler(PacketTunnelProviderError.coultNotSetNetworkSettings)
|
startTunnelCompletionHandler(PacketTunnelProviderError.coultNotSetNetworkSettings)
|
||||||
} else {
|
} else {
|
||||||
startTunnelCompletionHandler(nil /* No errors */)
|
startTunnelCompletionHandler(nil /* No errors */)
|
||||||
|
|
Loading…
Reference in New Issue