]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Localize remaining strings in network extension
authorJason A. Donenfeld <Jason@zx2c4.com>
Sat, 22 Dec 2018 02:41:54 +0000 (03:41 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 22 Dec 2018 02:42:01 +0000 (03:42 +0100)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
WireGuard/Shared/Model/NETunnelProviderProtocol+Extension.swift
WireGuard/WireGuard/Base.lproj/Localizable.strings
WireGuard/WireGuard/Tunnel/TunnelsManager.swift
WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift

index 98634fd2b3fb4684c667bca94598dd6434e2e165..d2179e0adc9392eb857a52bc13270bee0c51cf99 100644 (file)
@@ -3,6 +3,14 @@
 
 import NetworkExtension
 
+enum PacketTunnelProviderError: String, Error {
+    case savedProtocolConfigurationIsInvalid
+    case dnsResolutionFailure
+    case couldNotStartBackend
+    case couldNotDetermineFileDescriptor
+    case couldNotSetNetworkSettings
+}
+
 extension NETunnelProviderProtocol {
 
     enum Keys: String {
index ac4a7300fb3eaa48b95b10c6e8f8af02cef9553a..7815ddbde10b7cf1b65b8109e1c6cba8541c748d 100644 (file)
 
 "alertTunnelActivationFailureTitle" = "Activation failure";
 "alertTunnelActivationFailureMessage" = "The tunnel could not be activated. Please ensure that you are connected to the Internet.";
+"alertTunnelActivationSavedConfigFailureMessage" = "Unable to retrieve tunnel information from the saved configuration.";
+"alertTunnelActivationBackendFailureMessage" = "Unable to turn on Go backend library.";
+"alertTunnelActivationFileDescriptorFailureMessage" = "Unable to determine TUN device file descriptor.";
+"alertTunnelActivationSetNetworkSettingsMessage" = "Unable to apply network settings to tunnel object.";
+
 "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.";
 
+"alertTunnelDNSFailureTitle" = "DNS resolution failure";
+"alertTunnelDNSFailureMessage" = "One or more endpoint domains could not be resolved.";
+
 "alertTunnelNameEmptyTitle" = "No name provided";
 "alertTunnelNameEmptyMessage" = "Cannot create tunnel with an empty name";
 
 "alertTunnelAlreadyExistsWithThatNameTitle" = "Name already exists";
 "alertTunnelAlreadyExistsWithThatNameMessage" = "A tunnel with that name already exists";
 
-"alertTunnelActivationErrorTunnelIsNotInactiveTitle" = "Activation failure";
+"alertTunnelActivationErrorTunnelIsNotInactiveTitle" = "Activation in progress";
 "alertTunnelActivationErrorTunnelIsNotInactiveMessage" = "The tunnel is already active or in the process of being activated";
 
 // Tunnel management error alerts on system error
index 4913fd2b906b217b0fdd1f6b63627bc2c0a3039d..c25d4b6172865482675d061db9a4b37baf966bd1 100644 (file)
@@ -298,13 +298,22 @@ class TunnelsManager {
         guard let lastErrorData = try? Data(contentsOf: lastErrorFileURL) else { return nil }
         guard let lastErrorText = String(data: lastErrorData, encoding: .utf8) else { return nil }
         let lastErrorStrings = lastErrorText.splitToArray(separator: "\n")
-        guard lastErrorStrings.count == 3 else { return nil }
-        let attemptIdInDisk = lastErrorStrings[0]
-        if let attemptIdForTunnel = tunnel.activationAttemptId, attemptIdInDisk == attemptIdForTunnel {
-            return (title: lastErrorStrings[1], message: lastErrorStrings[2])
+        guard lastErrorStrings.count == 2 && tunnel.activationAttemptId == lastErrorStrings[0] else { return nil }
+
+        switch PacketTunnelProviderError(rawValue: lastErrorStrings[1]) {
+        case .some(.savedProtocolConfigurationIsInvalid):
+            return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationSavedConfigFailureMessage"))
+        case .some(.dnsResolutionFailure):
+            return (tr("alertTunnelDNSFailureTitle"), tr("alertTunnelDNSFailureMessage"))
+        case .some(.couldNotStartBackend):
+            return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationBackendFailureMessage"))
+        case .some(.couldNotDetermineFileDescriptor):
+            return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFileDescriptorFailureMessage"))
+        case .some(.couldNotSetNetworkSettings):
+            return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationSetNetworkSettingsMessage"))
+        default:
+            return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFailureMessage"))
         }
-
-        return nil
     }
 
     deinit {
index ac1a6368072475c7c8268ba1e1aa4f9f2df66ea1..43aa0d7cb85bfe23a77e1cfa3257c2bf214d2640 100644 (file)
@@ -4,32 +4,16 @@
 import NetworkExtension
 
 class ErrorNotifier {
-
     let activationAttemptId: String?
-    weak var tunnelProvider: NEPacketTunnelProvider?
 
-    init(activationAttemptId: String?, tunnelProvider: NEPacketTunnelProvider) {
+    init(activationAttemptId: String?) {
         self.activationAttemptId = activationAttemptId
-        self.tunnelProvider = tunnelProvider
         ErrorNotifier.removeLastErrorFile()
     }
 
-    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.")
-        }
-    }
-
     func notify(_ error: PacketTunnelProviderError) {
-        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)
+        guard let activationAttemptId = activationAttemptId, let lastErrorFilePath = FileManager.networkExtensionLastErrorFileURL?.path else { return }
+        let errorMessageData = "\(activationAttemptId)\n\(error)".data(using: .utf8)
         FileManager.default.createFile(atPath: lastErrorFilePath, contents: errorMessageData, attributes: nil)
     }
 
index bcec9b26eb2b2bc0ce5e77566110b616c410b707..bc4b542a75ed2c06cbb191b4151890829aca59a4 100644 (file)
@@ -6,13 +6,6 @@ import Network
 import NetworkExtension
 import os.log
 
-enum PacketTunnelProviderError: Error {
-    case savedProtocolConfigurationIsInvalid
-    case dnsResolutionFailure
-    case couldNotStartWireGuard
-    case coultNotSetNetworkSettings
-}
-
 class PacketTunnelProvider: NEPacketTunnelProvider {
 
     private var wgHandle: Int32?
@@ -26,7 +19,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
 
     override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
         let activationAttemptId = options?["activationAttemptId"] as? String
-        let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId, tunnelProvider: self)
+        let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId)
 
         guard let tunnelProviderProtocol = protocolConfiguration as? NETunnelProviderProtocol,
             let tunnelConfiguration = tunnelProviderProtocol.asTunnelConfiguration() else {
@@ -52,8 +45,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
         let fileDescriptor = packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32 //swiftlint:disable:this force_cast
         if fileDescriptor < 0 {
             wg_log(.error, staticMessage: "Starting tunnel failed: Could not determine file descriptor")
-            errorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard)
-            startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
+            errorNotifier.notify(PacketTunnelProviderError.couldNotDetermineFileDescriptor)
+            startTunnelCompletionHandler(PacketTunnelProviderError.couldNotDetermineFileDescriptor)
             return
         }
 
@@ -67,8 +60,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
         let handle = wireguardSettings.withGoString { return wgTurnOn($0, fileDescriptor) }
         if handle < 0 {
             wg_log(.error, message: "Starting tunnel failed with wgTurnOn returning \(handle)")
-            errorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard)
-            startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
+            errorNotifier.notify(PacketTunnelProviderError.couldNotStartBackend)
+            startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartBackend)
             return
         }
         wgHandle = handle
@@ -77,8 +70,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
         setTunnelNetworkSettings(networkSettings) { error in
             if let error = error {
                 wg_log(.error, message: "Starting tunnel failed with setTunnelNetworkSettings returning \(error.localizedDescription)")
-                errorNotifier.notify(PacketTunnelProviderError.coultNotSetNetworkSettings)
-                startTunnelCompletionHandler(PacketTunnelProviderError.coultNotSetNetworkSettings)
+                errorNotifier.notify(PacketTunnelProviderError.couldNotSetNetworkSettings)
+                startTunnelCompletionHandler(PacketTunnelProviderError.couldNotSetNetworkSettings)
             } else {
                 startTunnelCompletionHandler(nil)
             }