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)