2018-08-23 11:43:04 +00:00
|
|
|
//
|
2019-05-19 12:04:41 +00:00
|
|
|
// Configuration.swift
|
2018-08-23 11:43:04 +00:00
|
|
|
// TunnelKit
|
|
|
|
//
|
2018-08-27 18:30:09 +00:00
|
|
|
// Created by Davide De Rosa on 8/23/18.
|
2023-03-17 15:58:36 +00:00
|
|
|
// Copyright (c) 2023 Davide De Rosa. All rights reserved.
|
2018-08-27 18:30:09 +00:00
|
|
|
//
|
2019-05-14 08:58:47 +00:00
|
|
|
// https://github.com/passepartoutvpn
|
2018-08-27 18:30:09 +00:00
|
|
|
//
|
|
|
|
// This file is part of TunnelKit.
|
|
|
|
//
|
|
|
|
// TunnelKit is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// TunnelKit is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with TunnelKit. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
// This file incorporates work covered by the following copyright and
|
|
|
|
// permission notice:
|
|
|
|
//
|
|
|
|
// Copyright (c) 2018-Present Private Internet Access
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
//
|
2018-08-23 11:43:04 +00:00
|
|
|
|
|
|
|
import Foundation
|
2021-01-03 08:48:48 +00:00
|
|
|
import SwiftyBeaver
|
2021-10-25 14:27:27 +00:00
|
|
|
import TunnelKitCore
|
2021-01-03 08:48:48 +00:00
|
|
|
|
|
|
|
private let log = SwiftyBeaver.self
|
2018-08-23 11:43:04 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
extension OpenVPN {
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-10-05 17:13:59 +00:00
|
|
|
/// A pair of credentials for authentication.
|
|
|
|
public struct Credentials: Codable, Equatable {
|
|
|
|
|
|
|
|
/// The username.
|
|
|
|
public let username: String
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-10-05 17:13:59 +00:00
|
|
|
/// The password.
|
|
|
|
public let password: String
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-10-05 17:13:59 +00:00
|
|
|
public init(_ username: String, _ password: String) {
|
|
|
|
self.username = username
|
|
|
|
self.password = password
|
|
|
|
}
|
|
|
|
}
|
2018-08-23 11:43:04 +00:00
|
|
|
|
2019-05-19 12:39:51 +00:00
|
|
|
/// Encryption algorithm.
|
2018-09-06 08:55:56 +00:00
|
|
|
public enum Cipher: String, Codable, CustomStringConvertible {
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-08-23 13:44:31 +00:00
|
|
|
// WARNING: must match OpenSSL algorithm names
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-08-23 13:44:31 +00:00
|
|
|
/// AES encryption with 128-bit key size and CBC.
|
|
|
|
case aes128cbc = "AES-128-CBC"
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-09-06 08:37:53 +00:00
|
|
|
/// AES encryption with 192-bit key size and CBC.
|
|
|
|
case aes192cbc = "AES-192-CBC"
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-08-23 13:44:31 +00:00
|
|
|
/// AES encryption with 256-bit key size and CBC.
|
|
|
|
case aes256cbc = "AES-256-CBC"
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-08-23 13:44:31 +00:00
|
|
|
/// AES encryption with 128-bit key size and GCM.
|
|
|
|
case aes128gcm = "AES-128-GCM"
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-09-06 08:37:53 +00:00
|
|
|
/// AES encryption with 192-bit key size and GCM.
|
|
|
|
case aes192gcm = "AES-192-GCM"
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-08-23 13:44:31 +00:00
|
|
|
/// AES encryption with 256-bit key size and GCM.
|
|
|
|
case aes256gcm = "AES-256-GCM"
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-15 15:37:57 +00:00
|
|
|
/// Returns the key size for this cipher.
|
|
|
|
public var keySize: Int {
|
|
|
|
switch self {
|
|
|
|
case .aes128cbc, .aes128gcm:
|
|
|
|
return 128
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-15 15:37:57 +00:00
|
|
|
case .aes192cbc, .aes192gcm:
|
|
|
|
return 192
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-15 15:37:57 +00:00
|
|
|
case .aes256cbc, .aes256gcm:
|
|
|
|
return 256
|
|
|
|
}
|
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-09-04 13:48:57 +00:00
|
|
|
/// Digest should be ignored when this is `true`.
|
|
|
|
public var embedsDigest: Bool {
|
|
|
|
return rawValue.hasSuffix("-GCM")
|
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-09-06 09:14:04 +00:00
|
|
|
/// Returns a generic name for this cipher.
|
2018-09-06 08:55:56 +00:00
|
|
|
public var genericName: String {
|
2018-09-06 09:13:10 +00:00
|
|
|
return rawValue.hasSuffix("-GCM") ? "AES-GCM" : "AES-CBC"
|
2018-09-06 08:55:56 +00:00
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-09-06 08:55:56 +00:00
|
|
|
public var description: String {
|
|
|
|
return rawValue
|
|
|
|
}
|
2018-08-23 13:44:31 +00:00
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:39:51 +00:00
|
|
|
/// Message digest algorithm.
|
2018-09-06 08:55:56 +00:00
|
|
|
public enum Digest: String, Codable, CustomStringConvertible {
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-08-23 13:44:31 +00:00
|
|
|
// WARNING: must match OpenSSL algorithm names
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-08-23 13:44:31 +00:00
|
|
|
/// SHA1 message digest.
|
|
|
|
case sha1 = "SHA1"
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-09-06 08:37:53 +00:00
|
|
|
/// SHA224 message digest.
|
|
|
|
case sha224 = "SHA224"
|
|
|
|
|
2018-08-23 13:44:31 +00:00
|
|
|
/// SHA256 message digest.
|
|
|
|
case sha256 = "SHA256"
|
2018-09-06 08:37:53 +00:00
|
|
|
|
|
|
|
/// SHA256 message digest.
|
|
|
|
case sha384 = "SHA384"
|
|
|
|
|
|
|
|
/// SHA256 message digest.
|
|
|
|
case sha512 = "SHA512"
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-09-06 09:14:04 +00:00
|
|
|
/// Returns a generic name for this digest.
|
2018-09-06 08:55:56 +00:00
|
|
|
public var genericName: String {
|
|
|
|
return "HMAC"
|
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-09-06 08:55:56 +00:00
|
|
|
public var description: String {
|
|
|
|
return "\(genericName)-\(rawValue)"
|
|
|
|
}
|
2018-08-23 13:44:31 +00:00
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-25 11:06:22 +00:00
|
|
|
/// Routing policy.
|
|
|
|
public enum RoutingPolicy: String, Codable {
|
|
|
|
|
|
|
|
/// All IPv4 traffic goes through the VPN.
|
|
|
|
case IPv4
|
|
|
|
|
|
|
|
/// All IPv6 traffic goes through the VPN.
|
|
|
|
case IPv6
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-01 15:15:41 +00:00
|
|
|
/// Block LAN while connected.
|
|
|
|
case blockLocal
|
2019-04-25 11:06:22 +00:00
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-08 06:54:55 +00:00
|
|
|
/// Settings that can be pulled from server.
|
|
|
|
public enum PullMask: String, Codable, CaseIterable {
|
|
|
|
|
|
|
|
/// Routes and gateways.
|
|
|
|
case routes
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-08 06:54:55 +00:00
|
|
|
/// DNS settings.
|
|
|
|
case dns
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-08 06:54:55 +00:00
|
|
|
/// Proxy settings.
|
|
|
|
case proxy
|
|
|
|
}
|
|
|
|
|
2019-05-19 12:19:23 +00:00
|
|
|
/// The way to create a `Configuration` object for a `OpenVPNSession`.
|
2018-08-23 11:43:04 +00:00
|
|
|
public struct ConfigurationBuilder {
|
2018-08-30 09:05:34 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
// MARK: General
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The cipher algorithm for data encryption.
|
2019-05-19 12:04:41 +00:00
|
|
|
public var cipher: Cipher?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2021-01-02 23:44:42 +00:00
|
|
|
/// The set of supported cipher algorithms for data encryption (2.5.).
|
|
|
|
public var dataCiphers: [Cipher]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The digest algorithm for HMAC.
|
2019-05-19 12:04:41 +00:00
|
|
|
public var digest: Digest?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// Compression framing, disabled by default.
|
2019-05-19 12:04:41 +00:00
|
|
|
public var compressionFraming: CompressionFraming?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// Compression algorithm, disabled by default.
|
2019-05-19 12:04:41 +00:00
|
|
|
public var compressionAlgorithm: CompressionAlgorithm?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The CA for TLS negotiation (PEM format).
|
|
|
|
public var ca: CryptoContainer?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The optional client certificate for TLS negotiation (PEM format).
|
2018-10-25 06:02:48 +00:00
|
|
|
public var clientCertificate: CryptoContainer?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The private key for the certificate in `clientCertificate` (PEM format).
|
2018-10-25 06:02:48 +00:00
|
|
|
public var clientKey: CryptoContainer?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The optional TLS wrapping.
|
2019-05-19 12:04:41 +00:00
|
|
|
public var tlsWrap: TLSWrap?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2021-11-24 15:40:19 +00:00
|
|
|
/// If set, overrides TLS security level (0 = lowest).
|
|
|
|
public var tlsSecurityLevel: Int?
|
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// Sends periodical keep-alive packets if set.
|
2018-08-23 11:43:04 +00:00
|
|
|
public var keepAliveInterval: TimeInterval?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-10-22 08:43:57 +00:00
|
|
|
/// Disconnects after no keep-alive packets are received within timeout interval if set.
|
2019-09-30 18:54:29 +00:00
|
|
|
public var keepAliveTimeout: TimeInterval?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The number of seconds after which a renegotiation should be initiated. If `nil`, the client will never initiate a renegotiation.
|
2018-08-23 11:43:04 +00:00
|
|
|
public var renegotiatesAfter: TimeInterval?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
// MARK: Client
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The list of server endpoints.
|
2022-03-03 14:34:57 +00:00
|
|
|
public var remotes: [Endpoint]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// If true, checks EKU of server certificate.
|
|
|
|
public var checksEKU: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2020-05-08 22:02:16 +00:00
|
|
|
/// If true, checks if hostname (sanHost) is present in certificates SAN.
|
|
|
|
public var checksSANHost: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2020-05-08 22:02:16 +00:00
|
|
|
/// The server hostname used for checking certificate SAN.
|
|
|
|
public var sanHost: String?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// Picks endpoint from `remotes` randomly.
|
2019-03-25 09:17:47 +00:00
|
|
|
public var randomizeEndpoint: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-17 07:00:23 +00:00
|
|
|
/// Prepend hostnames with a number of random bytes defined in `Configuration.randomHostnamePrefixLength`.
|
|
|
|
public var randomizeHostnames: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-03 10:11:25 +00:00
|
|
|
/// Server is patched for the PIA VPN provider.
|
|
|
|
public var usesPIAPatches: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2020-12-27 21:56:09 +00:00
|
|
|
/// The tunnel MTU.
|
|
|
|
public var mtu: Int?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-02-12 07:37:51 +00:00
|
|
|
/// Requires username authentication.
|
|
|
|
public var authUserPass: Bool?
|
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
// MARK: Server
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The auth-token returned by the server.
|
|
|
|
public var authToken: String?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The peer-id returned by the server.
|
|
|
|
public var peerId: UInt32?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
// MARK: Routing
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:19:23 +00:00
|
|
|
/// The settings for IPv4. `OpenVPNSession` only evaluates this server-side.
|
2019-04-04 09:06:00 +00:00
|
|
|
public var ipv4: IPv4Settings?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:19:23 +00:00
|
|
|
/// The settings for IPv6. `OpenVPNSession` only evaluates this server-side.
|
2019-04-04 09:06:00 +00:00
|
|
|
public var ipv6: IPv6Settings?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-29 10:24:28 +00:00
|
|
|
/// The IPv4 routes if `ipv4` is nil.
|
|
|
|
public var routes4: [IPv4Settings.Route]?
|
|
|
|
|
|
|
|
/// The IPv6 routes if `ipv6` is nil.
|
|
|
|
public var routes6: [IPv6Settings.Route]?
|
|
|
|
|
2022-03-26 16:15:36 +00:00
|
|
|
/// Set false to ignore DNS settings, even when pushed.
|
|
|
|
public var isDNSEnabled: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2021-01-22 09:18:31 +00:00
|
|
|
/// The DNS protocol, defaults to `.plain` (iOS 14+ / macOS 11+).
|
|
|
|
public var dnsProtocol: DNSProtocol?
|
|
|
|
|
|
|
|
/// The DNS servers if `dnsProtocol = .plain` or nil.
|
2019-04-04 09:06:00 +00:00
|
|
|
public var dnsServers: [String]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2021-01-22 09:18:31 +00:00
|
|
|
/// The server URL if `dnsProtocol = .https`.
|
|
|
|
public var dnsHTTPSURL: URL?
|
|
|
|
|
|
|
|
/// The server name if `dnsProtocol = .tls`.
|
|
|
|
public var dnsTLSServerName: String?
|
|
|
|
|
2023-03-17 19:22:21 +00:00
|
|
|
/// The main domain name.
|
|
|
|
public var dnsDomain: String?
|
|
|
|
|
2019-04-04 09:06:00 +00:00
|
|
|
/// The search domain.
|
2019-10-25 15:14:59 +00:00
|
|
|
@available(*, deprecated, message: "Use searchDomains instead")
|
|
|
|
public var searchDomain: String? {
|
|
|
|
didSet {
|
|
|
|
guard let searchDomain = searchDomain else {
|
|
|
|
searchDomains = nil
|
|
|
|
return
|
|
|
|
}
|
|
|
|
searchDomains = [searchDomain]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-17 19:22:21 +00:00
|
|
|
/// The search domains.
|
2019-10-25 15:14:59 +00:00
|
|
|
public var searchDomains: [String]?
|
2019-04-04 11:13:28 +00:00
|
|
|
|
2019-10-21 19:47:45 +00:00
|
|
|
/// The Proxy Auto-Configuration (PAC) url.
|
2019-10-22 19:03:25 +00:00
|
|
|
public var proxyAutoConfigurationURL: URL?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-03-26 16:15:36 +00:00
|
|
|
/// Set false to ignore proxy settings, even when pushed.
|
|
|
|
public var isProxyEnabled: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-12 05:47:27 +00:00
|
|
|
/// The HTTP proxy.
|
|
|
|
public var httpProxy: Proxy?
|
2019-10-21 19:47:45 +00:00
|
|
|
|
2019-04-12 05:47:27 +00:00
|
|
|
/// The HTTPS proxy.
|
|
|
|
public var httpsProxy: Proxy?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-13 17:03:27 +00:00
|
|
|
/// The list of domains not passing through the proxy.
|
|
|
|
public var proxyBypassDomains: [String]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-25 11:06:22 +00:00
|
|
|
/// Policies for redirecting traffic through the VPN gateway.
|
|
|
|
public var routingPolicies: [RoutingPolicy]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-08 06:54:55 +00:00
|
|
|
/// Server settings that must not be pulled.
|
|
|
|
public var noPullMask: [PullMask]?
|
|
|
|
|
2022-11-06 16:46:10 +00:00
|
|
|
// MARK: Extra
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-11-06 16:46:10 +00:00
|
|
|
/// The method to follow in regards to the XOR patch.
|
|
|
|
public var xorMethod: XORMethod?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-02-12 07:37:51 +00:00
|
|
|
/**
|
|
|
|
Creates a `ConfigurationBuilder`.
|
|
|
|
|
|
|
|
- Parameter withFallbacks: If `true`, initializes builder with fallback values rather than nil.
|
|
|
|
*/
|
|
|
|
public init(withFallbacks: Bool = false) {
|
|
|
|
if withFallbacks {
|
2022-04-03 10:16:47 +00:00
|
|
|
cipher = Configuration.Fallback.cipher
|
|
|
|
digest = Configuration.Fallback.digest
|
|
|
|
compressionFraming = Configuration.Fallback.compressionFraming
|
|
|
|
compressionAlgorithm = Configuration.Fallback.compressionAlgorithm
|
2022-02-12 07:37:51 +00:00
|
|
|
}
|
2019-04-04 11:13:28 +00:00
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2018-08-23 11:43:04 +00:00
|
|
|
/**
|
2019-05-19 12:04:41 +00:00
|
|
|
Builds a `Configuration` object.
|
2018-08-23 11:43:04 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
- Returns: A `Configuration` object with this builder.
|
2018-08-23 11:43:04 +00:00
|
|
|
*/
|
|
|
|
public func build() -> Configuration {
|
|
|
|
return Configuration(
|
2018-08-23 13:44:31 +00:00
|
|
|
cipher: cipher,
|
2021-01-02 23:44:42 +00:00
|
|
|
dataCiphers: dataCiphers,
|
2018-08-23 13:44:31 +00:00
|
|
|
digest: digest,
|
2019-04-04 09:06:00 +00:00
|
|
|
compressionFraming: compressionFraming,
|
|
|
|
compressionAlgorithm: compressionAlgorithm,
|
2018-10-25 06:02:48 +00:00
|
|
|
ca: ca,
|
|
|
|
clientCertificate: clientCertificate,
|
|
|
|
clientKey: clientKey,
|
2018-09-19 20:22:35 +00:00
|
|
|
tlsWrap: tlsWrap,
|
2021-11-24 15:40:19 +00:00
|
|
|
tlsSecurityLevel: tlsSecurityLevel,
|
2018-08-23 11:43:04 +00:00
|
|
|
keepAliveInterval: keepAliveInterval,
|
2019-09-30 18:54:29 +00:00
|
|
|
keepAliveTimeout: keepAliveTimeout,
|
2018-10-18 09:36:02 +00:00
|
|
|
renegotiatesAfter: renegotiatesAfter,
|
2022-03-03 14:34:57 +00:00
|
|
|
remotes: remotes,
|
2019-04-04 09:06:00 +00:00
|
|
|
checksEKU: checksEKU,
|
2020-05-08 22:02:16 +00:00
|
|
|
checksSANHost: checksSANHost,
|
|
|
|
sanHost: sanHost,
|
2019-04-03 10:11:25 +00:00
|
|
|
randomizeEndpoint: randomizeEndpoint,
|
2022-10-17 07:00:23 +00:00
|
|
|
randomizeHostnames: randomizeHostnames,
|
2019-04-04 09:06:00 +00:00
|
|
|
usesPIAPatches: usesPIAPatches,
|
2020-12-27 21:56:09 +00:00
|
|
|
mtu: mtu,
|
2022-02-12 07:37:51 +00:00
|
|
|
authUserPass: authUserPass,
|
2019-04-04 09:06:00 +00:00
|
|
|
authToken: authToken,
|
|
|
|
peerId: peerId,
|
|
|
|
ipv4: ipv4,
|
|
|
|
ipv6: ipv6,
|
2022-10-29 10:24:28 +00:00
|
|
|
routes4: routes4,
|
|
|
|
routes6: routes6,
|
2022-03-26 16:15:36 +00:00
|
|
|
isDNSEnabled: isDNSEnabled,
|
2021-01-22 09:18:31 +00:00
|
|
|
dnsProtocol: dnsProtocol,
|
2019-04-04 09:06:00 +00:00
|
|
|
dnsServers: dnsServers,
|
2021-01-22 09:18:31 +00:00
|
|
|
dnsHTTPSURL: dnsHTTPSURL,
|
|
|
|
dnsTLSServerName: dnsTLSServerName,
|
2023-03-17 19:22:21 +00:00
|
|
|
dnsDomain: dnsDomain,
|
2019-10-25 15:14:59 +00:00
|
|
|
searchDomains: searchDomains,
|
2022-03-26 16:15:36 +00:00
|
|
|
isProxyEnabled: isProxyEnabled,
|
2019-04-12 05:47:27 +00:00
|
|
|
httpProxy: httpProxy,
|
2019-04-13 17:03:27 +00:00
|
|
|
httpsProxy: httpsProxy,
|
2019-10-22 19:03:25 +00:00
|
|
|
proxyAutoConfigurationURL: proxyAutoConfigurationURL,
|
2019-04-25 11:06:22 +00:00
|
|
|
proxyBypassDomains: proxyBypassDomains,
|
2022-10-08 06:54:55 +00:00
|
|
|
routingPolicies: routingPolicies,
|
2022-11-06 16:46:10 +00:00
|
|
|
noPullMask: noPullMask,
|
|
|
|
xorMethod: xorMethod
|
2018-08-23 11:43:04 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:19:23 +00:00
|
|
|
/// The immutable configuration for `OpenVPNSession`.
|
2022-03-22 06:14:57 +00:00
|
|
|
public struct Configuration: Codable, Equatable {
|
2022-09-23 19:45:04 +00:00
|
|
|
struct Fallback {
|
|
|
|
static let cipher: Cipher = .aes128cbc
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-09-23 19:45:04 +00:00
|
|
|
static let digest: Digest = .sha1
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-09-23 19:45:04 +00:00
|
|
|
static let compressionFraming: CompressionFraming = .disabled
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-09-23 19:45:04 +00:00
|
|
|
static let compressionAlgorithm: CompressionAlgorithm = .disabled
|
2022-04-03 10:16:47 +00:00
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-17 07:00:23 +00:00
|
|
|
private static let randomHostnamePrefixLength = 6
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.cipher`
|
2019-04-04 11:01:32 +00:00
|
|
|
public let cipher: Cipher?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2021-01-02 23:44:42 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.dataCiphers`
|
|
|
|
public let dataCiphers: [Cipher]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.digest`
|
2019-04-04 11:01:32 +00:00
|
|
|
public let digest: Digest?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.compressionFraming`
|
2019-04-04 11:01:32 +00:00
|
|
|
public let compressionFraming: CompressionFraming?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.compressionAlgorithm`
|
2019-04-04 09:06:00 +00:00
|
|
|
public let compressionAlgorithm: CompressionAlgorithm?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.ca`
|
2019-04-04 09:06:00 +00:00
|
|
|
public let ca: CryptoContainer?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.clientCertificate`
|
2018-10-25 06:02:48 +00:00
|
|
|
public let clientCertificate: CryptoContainer?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.clientKey`
|
2018-10-25 06:02:48 +00:00
|
|
|
public let clientKey: CryptoContainer?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.tlsWrap`
|
2019-04-28 21:07:27 +00:00
|
|
|
public let tlsWrap: TLSWrap?
|
2018-09-19 20:22:35 +00:00
|
|
|
|
2021-11-24 15:40:19 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.tlsSecurityLevel`
|
|
|
|
public let tlsSecurityLevel: Int?
|
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.keepAliveInterval`
|
2018-08-23 11:43:04 +00:00
|
|
|
public let keepAliveInterval: TimeInterval?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-09-30 18:54:29 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.keepAliveTimeout`
|
|
|
|
public let keepAliveTimeout: TimeInterval?
|
2018-08-23 11:43:04 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.renegotiatesAfter`
|
2018-08-23 11:43:04 +00:00
|
|
|
public let renegotiatesAfter: TimeInterval?
|
2018-10-18 09:36:02 +00:00
|
|
|
|
2022-03-03 14:34:57 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.remotes`
|
|
|
|
public let remotes: [Endpoint]?
|
2019-04-04 09:06:00 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.checksEKU`
|
2019-04-04 09:06:00 +00:00
|
|
|
public let checksEKU: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2020-05-08 22:02:16 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.checksSANHost`
|
|
|
|
public let checksSANHost: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2020-05-08 22:02:16 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.sanHost`
|
|
|
|
public let sanHost: String?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.randomizeEndpoint`
|
2019-03-25 09:17:47 +00:00
|
|
|
public let randomizeEndpoint: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-17 07:00:23 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.randomizeHostnames`
|
|
|
|
public var randomizeHostnames: Bool?
|
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.usesPIAPatches`
|
2019-04-03 10:11:25 +00:00
|
|
|
public let usesPIAPatches: Bool?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2020-12-27 21:56:09 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.mtu`
|
|
|
|
public let mtu: Int?
|
|
|
|
|
2022-02-12 07:37:51 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.authUserPass`
|
|
|
|
public let authUserPass: Bool?
|
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.authToken`
|
2019-04-04 09:06:00 +00:00
|
|
|
public let authToken: String?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.peerId`
|
2019-04-04 09:06:00 +00:00
|
|
|
public let peerId: UInt32?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.ipv4`
|
2019-04-04 09:06:00 +00:00
|
|
|
public let ipv4: IPv4Settings?
|
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.ipv6`
|
2019-04-04 09:06:00 +00:00
|
|
|
public let ipv6: IPv6Settings?
|
|
|
|
|
2022-10-29 10:24:28 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.routes4`
|
|
|
|
public let routes4: [IPv4Settings.Route]?
|
|
|
|
|
|
|
|
/// - Seealso: `ConfigurationBuilder.routes6`
|
|
|
|
public let routes6: [IPv6Settings.Route]?
|
|
|
|
|
2022-03-26 16:15:36 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.isDNSEnabled`
|
|
|
|
public let isDNSEnabled: Bool?
|
|
|
|
|
2021-01-22 09:18:31 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.dnsProtocol`
|
|
|
|
public let dnsProtocol: DNSProtocol?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.dnsServers`
|
2019-04-04 09:06:00 +00:00
|
|
|
public let dnsServers: [String]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2021-01-22 09:18:31 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.dnsHTTPSURL`
|
|
|
|
public let dnsHTTPSURL: URL?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2021-01-22 09:18:31 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.dnsTLSServerName`
|
|
|
|
public let dnsTLSServerName: String?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2023-03-17 19:22:21 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.dnsDomain`
|
|
|
|
public let dnsDomain: String?
|
|
|
|
|
2019-10-25 15:14:59 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.searchDomains`
|
|
|
|
public let searchDomains: [String]?
|
|
|
|
|
2022-03-26 16:15:36 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.isProxyEnabled`
|
|
|
|
public let isProxyEnabled: Bool?
|
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.httpProxy`
|
2019-04-28 21:07:27 +00:00
|
|
|
public let httpProxy: Proxy?
|
2019-10-21 19:47:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.httpsProxy`
|
2019-04-28 21:07:27 +00:00
|
|
|
public let httpsProxy: Proxy?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-10-22 19:03:25 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.proxyAutoConfigurationURL`
|
|
|
|
public let proxyAutoConfigurationURL: URL?
|
2019-10-21 19:47:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.proxyBypassDomains`
|
2019-04-28 21:07:27 +00:00
|
|
|
public let proxyBypassDomains: [String]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.routingPolicies`
|
2019-04-28 21:07:27 +00:00
|
|
|
public let routingPolicies: [RoutingPolicy]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-08 06:54:55 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.noPullMask`
|
|
|
|
public let noPullMask: [PullMask]?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-11-06 16:46:10 +00:00
|
|
|
/// - Seealso: `ConfigurationBuilder.xorMethod`
|
|
|
|
public let xorMethod: XORMethod?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 11:01:32 +00:00
|
|
|
// MARK: Shortcuts
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-04 11:01:32 +00:00
|
|
|
public var fallbackCipher: Cipher {
|
|
|
|
return cipher ?? Fallback.cipher
|
|
|
|
}
|
|
|
|
|
|
|
|
public var fallbackDigest: Digest {
|
|
|
|
return digest ?? Fallback.digest
|
|
|
|
}
|
|
|
|
|
|
|
|
public var fallbackCompressionFraming: CompressionFraming {
|
|
|
|
return compressionFraming ?? Fallback.compressionFraming
|
|
|
|
}
|
2022-09-23 21:01:57 +00:00
|
|
|
|
|
|
|
public var fallbackCompressionAlgorithm: CompressionAlgorithm {
|
|
|
|
return compressionAlgorithm ?? Fallback.compressionAlgorithm
|
|
|
|
}
|
2022-10-08 06:54:55 +00:00
|
|
|
|
|
|
|
public var pullMask: [PullMask]? {
|
|
|
|
let all = PullMask.allCases
|
|
|
|
guard let notPulled = noPullMask else {
|
|
|
|
return all
|
|
|
|
}
|
|
|
|
let pulled = Array(Set(all).subtracting(notPulled))
|
|
|
|
return !pulled.isEmpty ? pulled : nil
|
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-17 07:00:23 +00:00
|
|
|
// MARK: Computed
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-17 07:00:23 +00:00
|
|
|
public var processedRemotes: [Endpoint]? {
|
|
|
|
guard var processedRemotes = remotes else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if randomizeEndpoint ?? false {
|
|
|
|
processedRemotes.shuffle()
|
|
|
|
}
|
|
|
|
if let randomPrefixLength = (randomizeHostnames ?? false) ? Self.randomHostnamePrefixLength : nil {
|
|
|
|
processedRemotes = processedRemotes.compactMap {
|
|
|
|
do {
|
|
|
|
return try $0.withRandomPrefixLength(randomPrefixLength)
|
|
|
|
} catch {
|
|
|
|
log.warning("Could not prepend random prefix: \(error)")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return processedRemotes
|
|
|
|
}
|
2018-08-23 11:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-04 10:40:28 +00:00
|
|
|
|
2019-04-11 14:46:52 +00:00
|
|
|
// MARK: Modification
|
|
|
|
|
2019-05-19 12:04:41 +00:00
|
|
|
extension OpenVPN.Configuration {
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-04-11 14:46:52 +00:00
|
|
|
/**
|
2019-05-19 12:04:41 +00:00
|
|
|
Returns a `ConfigurationBuilder` to use this configuration as a starting point for a new one.
|
2019-04-11 14:46:52 +00:00
|
|
|
|
2022-02-12 07:37:51 +00:00
|
|
|
- Parameter withFallbacks: If `true`, initializes builder with fallback values rather than nil.
|
2019-05-19 12:04:41 +00:00
|
|
|
- Returns: An editable `ConfigurationBuilder` initialized with this configuration.
|
2019-04-11 14:46:52 +00:00
|
|
|
*/
|
2022-02-12 07:37:51 +00:00
|
|
|
public func builder(withFallbacks: Bool = false) -> OpenVPN.ConfigurationBuilder {
|
2019-05-19 12:04:41 +00:00
|
|
|
var builder = OpenVPN.ConfigurationBuilder()
|
2022-04-03 10:16:47 +00:00
|
|
|
builder.cipher = cipher ?? (withFallbacks ? Fallback.cipher : nil)
|
2021-01-02 23:44:42 +00:00
|
|
|
builder.dataCiphers = dataCiphers
|
2022-04-03 10:16:47 +00:00
|
|
|
builder.digest = digest ?? (withFallbacks ? Fallback.digest : nil)
|
|
|
|
builder.compressionFraming = compressionFraming ?? (withFallbacks ? Fallback.compressionFraming : nil)
|
|
|
|
builder.compressionAlgorithm = compressionAlgorithm ?? (withFallbacks ? Fallback.compressionAlgorithm : nil)
|
2019-04-11 14:46:52 +00:00
|
|
|
builder.ca = ca
|
|
|
|
builder.clientCertificate = clientCertificate
|
|
|
|
builder.clientKey = clientKey
|
|
|
|
builder.tlsWrap = tlsWrap
|
2021-11-24 15:40:19 +00:00
|
|
|
builder.tlsSecurityLevel = tlsSecurityLevel
|
2019-04-11 14:46:52 +00:00
|
|
|
builder.keepAliveInterval = keepAliveInterval
|
2019-09-30 18:54:29 +00:00
|
|
|
builder.keepAliveTimeout = keepAliveTimeout
|
2019-04-11 14:46:52 +00:00
|
|
|
builder.renegotiatesAfter = renegotiatesAfter
|
2022-03-03 14:34:57 +00:00
|
|
|
builder.remotes = remotes
|
2019-04-11 14:46:52 +00:00
|
|
|
builder.checksEKU = checksEKU
|
2020-05-08 22:02:16 +00:00
|
|
|
builder.checksSANHost = checksSANHost
|
|
|
|
builder.sanHost = sanHost
|
2019-04-11 14:46:52 +00:00
|
|
|
builder.randomizeEndpoint = randomizeEndpoint
|
2022-10-17 07:00:23 +00:00
|
|
|
builder.randomizeHostnames = randomizeHostnames
|
2019-04-11 14:46:52 +00:00
|
|
|
builder.usesPIAPatches = usesPIAPatches
|
2020-12-27 21:56:09 +00:00
|
|
|
builder.mtu = mtu
|
2022-02-12 07:37:51 +00:00
|
|
|
builder.authUserPass = authUserPass
|
2019-04-11 14:46:52 +00:00
|
|
|
builder.authToken = authToken
|
|
|
|
builder.peerId = peerId
|
|
|
|
builder.ipv4 = ipv4
|
|
|
|
builder.ipv6 = ipv6
|
2022-10-29 10:24:28 +00:00
|
|
|
builder.routes4 = routes4
|
|
|
|
builder.routes6 = routes6
|
2022-03-26 16:15:36 +00:00
|
|
|
builder.isDNSEnabled = isDNSEnabled
|
2021-01-22 09:18:31 +00:00
|
|
|
builder.dnsProtocol = dnsProtocol
|
2019-04-11 14:46:52 +00:00
|
|
|
builder.dnsServers = dnsServers
|
2021-01-22 09:18:31 +00:00
|
|
|
builder.dnsHTTPSURL = dnsHTTPSURL
|
|
|
|
builder.dnsTLSServerName = dnsTLSServerName
|
2023-03-17 19:22:21 +00:00
|
|
|
builder.dnsDomain = dnsDomain
|
2019-10-25 15:14:59 +00:00
|
|
|
builder.searchDomains = searchDomains
|
2022-03-26 16:15:36 +00:00
|
|
|
builder.isProxyEnabled = isProxyEnabled
|
2019-04-12 05:47:27 +00:00
|
|
|
builder.httpProxy = httpProxy
|
|
|
|
builder.httpsProxy = httpsProxy
|
2019-10-22 19:03:25 +00:00
|
|
|
builder.proxyAutoConfigurationURL = proxyAutoConfigurationURL
|
2019-04-13 17:03:27 +00:00
|
|
|
builder.proxyBypassDomains = proxyBypassDomains
|
2019-04-25 11:06:22 +00:00
|
|
|
builder.routingPolicies = routingPolicies
|
2022-10-08 06:54:55 +00:00
|
|
|
builder.noPullMask = noPullMask
|
2022-11-06 16:46:10 +00:00
|
|
|
builder.xorMethod = xorMethod
|
2019-04-11 14:46:52 +00:00
|
|
|
return builder
|
|
|
|
}
|
|
|
|
}
|
2021-01-03 08:48:48 +00:00
|
|
|
|
|
|
|
// MARK: Encoding
|
|
|
|
|
|
|
|
extension OpenVPN.Configuration {
|
2022-10-26 22:40:46 +00:00
|
|
|
public func print(isLocal: Bool) {
|
|
|
|
if isLocal {
|
|
|
|
guard let remotes = remotes else {
|
|
|
|
fatalError("No remotes set")
|
|
|
|
}
|
|
|
|
log.info("\tRemotes: \(remotes)")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isLocal {
|
|
|
|
log.info("\tIPv4: \(ipv4?.description ?? "not configured")")
|
|
|
|
log.info("\tIPv6: \(ipv6?.description ?? "not configured")")
|
|
|
|
}
|
2022-10-29 10:24:28 +00:00
|
|
|
if let routes = routes4 {
|
|
|
|
log.info("\tRoutes (IPv4): \(routes)")
|
|
|
|
}
|
|
|
|
if let routes = routes6 {
|
|
|
|
log.info("\tRoutes (IPv6): \(routes)")
|
|
|
|
}
|
2022-10-26 22:40:46 +00:00
|
|
|
|
|
|
|
if let cipher = cipher {
|
|
|
|
log.info("\tCipher: \(cipher)")
|
|
|
|
} else if isLocal {
|
|
|
|
log.info("\tCipher: \(fallbackCipher)")
|
|
|
|
}
|
|
|
|
if let digest = digest {
|
|
|
|
log.info("\tDigest: \(digest)")
|
|
|
|
} else if isLocal {
|
|
|
|
log.info("\tDigest: \(fallbackDigest)")
|
2021-11-24 15:40:19 +00:00
|
|
|
}
|
2022-10-26 22:40:46 +00:00
|
|
|
if let compressionFraming = compressionFraming {
|
|
|
|
log.info("\tCompression framing: \(compressionFraming)")
|
|
|
|
} else if isLocal {
|
|
|
|
log.info("\tCompression framing: \(fallbackCompressionFraming)")
|
|
|
|
}
|
|
|
|
if let compressionAlgorithm = compressionAlgorithm {
|
|
|
|
log.info("\tCompression algorithm: \(compressionAlgorithm)")
|
|
|
|
} else if isLocal {
|
|
|
|
log.info("\tCompression algorithm: \(fallbackCompressionAlgorithm)")
|
|
|
|
}
|
|
|
|
|
|
|
|
if isLocal {
|
|
|
|
log.info("\tUsername authentication: \(authUserPass ?? false)")
|
|
|
|
if let _ = clientCertificate {
|
|
|
|
log.info("\tClient verification: enabled")
|
|
|
|
} else {
|
|
|
|
log.info("\tClient verification: disabled")
|
|
|
|
}
|
|
|
|
if let tlsWrap = tlsWrap {
|
|
|
|
log.info("\tTLS wrapping: \(tlsWrap.strategy)")
|
|
|
|
} else {
|
|
|
|
log.info("\tTLS wrapping: disabled")
|
|
|
|
}
|
|
|
|
if let tlsSecurityLevel = tlsSecurityLevel {
|
|
|
|
log.info("\tTLS security level: \(tlsSecurityLevel)")
|
|
|
|
} else {
|
|
|
|
log.info("\tTLS security level: default")
|
|
|
|
}
|
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2021-01-03 08:48:48 +00:00
|
|
|
if let keepAliveSeconds = keepAliveInterval, keepAliveSeconds > 0 {
|
2021-01-27 00:36:48 +00:00
|
|
|
log.info("\tKeep-alive interval: \(keepAliveSeconds.asTimeString)")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-03 08:48:48 +00:00
|
|
|
log.info("\tKeep-alive interval: never")
|
|
|
|
}
|
|
|
|
if let keepAliveTimeoutSeconds = keepAliveTimeout, keepAliveTimeoutSeconds > 0 {
|
2021-01-27 00:36:48 +00:00
|
|
|
log.info("\tKeep-alive timeout: \(keepAliveTimeoutSeconds.asTimeString)")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-03 08:48:48 +00:00
|
|
|
log.info("\tKeep-alive timeout: never")
|
|
|
|
}
|
|
|
|
if let renegotiatesAfterSeconds = renegotiatesAfter, renegotiatesAfterSeconds > 0 {
|
2021-01-27 00:36:48 +00:00
|
|
|
log.info("\tRenegotiation: \(renegotiatesAfterSeconds.asTimeString)")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-03 08:48:48 +00:00
|
|
|
log.info("\tRenegotiation: never")
|
|
|
|
}
|
|
|
|
if checksEKU ?? false {
|
|
|
|
log.info("\tServer EKU verification: enabled")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-03 08:48:48 +00:00
|
|
|
log.info("\tServer EKU verification: disabled")
|
|
|
|
}
|
|
|
|
if checksSANHost ?? false {
|
|
|
|
log.info("\tHost SAN verification: enabled (\(sanHost ?? "-"))")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-03 08:48:48 +00:00
|
|
|
log.info("\tHost SAN verification: disabled")
|
|
|
|
}
|
2022-10-26 22:40:46 +00:00
|
|
|
|
2021-01-03 08:48:48 +00:00
|
|
|
if randomizeEndpoint ?? false {
|
|
|
|
log.info("\tRandomize endpoint: true")
|
|
|
|
}
|
2022-10-17 07:00:23 +00:00
|
|
|
if randomizeHostnames ?? false {
|
|
|
|
log.info("\tRandomize hostnames: true")
|
|
|
|
}
|
2022-10-26 22:40:46 +00:00
|
|
|
|
2021-01-03 08:48:48 +00:00
|
|
|
if let routingPolicies = routingPolicies {
|
2022-10-26 22:31:30 +00:00
|
|
|
log.info("\tGateway: \(routingPolicies.map(\.rawValue))")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-03 08:48:48 +00:00
|
|
|
log.info("\tGateway: not configured")
|
|
|
|
}
|
2022-10-26 22:40:46 +00:00
|
|
|
|
2021-01-22 16:58:33 +00:00
|
|
|
switch dnsProtocol {
|
|
|
|
case .https:
|
|
|
|
if let dnsHTTPSURL = dnsHTTPSURL {
|
|
|
|
log.info("\tDNS over HTTPS: \(dnsHTTPSURL.maskedDescription)")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-22 16:58:33 +00:00
|
|
|
log.info("\tDNS: not configured")
|
|
|
|
}
|
|
|
|
|
|
|
|
case .tls:
|
|
|
|
if let dnsTLSServerName = dnsTLSServerName {
|
|
|
|
log.info("\tDNS over TLS: \(dnsTLSServerName.maskedDescription)")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-22 16:58:33 +00:00
|
|
|
log.info("\tDNS: not configured")
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
if let dnsServers = dnsServers, !dnsServers.isEmpty {
|
|
|
|
log.info("\tDNS: \(dnsServers.maskedDescription)")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-22 16:58:33 +00:00
|
|
|
log.info("\tDNS: not configured")
|
|
|
|
}
|
2021-01-03 08:48:48 +00:00
|
|
|
}
|
2023-03-17 19:22:21 +00:00
|
|
|
if let dnsDomain = dnsDomain, !dnsDomain.isEmpty {
|
|
|
|
log.info("\tDNS domain: \(dnsDomain.maskedDescription)")
|
|
|
|
}
|
2021-01-03 08:48:48 +00:00
|
|
|
if let searchDomains = searchDomains, !searchDomains.isEmpty {
|
|
|
|
log.info("\tSearch domains: \(searchDomains.maskedDescription)")
|
|
|
|
}
|
2022-10-26 22:40:46 +00:00
|
|
|
|
2021-01-03 08:48:48 +00:00
|
|
|
if let httpProxy = httpProxy {
|
|
|
|
log.info("\tHTTP proxy: \(httpProxy.maskedDescription)")
|
|
|
|
}
|
|
|
|
if let httpsProxy = httpsProxy {
|
|
|
|
log.info("\tHTTPS proxy: \(httpsProxy.maskedDescription)")
|
|
|
|
}
|
|
|
|
if let proxyAutoConfigurationURL = proxyAutoConfigurationURL {
|
|
|
|
log.info("\tPAC: \(proxyAutoConfigurationURL)")
|
|
|
|
}
|
|
|
|
if let proxyBypassDomains = proxyBypassDomains {
|
|
|
|
log.info("\tProxy bypass domains: \(proxyBypassDomains.maskedDescription)")
|
|
|
|
}
|
2022-10-26 22:40:46 +00:00
|
|
|
|
2021-01-03 08:48:48 +00:00
|
|
|
if let mtu = mtu {
|
|
|
|
log.info("\tMTU: \(mtu)")
|
2022-10-26 22:40:46 +00:00
|
|
|
} else if isLocal {
|
2021-01-03 08:48:48 +00:00
|
|
|
log.info("\tMTU: default")
|
|
|
|
}
|
2022-10-26 22:40:46 +00:00
|
|
|
|
|
|
|
if isLocal, let noPullMask = noPullMask {
|
2022-10-08 06:54:55 +00:00
|
|
|
log.info("\tNot pulled: \(noPullMask.map(\.rawValue))")
|
|
|
|
}
|
2021-01-03 08:48:48 +00:00
|
|
|
}
|
|
|
|
}
|