]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Parsing: Always error on unrecognized keys
authorRoopesh Chander <roop@roopc.net>
Tue, 8 Jan 2019 18:06:27 +0000 (23:36 +0530)
committerRoopesh Chander <roop@roopc.net>
Mon, 14 Jan 2019 09:22:34 +0000 (14:52 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift
WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift

index 48c88b02626474b3c660239549e95b33c368e97f..625c25d408616ae7e20ba409aa02235ef7571bff 100644 (file)
@@ -34,7 +34,7 @@ extension TunnelConfiguration {
     }
 
     //swiftlint:disable:next function_body_length cyclomatic_complexity
-    convenience init(fromWgQuickConfig wgQuickConfig: String, called name: String? = nil, ignoreUnrecognizedKeys: Bool = true) throws {
+    convenience init(fromWgQuickConfig wgQuickConfig: String, called name: String? = nil) throws {
         var interfaceConfiguration: InterfaceConfiguration?
         var peerConfigurations = [PeerConfiguration]()
 
@@ -71,17 +71,15 @@ extension TunnelConfiguration {
                 } else {
                     attributes[key] = value
                 }
-                if !ignoreUnrecognizedKeys {
-                    let interfaceSectionKeys: Set<String> = ["privatekey", "listenport", "address", "dns", "mtu"]
-                    let peerSectionKeys: Set<String> = ["publickey", "presharedkey", "allowedips", "endpoint", "persistentkeepalive"]
-                    if parserState == .inInterfaceSection {
-                        guard interfaceSectionKeys.contains(key) else {
-                            throw ParseError.interfaceHasUnrecognizedKey(keyWithCase)
-                        }
-                    } else if parserState == .inPeerSection {
-                        guard peerSectionKeys.contains(key) else {
-                            throw ParseError.peerHasUnrecognizedKey(keyWithCase)
-                        }
+                let interfaceSectionKeys: Set<String> = ["privatekey", "listenport", "address", "dns", "mtu"]
+                let peerSectionKeys: Set<String> = ["publickey", "presharedkey", "allowedips", "endpoint", "persistentkeepalive"]
+                if parserState == .inInterfaceSection {
+                    guard interfaceSectionKeys.contains(key) else {
+                        throw ParseError.interfaceHasUnrecognizedKey(keyWithCase)
+                    }
+                } else if parserState == .inPeerSection {
+                    guard peerSectionKeys.contains(key) else {
+                        throw ParseError.peerHasUnrecognizedKey(keyWithCase)
                     }
                 }
             } else if lowercasedLine != "[interface]" && lowercasedLine != "[peer]" {
index 42cc6815962fb87238957925760c13e5415acb23..81437876e75a91a2ae7796d6ba917efe81eab64d 100644 (file)
@@ -128,7 +128,7 @@ class TunnelEditViewController: NSViewController {
                 return
             }
             do {
-                let tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: textView.string, called: nameRow.value, ignoreUnrecognizedKeys: false)
+                let tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: textView.string, called: nameRow.value)
                 let onDemandSetting = ActivateOnDemandSetting.defaultSetting
                 tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: onDemandSetting) { [weak self] error in
                     if let error = error {