Parser: Peers in a configuation may not share the same public key

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-11-06 08:17:03 +05:30
parent 24575a5cf9
commit 636aa98b79
1 changed files with 7 additions and 0 deletions

View File

@ -16,6 +16,7 @@ class WgQuickConfigFileParser {
case noInterface
case invalidInterface
case multipleInterfaces
case multiplePeersWithSamePublicKey
case invalidPeer
}
@ -149,6 +150,12 @@ class WgQuickConfigFileParser {
}
}
let peerPublicKeysArray = peerConfigurations.map { $0.publicKey }
let peerPublicKeysSet = Set<Data>(peerPublicKeysArray)
if (peerPublicKeysArray.count != peerPublicKeysSet.count) {
throw ParseError.multiplePeersWithSamePublicKey
}
if let interfaceConfiguration = interfaceConfiguration {
let tunnelConfiguration = TunnelConfiguration(interface: interfaceConfiguration)
tunnelConfiguration.peers = peerConfigurations