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

This commit is contained in:
Roopesh Chander 2018-11-06 08:17:03 +05:30
parent e6a6decd79
commit e05a6c31b9
1 changed files with 7 additions and 0 deletions

View File

@ -16,6 +16,7 @@ class WgQuickConfigFileParser {
case noInterface case noInterface
case invalidInterface case invalidInterface
case multipleInterfaces case multipleInterfaces
case multiplePeersWithSamePublicKey
case invalidPeer 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 { if let interfaceConfiguration = interfaceConfiguration {
let tunnelConfiguration = TunnelConfiguration(interface: interfaceConfiguration) let tunnelConfiguration = TunnelConfiguration(interface: interfaceConfiguration)
tunnelConfiguration.peers = peerConfigurations tunnelConfiguration.peers = peerConfigurations