From 2a22c0f2d6dd6bfd62f5663bddb11756e7d2a091 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Sun, 16 Dec 2018 01:11:23 +0530 Subject: Provide mock tunnels for the Simulator To help in generation of screenshots for the App Store Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/Tunnel/MockTunnels.swift | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 WireGuard/WireGuard/Tunnel/MockTunnels.swift (limited to 'WireGuard/WireGuard/Tunnel/MockTunnels.swift') 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 -- cgit v1.2.3-59-g8ed1b