From e9044966bf9484ad18865e946b741e8fbf037ec3 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Tue, 6 Nov 2018 08:17:19 +0530 Subject: [PATCH] Tunnel view model: Peers in a configuation may not share the same public key --- WireGuard/WireGuard/UI/TunnelViewModel.swift | 7 +++++++ 1 file changed, 7 insertions(+) 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(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)