2018-08-23 13:49:21 +00:00
|
|
|
//
|
|
|
|
// SessionProxy+PushReply.swift
|
|
|
|
// TunnelKit
|
|
|
|
//
|
2018-08-27 18:30:09 +00:00
|
|
|
// Created by Davide De Rosa on 7/25/18.
|
2019-03-09 10:44:18 +00:00
|
|
|
// Copyright (c) 2019 Davide De Rosa. All rights reserved.
|
2018-08-27 18:30:09 +00:00
|
|
|
//
|
|
|
|
// https://github.com/keeshux
|
|
|
|
//
|
|
|
|
// 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 13:49:21 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2018-08-24 13:27:20 +00:00
|
|
|
/// Encapsulates the IPv4 settings for the tunnel.
|
|
|
|
public struct IPv4Settings: CustomStringConvertible {
|
2018-08-24 09:57:09 +00:00
|
|
|
|
2018-08-28 15:39:23 +00:00
|
|
|
/// Represents an IPv4 route in the routing table.
|
|
|
|
public struct Route: CustomStringConvertible {
|
2018-08-24 13:27:20 +00:00
|
|
|
|
|
|
|
/// The destination host or subnet.
|
|
|
|
public let destination: String
|
|
|
|
|
|
|
|
/// The address mask.
|
|
|
|
public let mask: String
|
|
|
|
|
|
|
|
/// The address of the gateway (uses default gateway if not set).
|
|
|
|
public let gateway: String?
|
|
|
|
|
|
|
|
fileprivate init(_ destination: String, _ mask: String?, _ gateway: String?) {
|
|
|
|
self.destination = destination
|
|
|
|
self.mask = mask ?? "255.255.255.255"
|
|
|
|
self.gateway = gateway
|
|
|
|
}
|
2018-08-28 15:39:23 +00:00
|
|
|
|
|
|
|
// MARK: CustomStringConvertible
|
|
|
|
|
|
|
|
/// :nodoc:
|
|
|
|
public var description: String {
|
2018-11-05 19:38:18 +00:00
|
|
|
return "{\(destination.maskedDescription)/\(mask) \(gateway?.maskedDescription ?? "default")}"
|
2018-08-28 15:39:23 +00:00
|
|
|
}
|
2018-08-24 13:27:20 +00:00
|
|
|
}
|
2018-08-24 09:57:09 +00:00
|
|
|
|
2018-08-24 13:27:20 +00:00
|
|
|
/// The address.
|
|
|
|
let address: String
|
|
|
|
|
|
|
|
/// The address mask.
|
|
|
|
let addressMask: String
|
|
|
|
|
2018-08-24 09:57:09 +00:00
|
|
|
/// The address of the default gateway.
|
2018-08-24 13:27:20 +00:00
|
|
|
let defaultGateway: String
|
2018-08-24 09:45:41 +00:00
|
|
|
|
|
|
|
/// The additional routes.
|
2018-08-24 13:27:20 +00:00
|
|
|
let routes: [Route]
|
2018-08-24 09:57:09 +00:00
|
|
|
|
2018-08-24 13:27:20 +00:00
|
|
|
// MARK: CustomStringConvertible
|
|
|
|
|
|
|
|
/// :nodoc:
|
|
|
|
public var description: String {
|
2018-11-05 19:38:18 +00:00
|
|
|
return "addr \(address.maskedDescription) netmask \(addressMask) gw \(defaultGateway.maskedDescription) routes \(routes.map { $0.maskedDescription })"
|
2018-08-24 13:27:20 +00:00
|
|
|
}
|
2018-08-24 09:57:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 13:27:20 +00:00
|
|
|
/// Encapsulates the IPv6 settings for the tunnel.
|
|
|
|
public struct IPv6Settings: CustomStringConvertible {
|
2018-08-24 09:57:09 +00:00
|
|
|
|
2018-08-28 15:39:23 +00:00
|
|
|
/// Represents an IPv6 route in the routing table.
|
|
|
|
public struct Route: CustomStringConvertible {
|
|
|
|
|
2018-08-24 09:45:41 +00:00
|
|
|
/// The destination host or subnet.
|
|
|
|
public let destination: String
|
|
|
|
|
2018-08-24 13:27:20 +00:00
|
|
|
/// The address prefix length.
|
|
|
|
public let prefixLength: UInt8
|
2018-08-24 09:45:41 +00:00
|
|
|
|
|
|
|
/// The address of the gateway (uses default gateway if not set).
|
|
|
|
public let gateway: String?
|
|
|
|
|
2018-08-24 13:27:20 +00:00
|
|
|
fileprivate init(_ destination: String, _ prefixLength: UInt8?, _ gateway: String?) {
|
2018-08-24 09:45:41 +00:00
|
|
|
self.destination = destination
|
2018-08-24 13:27:20 +00:00
|
|
|
self.prefixLength = prefixLength ?? 3
|
2018-08-24 09:45:41 +00:00
|
|
|
self.gateway = gateway
|
|
|
|
}
|
2018-08-28 15:39:23 +00:00
|
|
|
|
|
|
|
// MARK: CustomStringConvertible
|
|
|
|
|
|
|
|
/// :nodoc:
|
|
|
|
public var description: String {
|
2018-11-05 19:38:18 +00:00
|
|
|
return "{\(destination.maskedDescription)/\(prefixLength) \(gateway?.maskedDescription ?? "default")}"
|
2018-08-28 15:39:23 +00:00
|
|
|
}
|
2018-08-24 09:45:41 +00:00
|
|
|
}
|
2018-08-24 13:27:20 +00:00
|
|
|
|
|
|
|
/// The address.
|
|
|
|
public let address: String
|
|
|
|
|
|
|
|
/// The address prefix length.
|
|
|
|
public let addressPrefixLength: UInt8
|
|
|
|
|
|
|
|
/// The address of the default gateway.
|
|
|
|
public let defaultGateway: String
|
|
|
|
|
|
|
|
/// The additional routes.
|
|
|
|
public let routes: [Route]
|
|
|
|
|
|
|
|
// MARK: CustomStringConvertible
|
|
|
|
|
|
|
|
/// :nodoc:
|
|
|
|
public var description: String {
|
2018-11-05 19:38:18 +00:00
|
|
|
return "addr \(address.maskedDescription)/\(addressPrefixLength) gw \(defaultGateway.maskedDescription) routes \(routes.map { $0.maskedDescription })"
|
2018-08-24 13:27:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Groups the parsed reply of a successfully started session.
|
|
|
|
public protocol SessionReply {
|
|
|
|
|
|
|
|
/// The IPv4 settings.
|
|
|
|
var ipv4: IPv4Settings? { get }
|
|
|
|
|
|
|
|
/// The IPv6 settings.
|
|
|
|
var ipv6: IPv6Settings? { get }
|
|
|
|
|
|
|
|
/// The DNS servers set up for this session.
|
|
|
|
var dnsServers: [String] { get }
|
2018-09-01 23:25:27 +00:00
|
|
|
|
2018-09-07 13:07:47 +00:00
|
|
|
/// The optional compression framing.
|
|
|
|
var compressionFraming: SessionProxy.CompressionFraming? { get }
|
|
|
|
|
2019-03-19 11:04:42 +00:00
|
|
|
/// The optional compression algorithm.
|
|
|
|
var compressionAlgorithm: SessionProxy.CompressionAlgorithm? { get }
|
2019-02-23 18:54:38 +00:00
|
|
|
|
2018-09-08 18:28:53 +00:00
|
|
|
/// The optional keep-alive interval.
|
|
|
|
var ping: Int? { get }
|
|
|
|
|
2018-09-01 23:30:19 +00:00
|
|
|
/// The optional authentication token.
|
|
|
|
var authToken: String? { get }
|
|
|
|
|
2018-09-01 23:25:27 +00:00
|
|
|
/// The optional 24-bit peer-id.
|
|
|
|
var peerId: UInt32? { get }
|
|
|
|
|
|
|
|
/// The negotiated cipher if any (NCP).
|
|
|
|
var cipher: SessionProxy.Cipher? { get }
|
2018-08-24 13:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension SessionProxy {
|
|
|
|
|
|
|
|
// XXX: parsing is very optimistic
|
2018-08-24 09:45:41 +00:00
|
|
|
|
2018-09-02 10:33:47 +00:00
|
|
|
struct PushReply: SessionReply, CustomStringConvertible {
|
2018-08-24 09:45:41 +00:00
|
|
|
private enum Topology: String {
|
|
|
|
case net30
|
|
|
|
|
|
|
|
case p2p
|
|
|
|
|
|
|
|
case subnet
|
|
|
|
}
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
private struct Regex {
|
|
|
|
static let prefix = "PUSH_REPLY,"
|
|
|
|
|
|
|
|
static let topology = NSRegularExpression("topology (net30|p2p|subnet)")
|
|
|
|
|
|
|
|
static let ifconfig = NSRegularExpression("ifconfig [\\d\\.]+ [\\d\\.]+")
|
|
|
|
|
|
|
|
static let ifconfig6 = NSRegularExpression("ifconfig-ipv6 [\\da-fA-F:]+/\\d+ [\\da-fA-F:]+")
|
|
|
|
|
|
|
|
static let gateway = NSRegularExpression("route-gateway [\\d\\.]+")
|
|
|
|
|
|
|
|
static let route = NSRegularExpression("route [\\d\\.]+( [\\d\\.]+){0,2}")
|
|
|
|
|
|
|
|
static let route6 = NSRegularExpression("route-ipv6 [\\da-fA-F:]+/\\d+( [\\da-fA-F:]+){0,2}")
|
|
|
|
|
|
|
|
static let dns = NSRegularExpression("dhcp-option DNS6? [\\d\\.a-fA-F:]+")
|
|
|
|
|
2019-02-23 18:54:38 +00:00
|
|
|
static let comp = NSRegularExpression("comp(ress|-lzo)[ \\w]*")
|
2019-02-23 18:13:53 +00:00
|
|
|
|
|
|
|
static let ping = NSRegularExpression("ping \\d+")
|
|
|
|
|
|
|
|
static let authToken = NSRegularExpression("auth-token [a-zA-Z0-9/=+]+")
|
|
|
|
|
|
|
|
static let peerId = NSRegularExpression("peer-id [0-9]+")
|
|
|
|
|
|
|
|
static let cipher = NSRegularExpression("cipher [^,\\s]+")
|
|
|
|
}
|
2018-09-07 13:07:47 +00:00
|
|
|
|
2018-09-02 10:33:47 +00:00
|
|
|
private let original: String
|
2018-09-01 23:25:27 +00:00
|
|
|
|
2018-08-24 13:27:20 +00:00
|
|
|
let ipv4: IPv4Settings?
|
|
|
|
|
|
|
|
let ipv6: IPv6Settings?
|
2018-08-23 13:49:21 +00:00
|
|
|
|
|
|
|
let dnsServers: [String]
|
|
|
|
|
2018-09-07 13:07:47 +00:00
|
|
|
let compressionFraming: SessionProxy.CompressionFraming?
|
|
|
|
|
2019-03-19 11:04:42 +00:00
|
|
|
let compressionAlgorithm: SessionProxy.CompressionAlgorithm?
|
2019-02-23 18:54:38 +00:00
|
|
|
|
2018-09-08 18:28:53 +00:00
|
|
|
let ping: Int?
|
|
|
|
|
2018-08-23 13:49:21 +00:00
|
|
|
let authToken: String?
|
|
|
|
|
|
|
|
let peerId: UInt32?
|
|
|
|
|
2018-09-01 23:25:27 +00:00
|
|
|
let cipher: SessionProxy.Cipher?
|
|
|
|
|
2018-08-23 13:49:21 +00:00
|
|
|
init?(message: String) throws {
|
2019-02-23 18:13:53 +00:00
|
|
|
guard message.hasPrefix(Regex.prefix) else {
|
2018-08-23 13:49:21 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-02-23 18:13:53 +00:00
|
|
|
let prefixOffset = message.index(message.startIndex, offsetBy: Regex.prefix.count)
|
2018-09-02 10:33:47 +00:00
|
|
|
original = String(message[prefixOffset..<message.endIndex])
|
|
|
|
|
2018-09-01 23:07:45 +00:00
|
|
|
var optTopologyArguments: [String]?
|
|
|
|
var optIfconfig4Arguments: [String]?
|
|
|
|
var optGateway4Arguments: [String]?
|
2018-08-24 13:27:20 +00:00
|
|
|
let address4: String
|
|
|
|
let addressMask4: String
|
|
|
|
let defaultGateway4: String
|
|
|
|
var routes4: [IPv4Settings.Route] = []
|
|
|
|
|
2018-09-01 23:07:45 +00:00
|
|
|
var optIfconfig6Arguments: [String]?
|
2018-08-24 09:45:41 +00:00
|
|
|
|
|
|
|
var dnsServers: [String] = []
|
2018-09-07 13:07:47 +00:00
|
|
|
var compressionFraming: SessionProxy.CompressionFraming?
|
2019-03-19 11:04:42 +00:00
|
|
|
var compressionAlgorithm: SessionProxy.CompressionAlgorithm?
|
2018-09-08 18:28:53 +00:00
|
|
|
var ping: Int?
|
2018-08-23 13:49:21 +00:00
|
|
|
var authToken: String?
|
|
|
|
var peerId: UInt32?
|
2018-09-01 23:25:27 +00:00
|
|
|
var cipher: SessionProxy.Cipher?
|
2018-08-24 09:45:41 +00:00
|
|
|
|
2018-08-24 13:27:20 +00:00
|
|
|
// MARK: Routing (IPv4)
|
2018-08-24 09:45:41 +00:00
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.topology.enumerateArguments(in: message) {
|
2018-09-01 23:07:45 +00:00
|
|
|
optTopologyArguments = $0
|
2018-08-24 09:45:41 +00:00
|
|
|
}
|
2018-09-01 23:07:45 +00:00
|
|
|
guard let topologyArguments = optTopologyArguments, topologyArguments.count == 1 else {
|
2018-08-24 09:45:41 +00:00
|
|
|
throw SessionError.malformedPushReply
|
|
|
|
}
|
|
|
|
|
|
|
|
// assumes "topology" to be always pushed to clients, even when not explicitly set (defaults to net30)
|
2018-09-01 23:07:45 +00:00
|
|
|
guard let topology = Topology(rawValue: topologyArguments[0]) else {
|
|
|
|
fatalError("Bad topology regexp, accepted unrecognized value: \(topologyArguments[0])")
|
2018-08-24 09:45:41 +00:00
|
|
|
}
|
2018-08-23 13:49:21 +00:00
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.ifconfig.enumerateArguments(in: message) {
|
2018-09-01 23:07:45 +00:00
|
|
|
optIfconfig4Arguments = $0
|
2018-08-23 13:49:21 +00:00
|
|
|
}
|
2018-09-01 23:07:45 +00:00
|
|
|
guard let ifconfig4Arguments = optIfconfig4Arguments, ifconfig4Arguments.count == 2 else {
|
2018-08-23 13:49:21 +00:00
|
|
|
throw SessionError.malformedPushReply
|
|
|
|
}
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.gateway.enumerateArguments(in: message) {
|
2018-09-01 23:07:45 +00:00
|
|
|
optGateway4Arguments = $0
|
2018-08-24 09:45:41 +00:00
|
|
|
}
|
2018-08-24 13:27:20 +00:00
|
|
|
|
2018-08-24 09:45:41 +00:00
|
|
|
//
|
|
|
|
// excerpts from OpenVPN manpage
|
|
|
|
//
|
|
|
|
// "--ifconfig l rn":
|
|
|
|
//
|
|
|
|
// Set TUN/TAP adapter parameters. l is the IP address of the local VPN endpoint. For TUN devices in point-to-point mode, rn is the IP address of
|
|
|
|
// the remote VPN endpoint. For TAP devices, or TUN devices used with --topology subnet, rn is the subnet mask of the virtual network segment which
|
|
|
|
// is being created or connected to.
|
|
|
|
//
|
|
|
|
// "--topology mode":
|
|
|
|
//
|
|
|
|
// Note: Using --topology subnet changes the interpretation of the arguments of --ifconfig to mean "address netmask", no longer "local remote".
|
|
|
|
//
|
|
|
|
switch topology {
|
|
|
|
case .subnet:
|
2018-08-24 13:27:20 +00:00
|
|
|
|
2018-08-24 09:45:41 +00:00
|
|
|
// default gateway required when topology is subnet
|
2018-09-01 23:07:45 +00:00
|
|
|
guard let gateway4Arguments = optGateway4Arguments, gateway4Arguments.count == 1 else {
|
2018-08-24 09:45:41 +00:00
|
|
|
throw SessionError.malformedPushReply
|
|
|
|
}
|
2018-09-01 23:07:45 +00:00
|
|
|
address4 = ifconfig4Arguments[0]
|
|
|
|
addressMask4 = ifconfig4Arguments[1]
|
|
|
|
defaultGateway4 = gateway4Arguments[0]
|
2018-08-24 09:45:41 +00:00
|
|
|
|
|
|
|
default:
|
2018-09-01 23:07:45 +00:00
|
|
|
address4 = ifconfig4Arguments[0]
|
2018-08-24 13:27:20 +00:00
|
|
|
addressMask4 = "255.255.255.255"
|
2018-09-01 23:07:45 +00:00
|
|
|
defaultGateway4 = ifconfig4Arguments[1]
|
2018-08-24 09:45:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.route.enumerateArguments(in: message) {
|
2018-09-01 23:07:45 +00:00
|
|
|
let routeEntryArguments = $0
|
2018-08-24 13:27:20 +00:00
|
|
|
|
2018-09-01 23:07:45 +00:00
|
|
|
let address = routeEntryArguments[0]
|
2018-08-24 09:45:41 +00:00
|
|
|
let mask: String?
|
|
|
|
let gateway: String?
|
2018-09-01 23:07:45 +00:00
|
|
|
if routeEntryArguments.count > 1 {
|
|
|
|
mask = routeEntryArguments[1]
|
2018-08-24 09:45:41 +00:00
|
|
|
} else {
|
|
|
|
mask = nil
|
|
|
|
}
|
2018-09-01 23:07:45 +00:00
|
|
|
if routeEntryArguments.count > 2 {
|
|
|
|
gateway = routeEntryArguments[2]
|
2018-08-24 09:45:41 +00:00
|
|
|
} else {
|
2018-08-24 13:27:20 +00:00
|
|
|
gateway = defaultGateway4
|
2018-08-24 09:45:41 +00:00
|
|
|
}
|
2018-08-24 13:27:20 +00:00
|
|
|
routes4.append(IPv4Settings.Route(address, mask, gateway))
|
|
|
|
}
|
|
|
|
|
|
|
|
ipv4 = IPv4Settings(
|
|
|
|
address: address4,
|
|
|
|
addressMask: addressMask4,
|
|
|
|
defaultGateway: defaultGateway4,
|
|
|
|
routes: routes4
|
|
|
|
)
|
|
|
|
|
|
|
|
// MARK: Routing (IPv6)
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.ifconfig6.enumerateArguments(in: message) {
|
2018-09-01 23:07:45 +00:00
|
|
|
optIfconfig6Arguments = $0
|
2018-08-24 13:27:20 +00:00
|
|
|
}
|
2018-09-01 23:07:45 +00:00
|
|
|
if let ifconfig6Arguments = optIfconfig6Arguments, ifconfig6Arguments.count == 2 {
|
|
|
|
let address6Components = ifconfig6Arguments[0].components(separatedBy: "/")
|
2018-08-24 13:27:20 +00:00
|
|
|
guard address6Components.count == 2 else {
|
|
|
|
throw SessionError.malformedPushReply
|
|
|
|
}
|
|
|
|
guard let addressPrefix6 = UInt8(address6Components[1]) else {
|
|
|
|
throw SessionError.malformedPushReply
|
|
|
|
}
|
|
|
|
let address6 = address6Components[0]
|
2018-09-01 23:07:45 +00:00
|
|
|
let defaultGateway6 = ifconfig6Arguments[1]
|
2018-08-24 13:27:20 +00:00
|
|
|
|
|
|
|
var routes6: [IPv6Settings.Route] = []
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.route6.enumerateArguments(in: message) {
|
2018-09-01 23:07:45 +00:00
|
|
|
let routeEntryArguments = $0
|
2018-08-24 13:27:20 +00:00
|
|
|
|
2018-09-01 23:07:45 +00:00
|
|
|
let destinationComponents = routeEntryArguments[0].components(separatedBy: "/")
|
2018-08-24 13:27:20 +00:00
|
|
|
guard destinationComponents.count == 2 else {
|
|
|
|
// throw SessionError.malformedPushReply
|
|
|
|
return
|
|
|
|
}
|
|
|
|
guard let prefix = UInt8(destinationComponents[1]) else {
|
|
|
|
// throw SessionError.malformedPushReply
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let destination = destinationComponents[0]
|
|
|
|
let gateway: String?
|
2018-09-01 23:07:45 +00:00
|
|
|
if routeEntryArguments.count > 1 {
|
|
|
|
gateway = routeEntryArguments[1]
|
2018-08-24 13:27:20 +00:00
|
|
|
} else {
|
|
|
|
gateway = defaultGateway6
|
|
|
|
}
|
|
|
|
routes6.append(IPv6Settings.Route(destination, prefix, gateway))
|
|
|
|
}
|
|
|
|
|
|
|
|
ipv6 = IPv6Settings(
|
|
|
|
address: address6,
|
|
|
|
addressPrefixLength: addressPrefix6,
|
|
|
|
defaultGateway: defaultGateway6,
|
|
|
|
routes: routes6
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
ipv6 = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: DNS
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.dns.enumerateArguments(in: message) {
|
2018-09-01 23:07:45 +00:00
|
|
|
dnsServers.append($0[1])
|
2018-08-24 09:45:41 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 13:07:47 +00:00
|
|
|
// MARK: Compression
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.comp.enumerateComponents(in: message) {
|
2018-09-07 13:07:47 +00:00
|
|
|
switch $0[0] {
|
|
|
|
case "comp-lzo":
|
|
|
|
compressionFraming = .compLZO
|
2019-03-19 11:04:42 +00:00
|
|
|
if !(($0.count == 2) && ($0[1] == "no")) {
|
|
|
|
compressionAlgorithm = .LZO
|
|
|
|
} else {
|
|
|
|
compressionAlgorithm = .disabled
|
|
|
|
}
|
2018-09-07 13:07:47 +00:00
|
|
|
|
|
|
|
case "compress":
|
|
|
|
compressionFraming = .compress
|
2019-03-19 11:04:42 +00:00
|
|
|
if $0.count > 1 {
|
|
|
|
compressionAlgorithm = .other
|
|
|
|
} else {
|
|
|
|
compressionAlgorithm = .disabled
|
|
|
|
}
|
2019-02-23 18:54:38 +00:00
|
|
|
|
2018-09-07 13:07:47 +00:00
|
|
|
default:
|
2018-09-07 13:22:03 +00:00
|
|
|
break
|
2018-09-07 13:07:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-08 18:28:53 +00:00
|
|
|
// MARK: Keep-alive
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.ping.enumerateArguments(in: message) {
|
2018-09-08 18:28:53 +00:00
|
|
|
ping = Int($0[0])
|
|
|
|
}
|
|
|
|
|
2018-08-24 09:45:41 +00:00
|
|
|
// MARK: Authentication
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.authToken.enumerateArguments(in: message) {
|
2018-09-01 23:07:45 +00:00
|
|
|
authToken = $0[0]
|
2018-08-23 13:49:21 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.peerId.enumerateArguments(in: message) {
|
2018-09-01 23:07:45 +00:00
|
|
|
peerId = UInt32($0[0])
|
2018-08-23 13:49:21 +00:00
|
|
|
}
|
2018-09-01 23:25:27 +00:00
|
|
|
|
|
|
|
// MARK: NCP
|
|
|
|
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.cipher.enumerateArguments(in: message) {
|
2018-09-01 23:25:27 +00:00
|
|
|
cipher = SessionProxy.Cipher(rawValue: $0[0].uppercased())
|
|
|
|
}
|
2018-08-23 13:49:21 +00:00
|
|
|
|
|
|
|
self.dnsServers = dnsServers
|
2018-09-07 13:07:47 +00:00
|
|
|
self.compressionFraming = compressionFraming
|
2019-03-19 11:04:42 +00:00
|
|
|
self.compressionAlgorithm = compressionAlgorithm
|
2018-09-08 18:28:53 +00:00
|
|
|
self.ping = ping
|
2018-08-23 13:49:21 +00:00
|
|
|
self.authToken = authToken
|
|
|
|
self.peerId = peerId
|
2018-09-01 23:25:27 +00:00
|
|
|
self.cipher = cipher
|
2018-08-23 13:49:21 +00:00
|
|
|
}
|
2018-09-02 10:33:47 +00:00
|
|
|
|
|
|
|
// MARK: CustomStringConvertible
|
|
|
|
|
|
|
|
var description: String {
|
|
|
|
let stripped = NSMutableString(string: original)
|
2019-02-23 18:13:53 +00:00
|
|
|
Regex.authToken.replaceMatches(
|
2018-09-02 10:33:47 +00:00
|
|
|
in: stripped,
|
|
|
|
options: [],
|
|
|
|
range: NSMakeRange(0, stripped.length),
|
|
|
|
withTemplate: "auth-token"
|
|
|
|
)
|
|
|
|
return stripped as String
|
|
|
|
}
|
2018-08-23 13:49:21 +00:00
|
|
|
}
|
|
|
|
}
|