2018-12-15 19:41:23 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-06-17 14:56:46 +00:00
|
|
|
// Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.
|
2018-12-15 19:41:23 +00:00
|
|
|
|
|
|
|
import NetworkExtension
|
|
|
|
|
|
|
|
// Creates mock tunnels for the iOS Simulator.
|
|
|
|
|
|
|
|
#if targetEnvironment(simulator)
|
|
|
|
class MockTunnels {
|
|
|
|
static let tunnelNames = [
|
|
|
|
"demo",
|
|
|
|
"edgesecurity",
|
|
|
|
"home",
|
2018-12-16 00:51:14 +00:00
|
|
|
"office",
|
|
|
|
"infra-fr",
|
|
|
|
"infra-us",
|
|
|
|
"krantz",
|
|
|
|
"metheny",
|
|
|
|
"frisell"
|
2018-12-15 19:41:23 +00:00
|
|
|
]
|
2018-12-16 00:51:14 +00:00
|
|
|
static let address = "192.168.%d.%d/32"
|
|
|
|
static let dnsServers = ["8.8.8.8", "8.8.4.4"]
|
|
|
|
static let endpoint = "demo.wireguard.com:51820"
|
2018-12-15 19:41:23 +00:00
|
|
|
static let allowedIPs = "0.0.0.0/0"
|
|
|
|
|
|
|
|
static func createMockTunnels() -> [NETunnelProviderManager] {
|
|
|
|
return tunnelNames.map { tunnelName -> NETunnelProviderManager in
|
|
|
|
|
2020-11-26 16:23:50 +00:00
|
|
|
var interface = InterfaceConfiguration(privateKey: PrivateKey())
|
2018-12-16 00:51:14 +00:00
|
|
|
interface.addresses = [IPAddressRange(from: String(format: address, Int.random(in: 1 ... 10), Int.random(in: 1 ... 254)))!]
|
2018-12-15 19:41:23 +00:00
|
|
|
interface.dns = dnsServers.map { DNSServer(from: $0)! }
|
|
|
|
|
2020-11-26 16:23:50 +00:00
|
|
|
var peer = PeerConfiguration(publicKey: PrivateKey().publicKey)
|
2018-12-15 19:41:23 +00:00
|
|
|
peer.endpoint = Endpoint(from: endpoint)
|
|
|
|
peer.allowedIPs = [IPAddressRange(from: allowedIPs)!]
|
|
|
|
|
2018-12-22 00:35:01 +00:00
|
|
|
let tunnelConfiguration = TunnelConfiguration(name: tunnelName, interface: interface, peers: [peer])
|
2018-12-15 19:41:23 +00:00
|
|
|
|
|
|
|
let tunnelProviderManager = NETunnelProviderManager()
|
2018-12-21 17:50:32 +00:00
|
|
|
tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration)
|
2018-12-22 00:35:01 +00:00
|
|
|
tunnelProviderManager.localizedDescription = tunnelConfiguration.name
|
2018-12-15 19:41:23 +00:00
|
|
|
tunnelProviderManager.isEnabled = true
|
|
|
|
|
|
|
|
return tunnelProviderManager
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|