aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-02-08 00:44:14 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-08 03:23:15 +0100
commit05547861b65100279027a64f58793caea1143a30 (patch)
treec69303b55e68e93efc71d2b199119019f1199ff6 /WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift
parentTunnelsManager: Ignore status changes on tunnel providers we don't have (diff)
downloadwireguard-apple-05547861b65100279027a64f58793caea1143a30.tar.xz
wireguard-apple-05547861b65100279027a64f58793caea1143a30.zip
Key: Constant time encoding
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift23
1 files changed, 11 insertions, 12 deletions
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift
index 02588c33..a4ff7dd2 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift
@@ -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()
- }
-}