mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2025-01-17 13:59:07 +00:00
d29f47fc9b
The username corresponds to the Account field in iOS system VPN UI, but if we don't set it, the field is not shown, so setting it isn't really required. Signed-off-by: Roopesh Chander <roop@roopc.net>
44 lines
1.4 KiB
Swift
44 lines
1.4 KiB
Swift
// SPDX-License-Identifier: MIT
|
|
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
|
|
|
import NetworkExtension
|
|
|
|
enum PacketTunnelProviderError: String, Error {
|
|
case savedProtocolConfigurationIsInvalid
|
|
case dnsResolutionFailure
|
|
case couldNotStartBackend
|
|
case couldNotDetermineFileDescriptor
|
|
case couldNotSetNetworkSettings
|
|
}
|
|
|
|
extension NETunnelProviderProtocol {
|
|
|
|
enum Keys: String {
|
|
case wgQuickConfig = "WgQuickConfig"
|
|
}
|
|
|
|
convenience init?(tunnelConfiguration: TunnelConfiguration) {
|
|
self.init()
|
|
|
|
let appId = Bundle.main.bundleIdentifier!
|
|
providerBundleIdentifier = "\(appId).network-extension"
|
|
providerConfiguration = [Keys.wgQuickConfig.rawValue: tunnelConfiguration.asWgQuickConfig()]
|
|
|
|
let endpoints = tunnelConfiguration.peers.compactMap { $0.endpoint }
|
|
if endpoints.count == 1 {
|
|
serverAddress = endpoints[0].stringRepresentation
|
|
} else if endpoints.isEmpty {
|
|
serverAddress = "Unspecified"
|
|
} else {
|
|
serverAddress = "Multiple endpoints"
|
|
}
|
|
}
|
|
|
|
func asTunnelConfiguration(called name: String? = nil) -> TunnelConfiguration? {
|
|
migrateConfigurationIfNeeded()
|
|
guard let serializedConfig = providerConfiguration?[Keys.wgQuickConfig.rawValue] as? String else { return nil }
|
|
return try? TunnelConfiguration(fromWgQuickConfig: serializedConfig, called: name)
|
|
}
|
|
|
|
}
|