aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/Tunnel/MockTunnels.swift
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard/WireGuard/Tunnel/MockTunnels.swift')
-rw-r--r--WireGuard/WireGuard/Tunnel/MockTunnels.swift43
1 files changed, 43 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/Tunnel/MockTunnels.swift b/WireGuard/WireGuard/Tunnel/MockTunnels.swift
new file mode 100644
index 0000000..116a1d8
--- /dev/null
+++ b/WireGuard/WireGuard/Tunnel/MockTunnels.swift
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018 WireGuard LLC. All Rights Reserved.
+
+import NetworkExtension
+
+// Creates mock tunnels for the iOS Simulator.
+
+#if targetEnvironment(simulator)
+class MockTunnels {
+ static let tunnelNames = [
+ "demo",
+ "edgesecurity",
+ "home",
+ "office"
+ ]
+ static let address = "192.168.4.184/24"
+ static let dnsServers = ["8.8.8.8", "4.4.4.4"]
+ static let endpoint = "demo.wireguard.com:12912"
+ static let allowedIPs = "0.0.0.0/0"
+
+ static func createMockTunnels() -> [NETunnelProviderManager] {
+ return tunnelNames.map { tunnelName -> NETunnelProviderManager in
+
+ var interface = InterfaceConfiguration(name: tunnelName, privateKey: Curve25519.generatePrivateKey())
+ interface.addresses = [IPAddressRange(from: address)!]
+ interface.dns = dnsServers.map { DNSServer(from: $0)! }
+
+ var peer = PeerConfiguration(publicKey: Curve25519.generatePublicKey(fromPrivateKey: Curve25519.generatePrivateKey()))
+ peer.endpoint = Endpoint(from: endpoint)
+ peer.allowedIPs = [IPAddressRange(from: allowedIPs)!]
+
+ let tunnelConfiguration = TunnelConfiguration(interface: interface, peers: [peer])
+
+ let tunnelProviderManager = NETunnelProviderManager()
+ tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration)
+ tunnelProviderManager.localizedDescription = tunnelName
+ tunnelProviderManager.isEnabled = true
+
+ return tunnelProviderManager
+ }
+ }
+}
+#endif