aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-06 08:17:19 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-06 08:17:56 +0530
commita62f7fb988348a4bce7f4674826966f750e79df7 (patch)
tree9a53ec989a8f8ae9aaf51eb513244b4170157aea
parentParser: Peers in a configuation may not share the same public key (diff)
downloadwireguard-apple-a62f7fb988348a4bce7f4674826966f750e79df7.tar.xz
wireguard-apple-a62f7fb988348a4bce7f4674826966f750e79df7.zip
Tunnel view model: Peers in a configuation may not share the same public key
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/TunnelViewModel.swift7
1 files changed, 7 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift
index da292c4..16da1c2 100644
--- a/WireGuard/WireGuard/UI/TunnelViewModel.swift
+++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift
@@ -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)