]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Tunnel view model: Peers in a configuation may not share the same public key
authorRoopesh Chander <roop@roopc.net>
Tue, 6 Nov 2018 02:47:19 +0000 (08:17 +0530)
committerRoopesh Chander <roop@roopc.net>
Tue, 6 Nov 2018 02:47:56 +0000 (08:17 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/UI/TunnelViewModel.swift

index da292c44452829bf827c0f0e8f990026aae9cd50..16da1c221167513d9724c0a4b905ba6c1d991bb3 100644 (file)
@@ -434,6 +434,13 @@ class TunnelViewModel {
                     peerConfigurations.append(peerConfiguration)
                 }
             }
+
+            let peerPublicKeysArray = peerConfigurations.map { $0.publicKey }
+            let peerPublicKeysSet = Set<Data>(peerPublicKeysArray)
+            if (peerPublicKeysArray.count != peerPublicKeysSet.count) {
+                return .error("Two or more peers cannot have the same public key")
+            }
+
             let tunnelConfiguration = TunnelConfiguration(interface: interfaceConfiguration)
             tunnelConfiguration.peers = peerConfigurations
             return .saved(tunnelConfiguration)