diff --git a/.jazzy.yaml b/.jazzy.yaml index 3995fec..bdc483a 100644 --- a/.jazzy.yaml +++ b/.jazzy.yaml @@ -1,7 +1,7 @@ clean: module: "TunnelKit" author: "Davide De Rosa" -author_url: "https://github.com/keeshux/TunnelKit" +author_url: "https://github.com/passepartoutvpn/tunnelkit" theme: fullwidth @@ -14,22 +14,25 @@ xcodebuild_arguments: custom_categories: - name: Core children: - - IOInterface - - LinkInterface - - TunnelInterface - BidirectionalState - - StaticKey - - SessionProxy - - SessionProxyDelegate - ConfigurationError - - SessionReply + - EndpointProtocol + - IOInterface - IPv4Settings - IPv6Settings - - SessionError + - LinkInterface + - Proxy + - TunnelInterface - SocketType - - EndpointProtocol + - name: OpenVPN + children: - ConfigurationParser + - CryptoContainer + - SessionError + - SessionProxy + - SessionProxyDelegate + - SessionReply + - StaticKey - name: AppExtension children: - - CryptoContainer - TunnelKitProvider diff --git a/TunnelKit.xcodeproj/project.pbxproj b/TunnelKit.xcodeproj/project.pbxproj index c3d2dda..4e5db07 100644 --- a/TunnelKit.xcodeproj/project.pbxproj +++ b/TunnelKit.xcodeproj/project.pbxproj @@ -181,6 +181,12 @@ 0ECEB11C2252CDAD00E9E551 /* tunnelbear.crt in Resources */ = {isa = PBXBuildFile; fileRef = 0ECEB11A2252CDAD00E9E551 /* tunnelbear.crt */; }; 0ED9C8642138139000621BA3 /* SessionProxy+CompressionFraming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */; }; 0ED9C8652138139000621BA3 /* SessionProxy+CompressionFraming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */; }; + 0EE2F96E2291636B00F56F49 /* IPv4Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F96D2291636B00F56F49 /* IPv4Settings.swift */; }; + 0EE2F96F2291636B00F56F49 /* IPv4Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F96D2291636B00F56F49 /* IPv4Settings.swift */; }; + 0EE2F9712291638600F56F49 /* IPv6Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F9702291638600F56F49 /* IPv6Settings.swift */; }; + 0EE2F9722291638600F56F49 /* IPv6Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F9702291638600F56F49 /* IPv6Settings.swift */; }; + 0EE2F974229163C900F56F49 /* Proxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F973229163C900F56F49 /* Proxy.swift */; }; + 0EE2F975229163C900F56F49 /* Proxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE2F973229163C900F56F49 /* Proxy.swift */; }; 0EE3B3E421471C3A0027AB17 /* StaticKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE3B3E321471C3A0027AB17 /* StaticKey.swift */; }; 0EE3B3E521471C3A0027AB17 /* StaticKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE3B3E321471C3A0027AB17 /* StaticKey.swift */; }; 0EE7A79820F6296F00B42E6A /* PacketMacros.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EE7A79720F6296F00B42E6A /* PacketMacros.m */; }; @@ -391,6 +397,9 @@ 0ECEB1142252C8E900E9E551 /* tunnelbear.enc.8.key */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tunnelbear.enc.8.key; sourceTree = ""; }; 0ECEB11A2252CDAD00E9E551 /* tunnelbear.crt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tunnelbear.crt; sourceTree = ""; }; 0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+CompressionFraming.swift"; sourceTree = ""; }; + 0EE2F96D2291636B00F56F49 /* IPv4Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPv4Settings.swift; sourceTree = ""; }; + 0EE2F9702291638600F56F49 /* IPv6Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPv6Settings.swift; sourceTree = ""; }; + 0EE2F973229163C900F56F49 /* Proxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Proxy.swift; sourceTree = ""; }; 0EE3B3E321471C3A0027AB17 /* StaticKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticKey.swift; sourceTree = ""; }; 0EE7A79420F61EDC00B42E6A /* PacketMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PacketMacros.h; sourceTree = ""; }; 0EE7A79720F6296F00B42E6A /* PacketMacros.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PacketMacros.m; sourceTree = ""; }; @@ -735,11 +744,14 @@ 0EFEB4362006D3C800F81029 /* Errors.h */, 0EFEB44B2006D3C800F81029 /* Errors.m */, 0EFEB4452006D3C800F81029 /* IOInterface.swift */, + 0EE2F96D2291636B00F56F49 /* IPv4Settings.swift */, + 0EE2F9702291638600F56F49 /* IPv6Settings.swift */, 0EFEB4492006D3C800F81029 /* LinkInterface.swift */, 0E58BF5522411F37006FB157 /* LZO.h */, 0E58BF5822411FEF006FB157 /* LZO.m */, 0EB03E0E2290CF52006D03A0 /* module.modulemap */, 0E12B29D21449ADB00B4BAE9 /* NSRegularExpression+Shortcuts.swift */, + 0EE2F973229163C900F56F49 /* Proxy.swift */, 0EFB902722788511006405E4 /* RoutingTable.h */, 0EFB902822788511006405E4 /* RoutingTable.m */, 0E0B203E2278A85B007A3CB9 /* RoutingTableEntry.h */, @@ -1249,6 +1261,7 @@ 0EB03E322290D22A006D03A0 /* MemoryDestination.swift in Sources */, 0E58BF4C22405C2F006FB157 /* StandardLZO.m in Sources */, 0EB03E222290D22A006D03A0 /* NETCPInterface.swift in Sources */, + 0EE2F974229163C900F56F49 /* Proxy.swift in Sources */, 0EFEB4732006D3C800F81029 /* LinkInterface.swift in Sources */, 0EFEB4652006D3C800F81029 /* SessionProxy+Authenticator.swift in Sources */, 0EE7A79820F6296F00B42E6A /* PacketMacros.m in Sources */, @@ -1268,6 +1281,7 @@ 0E12B2A821456C0200B4BAE9 /* ControlChannel.swift in Sources */, 0EFEB4552006D3C800F81029 /* SessionProxy+EncryptionBridge.swift in Sources */, 0EFEB45C2006D3C800F81029 /* ZeroingData.m in Sources */, + 0EE2F9712291638600F56F49 /* IPv6Settings.swift in Sources */, 0EFEB4632006D3C800F81029 /* ProtocolMacros.swift in Sources */, 0EFB902B22788512006405E4 /* RoutingTable.m in Sources */, 0EFEB46D2006D3C800F81029 /* Data+Manipulation.swift in Sources */, @@ -1280,6 +1294,7 @@ 0E011F882196E2AB00BA59EE /* ConfigurationParser.swift in Sources */, 0E39BCEA214B2AB60035E9DE /* ControlPacket.m in Sources */, 0EB03E3A2290D22A006D03A0 /* TunnelKitProvider+Interaction.swift in Sources */, + 0EE2F96E2291636B00F56F49 /* IPv4Settings.swift in Sources */, 0E12B2AB2145E01700B4BAE9 /* ControlChannelSerializer.swift in Sources */, 0EFEB4662006D3C800F81029 /* ZeroingData.swift in Sources */, 0EFEB4682006D3C800F81029 /* MSS.m in Sources */, @@ -1322,6 +1337,7 @@ 0EB03E332290D22A006D03A0 /* MemoryDestination.swift in Sources */, 0E58BF4D22405C2F006FB157 /* StandardLZO.m in Sources */, 0EB03E232290D22A006D03A0 /* NETCPInterface.swift in Sources */, + 0EE2F975229163C900F56F49 /* Proxy.swift in Sources */, 0EFEB4A12006D7F300F81029 /* LinkInterface.swift in Sources */, 0EE7A79920F6296F00B42E6A /* PacketMacros.m in Sources */, 0E0B20432278A85C007A3CB9 /* RoutingTableEntry.m in Sources */, @@ -1341,6 +1357,7 @@ 0EFEB4982006D7F300F81029 /* ZeroingData.swift in Sources */, 0EFEB4A32006D7F300F81029 /* Errors.m in Sources */, 0EFEB4A22006D7F300F81029 /* CoreConfiguration.swift in Sources */, + 0EE2F9722291638600F56F49 /* IPv6Settings.swift in Sources */, 0EFB902C22788512006405E4 /* RoutingTable.m in Sources */, 0EFEB4952006D7F300F81029 /* SecureRandom.swift in Sources */, 0EFEB49A2006D7F300F81029 /* MSS.m in Sources */, @@ -1353,6 +1370,7 @@ 0E011F892196E2AB00BA59EE /* ConfigurationParser.swift in Sources */, 0E39BCEB214B2AB60035E9DE /* ControlPacket.m in Sources */, 0EB03E3B2290D22A006D03A0 /* TunnelKitProvider+Interaction.swift in Sources */, + 0EE2F96F2291636B00F56F49 /* IPv4Settings.swift in Sources */, 0E12B2AC2145E01700B4BAE9 /* ControlChannelSerializer.swift in Sources */, 0E07598120F0060E00F38FD8 /* CryptoAEAD.m in Sources */, 0EFEB49C2006D7F300F81029 /* Data+Manipulation.swift in Sources */, diff --git a/TunnelKit/Sources/Core/EndpointProtocol.swift b/TunnelKit/Sources/Core/EndpointProtocol.swift index 1437113..50861c8 100644 --- a/TunnelKit/Sources/Core/EndpointProtocol.swift +++ b/TunnelKit/Sources/Core/EndpointProtocol.swift @@ -76,3 +76,19 @@ public struct EndpointProtocol: RawRepresentable, Equatable, CustomStringConvert return rawValue } } + +/// :nodoc: +extension EndpointProtocol: Codable { + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + guard let proto = try EndpointProtocol(rawValue: container.decode(String.self)) else { + throw ConfigurationError.malformed(option: "remote/proto") + } + self.init(proto.socketType, proto.port) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(rawValue) + } +} diff --git a/TunnelKit/Sources/Core/IPv4Settings.swift b/TunnelKit/Sources/Core/IPv4Settings.swift new file mode 100644 index 0000000..0b02b86 --- /dev/null +++ b/TunnelKit/Sources/Core/IPv4Settings.swift @@ -0,0 +1,75 @@ +// +// IPv4Settings.swift +// TunnelKit +// +// Created by Davide De Rosa on 5/19/19. +// Copyright (c) 2019 Davide De Rosa. All rights reserved. +// +// https://github.com/passepartoutvpn +// +// 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 . +// + +import Foundation + +/// Encapsulates the IPv4 settings for the tunnel. +public struct IPv4Settings: Codable, CustomStringConvertible { + + /// Represents an IPv4 route in the routing table. + public struct Route: Codable, CustomStringConvertible { + + /// 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 + + init(_ destination: String, _ mask: String?, _ gateway: String) { + self.destination = destination + self.mask = mask ?? "255.255.255.255" + self.gateway = gateway + } + + // MARK: CustomStringConvertible + + /// :nodoc: + public var description: String { + return "{\(destination.maskedDescription)/\(mask) \(gateway.maskedDescription)}" + } + } + + /// The address. + let address: String + + /// The address mask. + let addressMask: String + + /// The address of the default gateway. + let defaultGateway: String + + /// The additional routes. + let routes: [Route] + + // MARK: CustomStringConvertible + + /// :nodoc: + public var description: String { + return "addr \(address.maskedDescription) netmask \(addressMask) gw \(defaultGateway.maskedDescription) routes \(routes.map { $0.maskedDescription })" + } +} diff --git a/TunnelKit/Sources/Core/IPv6Settings.swift b/TunnelKit/Sources/Core/IPv6Settings.swift new file mode 100644 index 0000000..e85ad8c --- /dev/null +++ b/TunnelKit/Sources/Core/IPv6Settings.swift @@ -0,0 +1,75 @@ +// +// IPv6Settings.swift +// TunnelKit +// +// Created by Davide De Rosa on 5/19/19. +// Copyright (c) 2019 Davide De Rosa. All rights reserved. +// +// https://github.com/passepartoutvpn +// +// 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 . +// + +import Foundation + +/// Encapsulates the IPv6 settings for the tunnel. +public struct IPv6Settings: Codable, CustomStringConvertible { + + /// Represents an IPv6 route in the routing table. + public struct Route: Codable, CustomStringConvertible { + + /// The destination host or subnet. + public let destination: String + + /// The address prefix length. + public let prefixLength: UInt8 + + /// The address of the gateway (uses default gateway if not set). + public let gateway: String + + init(_ destination: String, _ prefixLength: UInt8?, _ gateway: String) { + self.destination = destination + self.prefixLength = prefixLength ?? 3 + self.gateway = gateway + } + + // MARK: CustomStringConvertible + + /// :nodoc: + public var description: String { + return "{\(destination.maskedDescription)/\(prefixLength) \(gateway.maskedDescription)}" + } + } + + /// 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 { + return "addr \(address.maskedDescription)/\(addressPrefixLength) gw \(defaultGateway.maskedDescription) routes \(routes.map { $0.maskedDescription })" + } +} diff --git a/TunnelKit/Sources/Core/Proxy.swift b/TunnelKit/Sources/Core/Proxy.swift new file mode 100644 index 0000000..5a667a9 --- /dev/null +++ b/TunnelKit/Sources/Core/Proxy.swift @@ -0,0 +1,65 @@ +// +// Proxy.swift +// TunnelKit +// +// Created by Davide De Rosa on 5/19/19. +// Copyright (c) 2019 Davide De Rosa. All rights reserved. +// +// https://github.com/passepartoutvpn +// +// 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 . +// + +import Foundation + +/// Encapsulates a proxy setting. +public struct Proxy: Codable, RawRepresentable, CustomStringConvertible { + + /// The proxy address. + public let address: String + + /// The proxy port. + public let port: UInt16 + + /// :nodoc: + public init(_ address: String, _ port: UInt16) { + self.address = address + self.port = port + } + + // MARK: RawRepresentable + + /// :nodoc: + public var rawValue: String { + return "\(address):\(port)" + } + + /// :nodoc: + public init?(rawValue: String) { + let comps = rawValue.components(separatedBy: ":") + guard comps.count == 2, let port = UInt16(comps[1]) else { + return nil + } + self.init(comps[0], port) + } + + // MARK: CustomStringConvertible + + /// :nodoc: + public var description: String { + return rawValue + } +} diff --git a/TunnelKit/Sources/OpenVPN/SessionProxy+Configuration.swift b/TunnelKit/Sources/OpenVPN/SessionProxy+Configuration.swift index 7a194df..677f726 100644 --- a/TunnelKit/Sources/OpenVPN/SessionProxy+Configuration.swift +++ b/TunnelKit/Sources/OpenVPN/SessionProxy+Configuration.swift @@ -454,156 +454,3 @@ extension SessionProxy.Configuration { return builder } } - -/// Encapsulates the IPv4 settings for the tunnel. -public struct IPv4Settings: Codable, CustomStringConvertible { - - /// Represents an IPv4 route in the routing table. - public struct Route: Codable, CustomStringConvertible { - - /// 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 - - init(_ destination: String, _ mask: String?, _ gateway: String) { - self.destination = destination - self.mask = mask ?? "255.255.255.255" - self.gateway = gateway - } - - // MARK: CustomStringConvertible - - /// :nodoc: - public var description: String { - return "{\(destination.maskedDescription)/\(mask) \(gateway.maskedDescription)}" - } - } - - /// The address. - let address: String - - /// The address mask. - let addressMask: String - - /// The address of the default gateway. - let defaultGateway: String - - /// The additional routes. - let routes: [Route] - - // MARK: CustomStringConvertible - - /// :nodoc: - public var description: String { - return "addr \(address.maskedDescription) netmask \(addressMask) gw \(defaultGateway.maskedDescription) routes \(routes.map { $0.maskedDescription })" - } -} - -/// Encapsulates the IPv6 settings for the tunnel. -public struct IPv6Settings: Codable, CustomStringConvertible { - - /// Represents an IPv6 route in the routing table. - public struct Route: Codable, CustomStringConvertible { - - /// The destination host or subnet. - public let destination: String - - /// The address prefix length. - public let prefixLength: UInt8 - - /// The address of the gateway (uses default gateway if not set). - public let gateway: String - - init(_ destination: String, _ prefixLength: UInt8?, _ gateway: String) { - self.destination = destination - self.prefixLength = prefixLength ?? 3 - self.gateway = gateway - } - - // MARK: CustomStringConvertible - - /// :nodoc: - public var description: String { - return "{\(destination.maskedDescription)/\(prefixLength) \(gateway.maskedDescription)}" - } - } - - /// 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 { - return "addr \(address.maskedDescription)/\(addressPrefixLength) gw \(defaultGateway.maskedDescription) routes \(routes.map { $0.maskedDescription })" - } -} - -/// Encapsulate a proxy setting. -public struct Proxy: Codable, RawRepresentable, CustomStringConvertible { - - /// The proxy address. - public let address: String - - /// The proxy port. - public let port: UInt16 - - /// :nodoc: - public init(_ address: String, _ port: UInt16) { - self.address = address - self.port = port - } - - // MARK: RawRepresentable - - /// :nodoc: - public var rawValue: String { - return "\(address):\(port)" - } - - /// :nodoc: - public init?(rawValue: String) { - let comps = rawValue.components(separatedBy: ":") - guard comps.count == 2, let port = UInt16(comps[1]) else { - return nil - } - self.init(comps[0], port) - } - - // MARK: CustomStringConvertible - - /// :nodoc: - public var description: String { - return rawValue - } -} - -/// :nodoc: -extension EndpointProtocol: Codable { - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - guard let proto = try EndpointProtocol(rawValue: container.decode(String.self)) else { - throw ConfigurationError.malformed(option: "remote/proto") - } - self.init(proto.socketType, proto.port) - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) - } -}