Key: Constant time encoding
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -17,7 +17,9 @@ class PacketTunnelSettingsGenerator {
|
||||
func endpointUapiConfiguration() -> String {
|
||||
var wgSettings = ""
|
||||
for (index, peer) in tunnelConfiguration.peers.enumerated() {
|
||||
wgSettings.append("public_key=\(peer.publicKey.hexEncodedString())\n")
|
||||
if let publicKey = peer.publicKey.hexKey() {
|
||||
wgSettings.append("public_key=\(publicKey)\n")
|
||||
}
|
||||
if let endpoint = resolvedEndpoints[index]?.withReresolvedIP() {
|
||||
if case .name(_, _) = endpoint.host { assert(false, "Endpoint is not resolved") }
|
||||
wgSettings.append("endpoint=\(endpoint.stringRepresentation)\n")
|
||||
@@ -28,8 +30,9 @@ class PacketTunnelSettingsGenerator {
|
||||
|
||||
func uapiConfiguration() -> String {
|
||||
var wgSettings = ""
|
||||
let privateKey = tunnelConfiguration.interface.privateKey.hexEncodedString()
|
||||
wgSettings.append("private_key=\(privateKey)\n")
|
||||
if let privateKey = tunnelConfiguration.interface.privateKey.hexKey() {
|
||||
wgSettings.append("private_key=\(privateKey)\n")
|
||||
}
|
||||
if let listenPort = tunnelConfiguration.interface.listenPort {
|
||||
wgSettings.append("listen_port=\(listenPort)\n")
|
||||
}
|
||||
@@ -38,9 +41,11 @@ class PacketTunnelSettingsGenerator {
|
||||
}
|
||||
assert(tunnelConfiguration.peers.count == resolvedEndpoints.count)
|
||||
for (index, peer) in tunnelConfiguration.peers.enumerated() {
|
||||
wgSettings.append("public_key=\(peer.publicKey.hexEncodedString())\n")
|
||||
if let preSharedKey = peer.preSharedKey {
|
||||
wgSettings.append("preshared_key=\(preSharedKey.hexEncodedString())\n")
|
||||
if let publicKey = peer.publicKey.hexKey() {
|
||||
wgSettings.append("public_key=\(publicKey)\n")
|
||||
}
|
||||
if let preSharedKey = peer.preSharedKey?.hexKey() {
|
||||
wgSettings.append("preshared_key=\(preSharedKey)\n")
|
||||
}
|
||||
if let endpoint = resolvedEndpoints[index]?.withReresolvedIP() {
|
||||
if case .name(_, _) = endpoint.host { assert(false, "Endpoint is not resolved") }
|
||||
@@ -149,9 +154,3 @@ class PacketTunnelSettingsGenerator {
|
||||
return (ipv4IncludedRoutes, ipv6IncludedRoutes)
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
func hexEncodedString() -> String {
|
||||
return self.map { String(format: "%02x", $0) }.joined()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user