diff --git a/Demo/Demo/Configuration.swift b/Demo/Demo/Configuration.swift index 558a008..76acc76 100644 --- a/Demo/Demo/Configuration.swift +++ b/Demo/Demo/Configuration.swift @@ -169,7 +169,7 @@ M69t86apMrAxkUxVJAWLRBd9fbYyzJgTW61tFqXWTZpiz6bhuWApSEzaHcL3/f5l -----END PRIVATE KEY----- """) - static func make(hostname: String, port: UInt16, socketType: SocketType) -> OpenVPNTunnelProvider.Configuration { + static func make(hostname: String, port: UInt16, socketType: SocketType) -> OpenVPNProvider.Configuration { var sessionBuilder = OpenVPN.ConfigurationBuilder() sessionBuilder.ca = ca sessionBuilder.cipher = .aes128cbc @@ -181,7 +181,7 @@ M69t86apMrAxkUxVJAWLRBd9fbYyzJgTW61tFqXWTZpiz6bhuWApSEzaHcL3/f5l sessionBuilder.clientCertificate = clientCertificate sessionBuilder.clientKey = clientKey sessionBuilder.mtu = 1350 - var builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) + var builder = OpenVPNProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) builder.shouldDebug = true builder.masksPrivateData = false return builder.build() diff --git a/Demo/Demo/PacketTunnelProvider.swift b/Demo/Demo/PacketTunnelProvider.swift index f0c1cf0..b832279 100644 --- a/Demo/Demo/PacketTunnelProvider.swift +++ b/Demo/Demo/PacketTunnelProvider.swift @@ -23,7 +23,7 @@ // along with TunnelKit. If not, see . // -import TunnelKitOpenVPN +import TunnelKitOpenVPNAppExtension class PacketTunnelProvider: OpenVPNTunnelProvider { } diff --git a/Demo/TunnelKit.xcodeproj/project.pbxproj b/Demo/TunnelKit.xcodeproj/project.pbxproj index d329fb3..db41e02 100644 --- a/Demo/TunnelKit.xcodeproj/project.pbxproj +++ b/Demo/TunnelKit.xcodeproj/project.pbxproj @@ -29,10 +29,10 @@ 0E1108B11F77B9F900A92462 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E1108AF1F77B9F900A92462 /* Main.storyboard */; }; 0E1108B31F77B9F900A92462 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E1108B21F77B9F900A92462 /* Assets.xcassets */; }; 0E1108B61F77B9F900A92462 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E1108B41F77B9F900A92462 /* LaunchScreen.storyboard */; }; + 0E80FA5127396F5F000F5A45 /* TunnelKitOpenVPNAppExtension in Frameworks */ = {isa = PBXBuildFile; productRef = 0E80FA5027396F5F000F5A45 /* TunnelKitOpenVPNAppExtension */; }; + 0E80FA5327396F66000F5A45 /* TunnelKitOpenVPNAppExtension in Frameworks */ = {isa = PBXBuildFile; productRef = 0E80FA5227396F66000F5A45 /* TunnelKitOpenVPNAppExtension */; }; 0EFD5B312727250500C7D5FD /* TunnelKitOpenVPN in Frameworks */ = {isa = PBXBuildFile; productRef = 0EFD5B302727250500C7D5FD /* TunnelKitOpenVPN */; }; 0EFD5B332727250B00C7D5FD /* TunnelKitOpenVPN in Frameworks */ = {isa = PBXBuildFile; productRef = 0EFD5B322727250B00C7D5FD /* TunnelKitOpenVPN */; }; - 0EFD5B352727250E00C7D5FD /* TunnelKitOpenVPN in Frameworks */ = {isa = PBXBuildFile; productRef = 0EFD5B342727250E00C7D5FD /* TunnelKitOpenVPN */; }; - 0EFD5B372727251200C7D5FD /* TunnelKitOpenVPN in Frameworks */ = {isa = PBXBuildFile; productRef = 0EFD5B362727251200C7D5FD /* TunnelKitOpenVPN */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -166,8 +166,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 0EFD5B352727250E00C7D5FD /* TunnelKitOpenVPN in Frameworks */, 0E0541A125A2343500EFC5FF /* NetworkExtension.framework in Frameworks */, + 0E80FA5127396F5F000F5A45 /* TunnelKitOpenVPNAppExtension in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -183,7 +183,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 0EFD5B372727251200C7D5FD /* TunnelKitOpenVPN in Frameworks */, + 0E80FA5327396F66000F5A45 /* TunnelKitOpenVPNAppExtension in Frameworks */, 0E05427825A239C600EFC5FF /* NetworkExtension.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -343,7 +343,7 @@ ); name = "TunnelKitDemoTunnel-iOS"; packageProductDependencies = ( - 0EFD5B342727250E00C7D5FD /* TunnelKitOpenVPN */, + 0E80FA5027396F5F000F5A45 /* TunnelKitOpenVPNAppExtension */, ); productName = Tunnel; productReference = 0E05419F25A2343500EFC5FF /* TunnelKitDemoTunnel-iOS.appex */; @@ -386,7 +386,7 @@ ); name = "TunnelKitDemoTunnel-macOS"; packageProductDependencies = ( - 0EFD5B362727251200C7D5FD /* TunnelKitOpenVPN */, + 0E80FA5227396F66000F5A45 /* TunnelKitOpenVPNAppExtension */, ); productName = Tunnel; productReference = 0E05427725A239C600EFC5FF /* TunnelKitDemoTunnel-macOS.appex */; @@ -1032,6 +1032,14 @@ /* End XCConfigurationList section */ /* Begin XCSwiftPackageProductDependency section */ + 0E80FA5027396F5F000F5A45 /* TunnelKitOpenVPNAppExtension */ = { + isa = XCSwiftPackageProductDependency; + productName = TunnelKitOpenVPNAppExtension; + }; + 0E80FA5227396F66000F5A45 /* TunnelKitOpenVPNAppExtension */ = { + isa = XCSwiftPackageProductDependency; + productName = TunnelKitOpenVPNAppExtension; + }; 0EFD5B302727250500C7D5FD /* TunnelKitOpenVPN */ = { isa = XCSwiftPackageProductDependency; productName = TunnelKitOpenVPN; @@ -1040,14 +1048,6 @@ isa = XCSwiftPackageProductDependency; productName = TunnelKitOpenVPN; }; - 0EFD5B342727250E00C7D5FD /* TunnelKitOpenVPN */ = { - isa = XCSwiftPackageProductDependency; - productName = TunnelKitOpenVPN; - }; - 0EFD5B362727251200C7D5FD /* TunnelKitOpenVPN */ = { - isa = XCSwiftPackageProductDependency; - productName = TunnelKitOpenVPN; - }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 0E17D7F01F730D9F009EE129 /* Project object */; diff --git a/Package.resolved b/Package.resolved index dca1223..f46a77c 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,7 +6,7 @@ "repositoryURL": "https://github.com/keeshux/openssl-apple", "state": { "branch": null, - "revision": "1889136399ba40e4fc358cfe7fafef7170aac3f7", + "revision": "37043e7c92c9fb348d1d668b0402148c9fa9873c", "version": "1.1.112" } }, diff --git a/Package.swift b/Package.swift index 6a9ddf7..ebdbde7 100644 --- a/Package.swift +++ b/Package.swift @@ -12,11 +12,7 @@ let package = Package( // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "TunnelKit", - targets: [ - "TunnelKitCore", - "TunnelKitAppExtension", - "TunnelKitManager" - ] + targets: ["TunnelKit"] ), .library( name: "TunnelKitIKE", @@ -26,6 +22,10 @@ let package = Package( name: "TunnelKitOpenVPN", targets: ["TunnelKitOpenVPN"] ), + .library( + name: "TunnelKitOpenVPNAppExtension", + targets: ["TunnelKitOpenVPNAppExtension"] + ), .library( name: "TunnelKitLZO", targets: ["TunnelKitLZO"] @@ -40,41 +40,71 @@ let package = Package( targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "TunnelKit", + dependencies: [ + "TunnelKitCore", + "TunnelKitManager" + ] + ), .target( name: "TunnelKitCore", dependencies: [ - "_TunnelKitUtils", - "_TunnelKitCoreObjC", - "SwiftyBeaver"]), + "__TunnelKitUtils", + "CTunnelKitCore", + "SwiftyBeaver" + ]), .target( - name: "_TunnelKitCoreObjC", - dependencies: []), + name: "TunnelKitManager", + dependencies: [ + "TunnelKitCore" + ]), .target( name: "TunnelKitAppExtension", dependencies: [ "TunnelKitCore", - "SwiftyBeaver"]), - .target( - name: "TunnelKitManager", - dependencies: [ - "TunnelKitCore"]), + "SwiftyBeaver" + ]), .target( name: "TunnelKitIKE", dependencies: [ "TunnelKitCore", - "TunnelKitManager"]), + "TunnelKitManager" + ]), .target( name: "TunnelKitOpenVPN", dependencies: [ - "TunnelKitCore", - "_TunnelKitOpenVPNObjC", - "TunnelKitAppExtension", - "TunnelKitManager"]), + "TunnelKitOpenVPNCore", + "TunnelKitOpenVPNManager" + ]), + // .target( - name: "_TunnelKitOpenVPNObjC", + name: "TunnelKitOpenVPNCore", dependencies: [ - "openssl-apple", - "_TunnelKitCoreObjC"]), + "TunnelKitCore", + "CTunnelKitOpenVPNCore", + "CTunnelKitOpenVPNProtocol" // FIXME: remove dependency on TLSBox + ]), + .target( + name: "TunnelKitOpenVPNManager", + dependencies: [ + "TunnelKitManager", + "TunnelKitOpenVPNCore" + ]), + .target( + name: "TunnelKitOpenVPNProtocol", + dependencies: [ + "TunnelKitOpenVPNCore", + "CTunnelKitOpenVPNProtocol" + ]), + .target( + name: "TunnelKitOpenVPNAppExtension", + dependencies: [ + "TunnelKitAppExtension", + "TunnelKitOpenVPNCore", + "TunnelKitOpenVPNManager", + "TunnelKitOpenVPNProtocol" + ]), .target( name: "TunnelKitLZO", dependencies: [], @@ -84,9 +114,24 @@ let package = Package( "lib/README.LZO", "lib/testmini.c" ]), + // .target( - name: "_TunnelKitUtils", + name: "CTunnelKitCore", dependencies: []), + .target( + name: "CTunnelKitOpenVPNCore", + dependencies: []), + .target( + name: "CTunnelKitOpenVPNProtocol", + dependencies: [ + "CTunnelKitCore", + "CTunnelKitOpenVPNCore", + "openssl-apple" + ]), + .target( + name: "__TunnelKitUtils", + dependencies: []), + // .testTarget( name: "TunnelKitCoreTests", dependencies: [ @@ -95,7 +140,8 @@ let package = Package( .testTarget( name: "TunnelKitOpenVPNTests", dependencies: [ - "TunnelKitOpenVPN", + "TunnelKitOpenVPNCore", + "TunnelKitOpenVPNAppExtension", "TunnelKitLZO" ], resources: [ diff --git a/Sources/_TunnelKitCoreObjC/Allocation.m b/Sources/CTunnelKitCore/Allocation.m similarity index 100% rename from Sources/_TunnelKitCoreObjC/Allocation.m rename to Sources/CTunnelKitCore/Allocation.m diff --git a/Sources/_TunnelKitCoreObjC/Errors.m b/Sources/CTunnelKitCore/Errors.m similarity index 100% rename from Sources/_TunnelKitCoreObjC/Errors.m rename to Sources/CTunnelKitCore/Errors.m diff --git a/Sources/_TunnelKitCoreObjC/LZOFactory.m b/Sources/CTunnelKitCore/LZOFactory.m similarity index 100% rename from Sources/_TunnelKitCoreObjC/LZOFactory.m rename to Sources/CTunnelKitCore/LZOFactory.m diff --git a/Sources/_TunnelKitCoreObjC/RoutingTable.m b/Sources/CTunnelKitCore/RoutingTable.m similarity index 100% rename from Sources/_TunnelKitCoreObjC/RoutingTable.m rename to Sources/CTunnelKitCore/RoutingTable.m diff --git a/Sources/_TunnelKitCoreObjC/RoutingTableEntry.m b/Sources/CTunnelKitCore/RoutingTableEntry.m similarity index 100% rename from Sources/_TunnelKitCoreObjC/RoutingTableEntry.m rename to Sources/CTunnelKitCore/RoutingTableEntry.m diff --git a/Sources/_TunnelKitCoreObjC/ZeroingData.m b/Sources/CTunnelKitCore/ZeroingData.m similarity index 100% rename from Sources/_TunnelKitCoreObjC/ZeroingData.m rename to Sources/CTunnelKitCore/ZeroingData.m diff --git a/Sources/_TunnelKitCoreObjC/include/Allocation.h b/Sources/CTunnelKitCore/include/Allocation.h similarity index 100% rename from Sources/_TunnelKitCoreObjC/include/Allocation.h rename to Sources/CTunnelKitCore/include/Allocation.h diff --git a/Sources/_TunnelKitCoreObjC/include/CompressionProvider.h b/Sources/CTunnelKitCore/include/CompressionProvider.h similarity index 100% rename from Sources/_TunnelKitCoreObjC/include/CompressionProvider.h rename to Sources/CTunnelKitCore/include/CompressionProvider.h diff --git a/Sources/_TunnelKitCoreObjC/include/Errors.h b/Sources/CTunnelKitCore/include/Errors.h similarity index 100% rename from Sources/_TunnelKitCoreObjC/include/Errors.h rename to Sources/CTunnelKitCore/include/Errors.h diff --git a/Sources/_TunnelKitCoreObjC/include/LZOFactory.h b/Sources/CTunnelKitCore/include/LZOFactory.h similarity index 100% rename from Sources/_TunnelKitCoreObjC/include/LZOFactory.h rename to Sources/CTunnelKitCore/include/LZOFactory.h diff --git a/Sources/_TunnelKitCoreObjC/include/RoutingTable.h b/Sources/CTunnelKitCore/include/RoutingTable.h similarity index 100% rename from Sources/_TunnelKitCoreObjC/include/RoutingTable.h rename to Sources/CTunnelKitCore/include/RoutingTable.h diff --git a/Sources/_TunnelKitCoreObjC/include/RoutingTableEntry.h b/Sources/CTunnelKitCore/include/RoutingTableEntry.h similarity index 100% rename from Sources/_TunnelKitCoreObjC/include/RoutingTableEntry.h rename to Sources/CTunnelKitCore/include/RoutingTableEntry.h diff --git a/Sources/_TunnelKitCoreObjC/include/ZeroingData.h b/Sources/CTunnelKitCore/include/ZeroingData.h similarity index 100% rename from Sources/_TunnelKitCoreObjC/include/ZeroingData.h rename to Sources/CTunnelKitCore/include/ZeroingData.h diff --git a/Sources/_TunnelKitCoreObjC/include/route.h b/Sources/CTunnelKitCore/include/route.h similarity index 100% rename from Sources/_TunnelKitCoreObjC/include/route.h rename to Sources/CTunnelKitCore/include/route.h diff --git a/Sources/CTunnelKitOpenVPNCore/Dummy.m b/Sources/CTunnelKitOpenVPNCore/Dummy.m new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Sources/CTunnelKitOpenVPNCore/Dummy.m @@ -0,0 +1 @@ + diff --git a/Sources/_TunnelKitOpenVPNObjC/include/CompressionAlgorithmNative.h b/Sources/CTunnelKitOpenVPNCore/include/CompressionAlgorithmNative.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/CompressionAlgorithmNative.h rename to Sources/CTunnelKitOpenVPNCore/include/CompressionAlgorithmNative.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/CompressionFramingNative.h b/Sources/CTunnelKitOpenVPNCore/include/CompressionFramingNative.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/CompressionFramingNative.h rename to Sources/CTunnelKitOpenVPNCore/include/CompressionFramingNative.h diff --git a/Sources/_TunnelKitOpenVPNObjC/ControlPacket.m b/Sources/CTunnelKitOpenVPNProtocol/ControlPacket.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/ControlPacket.m rename to Sources/CTunnelKitOpenVPNProtocol/ControlPacket.m diff --git a/Sources/_TunnelKitOpenVPNObjC/CryptoAEAD.m b/Sources/CTunnelKitOpenVPNProtocol/CryptoAEAD.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/CryptoAEAD.m rename to Sources/CTunnelKitOpenVPNProtocol/CryptoAEAD.m diff --git a/Sources/_TunnelKitOpenVPNObjC/CryptoBox.m b/Sources/CTunnelKitOpenVPNProtocol/CryptoBox.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/CryptoBox.m rename to Sources/CTunnelKitOpenVPNProtocol/CryptoBox.m diff --git a/Sources/_TunnelKitOpenVPNObjC/CryptoCBC.m b/Sources/CTunnelKitOpenVPNProtocol/CryptoCBC.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/CryptoCBC.m rename to Sources/CTunnelKitOpenVPNProtocol/CryptoCBC.m diff --git a/Sources/_TunnelKitOpenVPNObjC/CryptoCTR.m b/Sources/CTunnelKitOpenVPNProtocol/CryptoCTR.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/CryptoCTR.m rename to Sources/CTunnelKitOpenVPNProtocol/CryptoCTR.m diff --git a/Sources/_TunnelKitOpenVPNObjC/DataPath.m b/Sources/CTunnelKitOpenVPNProtocol/DataPath.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/DataPath.m rename to Sources/CTunnelKitOpenVPNProtocol/DataPath.m diff --git a/Sources/_TunnelKitOpenVPNObjC/MSS.m b/Sources/CTunnelKitOpenVPNProtocol/MSS.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/MSS.m rename to Sources/CTunnelKitOpenVPNProtocol/MSS.m diff --git a/Sources/_TunnelKitOpenVPNObjC/PacketMacros.m b/Sources/CTunnelKitOpenVPNProtocol/PacketMacros.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/PacketMacros.m rename to Sources/CTunnelKitOpenVPNProtocol/PacketMacros.m diff --git a/Sources/_TunnelKitOpenVPNObjC/PacketStream.m b/Sources/CTunnelKitOpenVPNProtocol/PacketStream.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/PacketStream.m rename to Sources/CTunnelKitOpenVPNProtocol/PacketStream.m diff --git a/Sources/_TunnelKitOpenVPNObjC/ReplayProtector.m b/Sources/CTunnelKitOpenVPNProtocol/ReplayProtector.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/ReplayProtector.m rename to Sources/CTunnelKitOpenVPNProtocol/ReplayProtector.m diff --git a/Sources/_TunnelKitOpenVPNObjC/TLSBox.m b/Sources/CTunnelKitOpenVPNProtocol/TLSBox.m similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/TLSBox.m rename to Sources/CTunnelKitOpenVPNProtocol/TLSBox.m diff --git a/Sources/_TunnelKitOpenVPNObjC/include/ControlPacket.h b/Sources/CTunnelKitOpenVPNProtocol/include/ControlPacket.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/ControlPacket.h rename to Sources/CTunnelKitOpenVPNProtocol/include/ControlPacket.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/Crypto.h b/Sources/CTunnelKitOpenVPNProtocol/include/Crypto.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/Crypto.h rename to Sources/CTunnelKitOpenVPNProtocol/include/Crypto.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/CryptoAEAD.h b/Sources/CTunnelKitOpenVPNProtocol/include/CryptoAEAD.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/CryptoAEAD.h rename to Sources/CTunnelKitOpenVPNProtocol/include/CryptoAEAD.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/CryptoBox.h b/Sources/CTunnelKitOpenVPNProtocol/include/CryptoBox.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/CryptoBox.h rename to Sources/CTunnelKitOpenVPNProtocol/include/CryptoBox.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/CryptoCBC.h b/Sources/CTunnelKitOpenVPNProtocol/include/CryptoCBC.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/CryptoCBC.h rename to Sources/CTunnelKitOpenVPNProtocol/include/CryptoCBC.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/CryptoCTR.h b/Sources/CTunnelKitOpenVPNProtocol/include/CryptoCTR.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/CryptoCTR.h rename to Sources/CTunnelKitOpenVPNProtocol/include/CryptoCTR.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/CryptoMacros.h b/Sources/CTunnelKitOpenVPNProtocol/include/CryptoMacros.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/CryptoMacros.h rename to Sources/CTunnelKitOpenVPNProtocol/include/CryptoMacros.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/DataPath.h b/Sources/CTunnelKitOpenVPNProtocol/include/DataPath.h similarity index 97% rename from Sources/_TunnelKitOpenVPNObjC/include/DataPath.h rename to Sources/CTunnelKitOpenVPNProtocol/include/DataPath.h index e6a5dd8..560b5dc 100644 --- a/Sources/_TunnelKitOpenVPNObjC/include/DataPath.h +++ b/Sources/CTunnelKitOpenVPNProtocol/include/DataPath.h @@ -36,8 +36,7 @@ #import -#import "CompressionFramingNative.h" -#import "CompressionAlgorithmNative.h" +@import CTunnelKitOpenVPNCore; NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/_TunnelKitOpenVPNObjC/include/DataPathCrypto.h b/Sources/CTunnelKitOpenVPNProtocol/include/DataPathCrypto.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/DataPathCrypto.h rename to Sources/CTunnelKitOpenVPNProtocol/include/DataPathCrypto.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/MSS.h b/Sources/CTunnelKitOpenVPNProtocol/include/MSS.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/MSS.h rename to Sources/CTunnelKitOpenVPNProtocol/include/MSS.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/PacketMacros.h b/Sources/CTunnelKitOpenVPNProtocol/include/PacketMacros.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/PacketMacros.h rename to Sources/CTunnelKitOpenVPNProtocol/include/PacketMacros.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/PacketStream.h b/Sources/CTunnelKitOpenVPNProtocol/include/PacketStream.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/PacketStream.h rename to Sources/CTunnelKitOpenVPNProtocol/include/PacketStream.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/ReplayProtector.h b/Sources/CTunnelKitOpenVPNProtocol/include/ReplayProtector.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/ReplayProtector.h rename to Sources/CTunnelKitOpenVPNProtocol/include/ReplayProtector.h diff --git a/Sources/_TunnelKitOpenVPNObjC/include/TLSBox.h b/Sources/CTunnelKitOpenVPNProtocol/include/TLSBox.h similarity index 100% rename from Sources/_TunnelKitOpenVPNObjC/include/TLSBox.h rename to Sources/CTunnelKitOpenVPNProtocol/include/TLSBox.h diff --git a/Sources/TunnelKit/Exports.swift b/Sources/TunnelKit/Exports.swift new file mode 100644 index 0000000..4feee2c --- /dev/null +++ b/Sources/TunnelKit/Exports.swift @@ -0,0 +1,2 @@ +@_exported import TunnelKitCore +@_exported import TunnelKitManager diff --git a/Sources/TunnelKitCore/Errors.swift b/Sources/TunnelKitCore/Errors.swift index 27c3430..cf5e52d 100644 --- a/Sources/TunnelKitCore/Errors.swift +++ b/Sources/TunnelKitCore/Errors.swift @@ -24,7 +24,7 @@ // import Foundation -import _TunnelKitCoreObjC +import CTunnelKitCore extension Error { public func isTunnelKitError() -> Bool { diff --git a/Sources/TunnelKitCore/SecureRandom.swift b/Sources/TunnelKitCore/SecureRandom.swift index f343455..049fd8b 100644 --- a/Sources/TunnelKitCore/SecureRandom.swift +++ b/Sources/TunnelKitCore/SecureRandom.swift @@ -36,8 +36,8 @@ import Foundation import Security.SecRandom -import _TunnelKitCoreObjC -import _TunnelKitUtils +import CTunnelKitCore +import __TunnelKitUtils /// :nodoc: public enum SecureRandomError: Error { diff --git a/Sources/TunnelKitCore/ZeroingData.swift b/Sources/TunnelKitCore/ZeroingData.swift index bb4343d..55db264 100644 --- a/Sources/TunnelKitCore/ZeroingData.swift +++ b/Sources/TunnelKitCore/ZeroingData.swift @@ -35,7 +35,7 @@ // import Foundation -import _TunnelKitCoreObjC +import CTunnelKitCore public func Z() -> ZeroingData { return ZeroingData() diff --git a/Sources/TunnelKitLZO/include/Errors.h b/Sources/TunnelKitLZO/include/Errors.h index 0a905c8..8afcae1 120000 --- a/Sources/TunnelKitLZO/include/Errors.h +++ b/Sources/TunnelKitLZO/include/Errors.h @@ -1 +1 @@ -../../_TunnelKitCoreObjC/include/Errors.h \ No newline at end of file +../../CTunnelKitCore/include/Errors.h \ No newline at end of file diff --git a/Sources/TunnelKitAppExtension/Keychain.swift b/Sources/TunnelKitManager/Keychain.swift similarity index 100% rename from Sources/TunnelKitAppExtension/Keychain.swift rename to Sources/TunnelKitManager/Keychain.swift diff --git a/Sources/TunnelKitOpenVPN/AppExtension/OpenVPNTunnelProvider+Interaction.swift b/Sources/TunnelKitOpenVPN/AppExtension/OpenVPNTunnelProvider+Interaction.swift deleted file mode 100644 index d78fee5..0000000 --- a/Sources/TunnelKitOpenVPN/AppExtension/OpenVPNTunnelProvider+Interaction.swift +++ /dev/null @@ -1,151 +0,0 @@ -// -// OpenVPNTunnelProvider+Interaction.swift -// TunnelKit -// -// Created by Davide De Rosa on 9/24/17. -// Copyright (c) 2021 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 . -// -// 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. -// - -import Foundation - -extension OpenVPNTunnelProvider { - - // MARK: Interaction - - /// The messages accepted by `OpenVPNTunnelProvider`. - public class Message: Equatable { - - /// Requests a snapshot of the latest debug log. Returns the log data decoded from UTF-8. - public static let requestLog = Message(0xff) - - /// Requests the current bytes count from data channel (if connected). - /// - /// Data is 16 bytes: low 8 = received, high 8 = sent. - public static let dataCount = Message(0xfe) - - /// Requests the configuration pulled from the server (if connected and available). - /// - /// Data is JSON (Decodable). - public static let serverConfiguration = Message(0xfd) - - /// The underlying raw message `Data` to forward to the tunnel via IPC. - public let data: Data - - private init(_ byte: UInt8) { - data = Data([byte]) - } - - init(_ data: Data) { - self.data = data - } - - // MARK: Equatable - - /// :nodoc: - public static func ==(lhs: Message, rhs: Message) -> Bool { - return (lhs.data == rhs.data) - } - } - - // mostly programming errors by host app - enum ProviderConfigurationError: Error { - - /// A field in the `OpenVPNTunnelProvider.Configuration` provided is incorrect or incomplete. - case parameter(name: String) - - /// Credentials are missing or inaccessible. - case credentials(details: String) - - /// The pseudo-random number generator could not be initialized. - case prngInitialization - - /// The TLS certificate could not be serialized. - case certificateSerialization - } - - /// The errors causing a tunnel disconnection. - public enum ProviderError: String, Error { - - /// Socket endpoint could not be resolved. - case dnsFailure - - /// No more protocols available to try. - case exhaustedProtocols - - /// Socket failed to reach active state. - case socketActivity - - /// Credentials authentication failed. - case authentication - - /// TLS could not be initialized (e.g. malformed CA or client PEMs). - case tlsInitialization - - /// TLS server verification failed. - case tlsServerVerification - - /// TLS handshake failed. - case tlsHandshake - - /// The encryption logic could not be initialized (e.g. PRNG, algorithms). - case encryptionInitialization - - /// Data encryption/decryption failed. - case encryptionData - - /// The LZO engine failed. - case lzo - - /// Server uses an unsupported compression algorithm. - case serverCompression - - /// Tunnel timed out. - case timeout - - /// An error occurred at the link level. - case linkError - - /// Network routing information is missing or incomplete. - case routing - - /// The current network changed (e.g. switched from WiFi to data connection). - case networkChanged - - /// Default gateway could not be attained. - case gatewayUnattainable - - /// Remove server has shut down. - case serverShutdown - - /// The server replied in an unexpected way. - case unexpectedReply - } -} diff --git a/Sources/TunnelKitOpenVPN/Exports.swift b/Sources/TunnelKitOpenVPN/Exports.swift new file mode 100644 index 0000000..6205540 --- /dev/null +++ b/Sources/TunnelKitOpenVPN/Exports.swift @@ -0,0 +1,2 @@ +@_exported import TunnelKitOpenVPNCore +@_exported import TunnelKitOpenVPNManager diff --git a/Sources/TunnelKitOpenVPN/AppExtension/ConnectionStrategy.swift b/Sources/TunnelKitOpenVPNAppExtension/ConnectionStrategy.swift similarity index 97% rename from Sources/TunnelKitOpenVPN/AppExtension/ConnectionStrategy.swift rename to Sources/TunnelKitOpenVPNAppExtension/ConnectionStrategy.swift index a41ea77..0bb3159 100644 --- a/Sources/TunnelKitOpenVPN/AppExtension/ConnectionStrategy.swift +++ b/Sources/TunnelKitOpenVPNAppExtension/ConnectionStrategy.swift @@ -39,6 +39,7 @@ import NetworkExtension import SwiftyBeaver import TunnelKitCore import TunnelKitAppExtension +import TunnelKitOpenVPNManager private let log = SwiftyBeaver.self @@ -73,7 +74,7 @@ class ConnectionStrategy { private let resolvedAddresses: [String] - init(configuration: OpenVPNTunnelProvider.Configuration) { + init(configuration: OpenVPNProvider.Configuration) { hostname = configuration.sessionConfiguration.hostname guard var endpointProtocols = configuration.sessionConfiguration.endpointProtocols else { fatalError("No endpoints provided") @@ -170,7 +171,7 @@ class ConnectionStrategy { guard let hostname = hostname else { log.error("DNS resolution unavailable: no hostname provided!") - completionHandler(nil, OpenVPNTunnelProvider.ProviderError.dnsFailure) + completionHandler(nil, OpenVPNProviderError.dnsFailure) return } log.debug("DNS resolve hostname: \(hostname.maskedDescription)") @@ -187,7 +188,7 @@ class ConnectionStrategy { guard self.hasEndpoint() else { log.error("No endpoints available") - completionHandler(nil, OpenVPNTunnelProvider.ProviderError.dnsFailure) + completionHandler(nil, OpenVPNProviderError.dnsFailure) return } diff --git a/Sources/TunnelKitOpenVPN/AppExtension/NETCPLink.swift b/Sources/TunnelKitOpenVPNAppExtension/NETCPLink.swift similarity index 99% rename from Sources/TunnelKitOpenVPN/AppExtension/NETCPLink.swift rename to Sources/TunnelKitOpenVPNAppExtension/NETCPLink.swift index 6249f2b..aa5c794 100644 --- a/Sources/TunnelKitOpenVPN/AppExtension/NETCPLink.swift +++ b/Sources/TunnelKitOpenVPNAppExtension/NETCPLink.swift @@ -27,7 +27,7 @@ import Foundation import NetworkExtension import TunnelKitCore import TunnelKitAppExtension -import _TunnelKitOpenVPNObjC +import CTunnelKitOpenVPNProtocol class NETCPLink: LinkInterface { private let impl: NWTCPConnection diff --git a/Sources/TunnelKitOpenVPN/AppExtension/NEUDPLink.swift b/Sources/TunnelKitOpenVPNAppExtension/NEUDPLink.swift similarity index 100% rename from Sources/TunnelKitOpenVPN/AppExtension/NEUDPLink.swift rename to Sources/TunnelKitOpenVPNAppExtension/NEUDPLink.swift diff --git a/Sources/TunnelKitOpenVPN/AppExtension/OpenVPNTunnelProvider.swift b/Sources/TunnelKitOpenVPNAppExtension/OpenVPNTunnelProvider.swift similarity index 95% rename from Sources/TunnelKitOpenVPN/AppExtension/OpenVPNTunnelProvider.swift rename to Sources/TunnelKitOpenVPNAppExtension/OpenVPNTunnelProvider.swift index 9e82ca0..177c6b8 100644 --- a/Sources/TunnelKitOpenVPN/AppExtension/OpenVPNTunnelProvider.swift +++ b/Sources/TunnelKitOpenVPNAppExtension/OpenVPNTunnelProvider.swift @@ -42,8 +42,12 @@ import SystemConfiguration.CaptiveNetwork import CoreWLAN #endif import TunnelKitCore -import _TunnelKitCoreObjC +import TunnelKitOpenVPNCore +import TunnelKitManager +import TunnelKitOpenVPNManager +import TunnelKitOpenVPNProtocol import TunnelKitAppExtension +import CTunnelKitCore private let log = SwiftyBeaver.self @@ -117,7 +121,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { private lazy var defaults = UserDefaults(suiteName: appGroup) - private var cfg: Configuration! + private var cfg: OpenVPNProvider.Configuration! private var strategy: ConnectionStrategy! @@ -150,16 +154,16 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { // required configuration do { guard let tunnelProtocol = protocolConfiguration as? NETunnelProviderProtocol else { - throw ProviderConfigurationError.parameter(name: "protocolConfiguration") + throw OpenVPNProviderConfigurationError.parameter(name: "protocolConfiguration") } guard let serverAddress = tunnelProtocol.serverAddress else { - throw ProviderConfigurationError.parameter(name: "protocolConfiguration.serverAddress") + throw OpenVPNProviderConfigurationError.parameter(name: "protocolConfiguration.serverAddress") } guard let providerConfiguration = tunnelProtocol.providerConfiguration else { - throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration") + throw OpenVPNProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration") } - try appGroup = Configuration.appGroup(from: providerConfiguration) - try cfg = Configuration.parsed(from: providerConfiguration) + try appGroup = OpenVPNProvider.Configuration.appGroup(from: providerConfiguration) + try cfg = OpenVPNProvider.Configuration.parsed(from: providerConfiguration) // inject serverAddress into sessionConfiguration.hostname if !serverAddress.isEmpty { @@ -171,7 +175,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { } } catch let e { var message: String? - if let te = e as? ProviderConfigurationError { + if let te = e as? OpenVPNProviderConfigurationError { switch te { case .parameter(let name): message = "Tunnel configuration incomplete: \(name)" @@ -217,7 +221,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { if let username = protocolConfiguration.username, let passwordReference = protocolConfiguration.passwordReference { let keychain = Keychain(group: appGroup) guard let password = try? keychain.password(for: username, reference: passwordReference) else { - completionHandler(ProviderConfigurationError.credentials(details: "keychain.password(for:, reference:)")) + completionHandler(OpenVPNProviderConfigurationError.credentials(details: "keychain.password(for:, reference:)")) return } credentials = OpenVPN.Credentials(username, password) @@ -229,7 +233,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { cfg.clearLastError(in: appGroup) guard OpenVPN.prepareRandomNumberGenerator(seedLength: prngSeedLength) else { - completionHandler(ProviderConfigurationError.prngInitialization) + completionHandler(OpenVPNProviderConfigurationError.prngInitialization) return } @@ -292,7 +296,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { /// :nodoc: open override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)? = nil) { var response: Data? - switch Message(messageData) { + switch OpenVPNProvider.Message(messageData) { case .requestLog: response = memoryLog.description.data(using: .utf8) @@ -398,7 +402,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { // from stopTunnel(), in which case we don't need to feed an error parameter to // the stop completion handler // - pendingStartHandler?(error ?? ProviderError.socketActivity) + pendingStartHandler?(error ?? OpenVPNProviderError.socketActivity) pendingStartHandler = nil } // stopped intentionally @@ -476,7 +480,7 @@ extension OpenVPNTunnelProvider: GenericSocketDelegate { // look for error causing shutdown shutdownError = session.stopError if failure && (shutdownError == nil) { - shutdownError = ProviderError.linkError + shutdownError = OpenVPNProviderError.linkError } didTimeoutNegotiation = (shutdownError as? OpenVPNError == .negotiationTimeout) @@ -522,7 +526,7 @@ extension OpenVPNTunnelProvider: GenericSocketDelegate { public func socketHasBetterPath(_ socket: GenericSocket) { log.debug("Stopping tunnel due to a new better path") logCurrentSSID() - session?.reconnect(error: ProviderError.networkChanged) + session?.reconnect(error: OpenVPNProviderError.networkChanged) } } @@ -683,7 +687,7 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate { hasGateway = true } guard !isGateway || hasGateway else { - session?.shutdown(error: ProviderError.gatewayUnattainable) + session?.shutdown(error: OpenVPNProviderError.gatewayUnattainable) return } @@ -704,7 +708,7 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate { case .tls: guard let dnsServers = cfg.sessionConfiguration.dnsServers else { - session?.shutdown(error: ProviderError.dnsFailure) + session?.shutdown(error: OpenVPNProviderError.dnsFailure) return } guard let serverName = cfg.sessionConfiguration.dnsTLSServerName else { @@ -848,7 +852,7 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate { extension OpenVPNTunnelProvider { private func tryNextEndpoint() -> Bool { guard strategy.tryNextEndpoint() else { - disposeTunnel(error: ProviderError.exhaustedProtocols) + disposeTunnel(error: OpenVPNProviderError.exhaustedProtocols) return false } return true @@ -900,10 +904,10 @@ extension OpenVPNTunnelProvider { // MARK: Errors private func setErrorStatus(with error: Error) { - defaults?.set(unifiedError(from: error).rawValue, forKey: Configuration.lastErrorKey) + defaults?.set(unifiedError(from: error).rawValue, forKey: OpenVPNProvider.Configuration.lastErrorKey) } - private func unifiedError(from error: Error) -> ProviderError { + private func unifiedError(from error: Error) -> OpenVPNProviderError { if let te = error.tunnelKitErrorCode() { switch te { case .cryptoRandomGenerator, .cryptoAlgorithm: @@ -957,7 +961,7 @@ extension OpenVPNTunnelProvider { return .unexpectedReply } } - return error as? ProviderError ?? .linkError + return error as? OpenVPNProviderError ?? .linkError } } diff --git a/Sources/TunnelKitOpenVPN/CompressionAlgorithm.swift b/Sources/TunnelKitOpenVPNCore/CompressionAlgorithm.swift similarity index 94% rename from Sources/TunnelKitOpenVPN/CompressionAlgorithm.swift rename to Sources/TunnelKitOpenVPNCore/CompressionAlgorithm.swift index faf918a..87aeb5b 100644 --- a/Sources/TunnelKitOpenVPN/CompressionAlgorithm.swift +++ b/Sources/TunnelKitOpenVPNCore/CompressionAlgorithm.swift @@ -24,7 +24,7 @@ // import Foundation -import _TunnelKitOpenVPNObjC +import CTunnelKitOpenVPNCore extension OpenVPN { @@ -40,7 +40,8 @@ extension OpenVPN { /// Any other compression algorithm (unsupported). case other - var native: CompressionAlgorithmNative { + /// :nodoc: + public var native: CompressionAlgorithmNative { guard let val = CompressionAlgorithmNative(rawValue: rawValue) else { fatalError("Unhandled CompressionAlgorithm bridging") } diff --git a/Sources/TunnelKitOpenVPN/CompressionFraming.swift b/Sources/TunnelKitOpenVPNCore/CompressionFraming.swift similarity index 95% rename from Sources/TunnelKitOpenVPN/CompressionFraming.swift rename to Sources/TunnelKitOpenVPNCore/CompressionFraming.swift index 8281960..f0eab6e 100644 --- a/Sources/TunnelKitOpenVPN/CompressionFraming.swift +++ b/Sources/TunnelKitOpenVPNCore/CompressionFraming.swift @@ -24,7 +24,7 @@ // import Foundation -import _TunnelKitOpenVPNObjC +import CTunnelKitOpenVPNCore extension OpenVPN { @@ -43,7 +43,8 @@ extension OpenVPN { /// Framing compatible with 2.4 `compress` (version 2, e.g. stub-v2). case compressV2 - var native: CompressionFramingNative { + /// :nodoc: + public var native: CompressionFramingNative { guard let val = CompressionFramingNative(rawValue: rawValue) else { fatalError("Unhandled CompressionFraming bridging") } diff --git a/Sources/TunnelKitOpenVPN/Configuration.swift b/Sources/TunnelKitOpenVPNCore/Configuration.swift similarity index 99% rename from Sources/TunnelKitOpenVPN/Configuration.swift rename to Sources/TunnelKitOpenVPNCore/Configuration.swift index a046501..34e8fc3 100644 --- a/Sources/TunnelKitOpenVPN/Configuration.swift +++ b/Sources/TunnelKitOpenVPNCore/Configuration.swift @@ -561,7 +561,9 @@ extension OpenVPN.Configuration { // MARK: Encoding extension OpenVPN.Configuration { - func print() { + + /// :nodoc: + public func print() { guard let endpointProtocols = endpointProtocols else { fatalError("No sessionConfiguration.endpointProtocols set") } diff --git a/Sources/TunnelKitOpenVPN/ConfigurationParser.swift b/Sources/TunnelKitOpenVPNCore/ConfigurationParser.swift similarity index 99% rename from Sources/TunnelKitOpenVPN/ConfigurationParser.swift rename to Sources/TunnelKitOpenVPNCore/ConfigurationParser.swift index 9287dc7..b14046b 100644 --- a/Sources/TunnelKitOpenVPN/ConfigurationParser.swift +++ b/Sources/TunnelKitOpenVPNCore/ConfigurationParser.swift @@ -26,8 +26,8 @@ import Foundation import SwiftyBeaver import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitUtils +import CTunnelKitCore +import __TunnelKitUtils private let log = SwiftyBeaver.self @@ -38,7 +38,7 @@ extension OpenVPN { // XXX: parsing is very optimistic - struct Regex { + public struct Regex { // MARK: General @@ -84,7 +84,8 @@ extension OpenVPN { // MARK: Server - static let authToken = NSRegularExpression("^auth-token +[a-zA-Z0-9/=+]+") + /// :nodoc: + public static let authToken = NSRegularExpression("^auth-token +[a-zA-Z0-9/=+]+") static let peerId = NSRegularExpression("^peer-id +[0-9]+") @@ -679,6 +680,7 @@ extension OpenVPN { sessionBuilder.clientCertificate = optClientCertificate if let clientKey = optClientKey, clientKey.isEncrypted { + // FIXME: remove dependency on TLSBox guard let passphrase = passphrase else { throw ConfigurationError.encryptionPassphrase } diff --git a/Sources/TunnelKitOpenVPN/CryptoContainer.swift b/Sources/TunnelKitOpenVPNCore/CryptoContainer.swift similarity index 97% rename from Sources/TunnelKitOpenVPN/CryptoContainer.swift rename to Sources/TunnelKitOpenVPNCore/CryptoContainer.swift index 2393cb5..0760430 100644 --- a/Sources/TunnelKitOpenVPN/CryptoContainer.swift +++ b/Sources/TunnelKitOpenVPNCore/CryptoContainer.swift @@ -35,7 +35,9 @@ // import Foundation -import _TunnelKitOpenVPNObjC + +// FIXME: remove dependency on TLSBox +import CTunnelKitOpenVPNProtocol extension OpenVPN { @@ -65,6 +67,7 @@ extension OpenVPN { try pem.write(to: url, atomically: true, encoding: .ascii) } + // FIXME: remove dependency on TLSBox func decrypted(with passphrase: String) throws -> CryptoContainer { let decryptedPEM = try TLSBox.decryptedPrivateKey(fromPEM: pem, passphrase: passphrase) return CryptoContainer(pem: decryptedPEM) diff --git a/Sources/TunnelKitOpenVPNCore/OpenVPN.swift b/Sources/TunnelKitOpenVPNCore/OpenVPN.swift new file mode 100644 index 0000000..77395d0 --- /dev/null +++ b/Sources/TunnelKitOpenVPNCore/OpenVPN.swift @@ -0,0 +1,30 @@ +// +// OpenVPN.swift +// TunnelKit +// +// Created by Davide De Rosa on 5/19/19. +// Copyright (c) 2021 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 + +/// Container for OpenVPN classes. +public class OpenVPN { +} diff --git a/Sources/TunnelKitOpenVPN/OpenVPNError.swift b/Sources/TunnelKitOpenVPNCore/OpenVPNError.swift similarity index 100% rename from Sources/TunnelKitOpenVPN/OpenVPNError.swift rename to Sources/TunnelKitOpenVPNCore/OpenVPNError.swift diff --git a/Sources/TunnelKitOpenVPN/StaticKey.swift b/Sources/TunnelKitOpenVPNCore/StaticKey.swift similarity index 98% rename from Sources/TunnelKitOpenVPN/StaticKey.swift rename to Sources/TunnelKitOpenVPNCore/StaticKey.swift index d2d2699..3e5e863 100644 --- a/Sources/TunnelKitOpenVPN/StaticKey.swift +++ b/Sources/TunnelKitOpenVPNCore/StaticKey.swift @@ -25,7 +25,7 @@ import Foundation import TunnelKitCore -import _TunnelKitCoreObjC +import CTunnelKitCore extension OpenVPN { @@ -61,7 +61,8 @@ extension OpenVPN { private let secureData: ZeroingData - let direction: Direction? + /// :nodoc: + public let direction: Direction? /// Returns the encryption key. /// diff --git a/Sources/TunnelKitOpenVPN/TLSWrap.swift b/Sources/TunnelKitOpenVPNCore/TLSWrap.swift similarity index 100% rename from Sources/TunnelKitOpenVPN/TLSWrap.swift rename to Sources/TunnelKitOpenVPNCore/TLSWrap.swift diff --git a/Sources/TunnelKitOpenVPN/AppExtension/OpenVPNTunnelProvider+Configuration.swift b/Sources/TunnelKitOpenVPNManager/OpenVPNProvider+Configuration.swift similarity index 79% rename from Sources/TunnelKitOpenVPN/AppExtension/OpenVPNTunnelProvider+Configuration.swift rename to Sources/TunnelKitOpenVPNManager/OpenVPNProvider+Configuration.swift index f76134f..95857c1 100644 --- a/Sources/TunnelKitOpenVPN/AppExtension/OpenVPNTunnelProvider+Configuration.swift +++ b/Sources/TunnelKitOpenVPNManager/OpenVPNProvider+Configuration.swift @@ -1,5 +1,5 @@ // -// OpenVPNTunnelProvider+Configuration.swift +// OpenVPNProvider+Configuration.swift // TunnelKit // // Created by Davide De Rosa on 10/23/17. @@ -38,20 +38,21 @@ import Foundation import NetworkExtension import SwiftyBeaver import TunnelKitCore -import _TunnelKitCoreObjC -import TunnelKitAppExtension -import _TunnelKitUtils +import TunnelKitOpenVPNCore +import TunnelKitManager +import CTunnelKitCore +import __TunnelKitUtils private let log = SwiftyBeaver.self -extension OpenVPNTunnelProvider { +extension OpenVPNProvider { private struct ExtraKeys { static let appGroup = "appGroup" } // MARK: Configuration - /// The way to create a `OpenVPNTunnelProvider.Configuration` object for the tunnel profile. + /// The way to create a `OpenVPNProvider.Configuration` object for the tunnel profile. public struct ConfigurationBuilder { /// :nodoc: @@ -108,9 +109,9 @@ extension OpenVPNTunnelProvider { } /** - Builds a `OpenVPNTunnelProvider.Configuration` object that will connect to the provided endpoint. + Builds a `OpenVPNProvider.Configuration` object that will connect to the provided endpoint. - - Returns: A `OpenVPNTunnelProvider.Configuration` object with this builder and the additional method parameters. + - Returns: A `OpenVPNProvider.Configuration` object with this builder and the additional method parameters. */ public func build() -> Configuration { return Configuration( @@ -125,35 +126,36 @@ extension OpenVPNTunnelProvider { } } - /// Offers a bridge between the abstract `OpenVPNTunnelProvider.ConfigurationBuilder` and a concrete `NETunnelProviderProtocol` profile. + /// Offers a bridge between the abstract `OpenVPNProvider.ConfigurationBuilder` and a concrete `NETunnelProviderProtocol` profile. public struct Configuration: Codable { - /// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.sessionConfiguration` + /// - Seealso: `OpenVPNProvider.ConfigurationBuilder.sessionConfiguration` public let sessionConfiguration: OpenVPN.Configuration - /// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.prefersResolvedAddresses` + /// - Seealso: `OpenVPNProvider.ConfigurationBuilder.prefersResolvedAddresses` public let prefersResolvedAddresses: Bool - /// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.resolvedAddresses` + /// - Seealso: `OpenVPNProvider.ConfigurationBuilder.resolvedAddresses` public let resolvedAddresses: [String]? - /// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.shouldDebug` + /// - Seealso: `OpenVPNProvider.ConfigurationBuilder.shouldDebug` public let shouldDebug: Bool - /// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.debugLogFormat` + /// - Seealso: `OpenVPNProvider.ConfigurationBuilder.debugLogFormat` public let debugLogFormat: String? - /// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.masksPrivateData` + /// - Seealso: `OpenVPNProvider.ConfigurationBuilder.masksPrivateData` public let masksPrivateData: Bool? - /// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.versionIdentifier` + /// - Seealso: `OpenVPNProvider.ConfigurationBuilder.versionIdentifier` public let versionIdentifier: String? // MARK: Shortcuts static let debugLogFilename = "debug.log" - static let lastErrorKey = "TunnelKitLastError" + /// :nodoc: + public static let lastErrorKey = "TunnelKitLastError" fileprivate static let dataCountKey = "TunnelKitDataCount" @@ -192,11 +194,11 @@ extension OpenVPNTunnelProvider { - Parameter in: The app group where to locate the error key. - Returns: The last tunnel error, if any. */ - public func lastError(in appGroup: String) -> ProviderError? { + public func lastError(in appGroup: String) -> OpenVPNProviderError? { guard let rawValue = UserDefaults(suiteName: appGroup)?.string(forKey: Configuration.lastErrorKey) else { return nil } - return ProviderError(rawValue: rawValue) + return OpenVPNProviderError(rawValue: rawValue) } /** @@ -231,26 +233,26 @@ extension OpenVPNTunnelProvider { - Parameter from: The map to parse. - Returns: The parsed app group. - - Throws: `ProviderError.configuration` if `providerConfiguration` does not contain an app group. + - Throws: `OpenVPNProviderError.configuration` if `providerConfiguration` does not contain an app group. */ public static func appGroup(from providerConfiguration: [String: Any]) throws -> String { guard let appGroup = providerConfiguration[ExtraKeys.appGroup] as? String else { - throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[\(ExtraKeys.appGroup)]") + throw OpenVPNProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[\(ExtraKeys.appGroup)]") } return appGroup } /** - Parses a new `OpenVPNTunnelProvider.Configuration` object from a provider configuration map. + Parses a new `OpenVPNProvider.Configuration` object from a provider configuration map. - Parameter from: The map to parse. - - Returns: The parsed `OpenVPNTunnelProvider.Configuration` object. - - Throws: `ProviderError.configuration` if `providerConfiguration` is incomplete. + - Returns: The parsed `OpenVPNProvider.Configuration` object. + - Throws: `OpenVPNProviderError.configuration` if `providerConfiguration` is incomplete. */ public static func parsed(from providerConfiguration: [String: Any]) throws -> Configuration { - let cfg = try fromDictionary(OpenVPNTunnelProvider.Configuration.self, providerConfiguration) + let cfg = try fromDictionary(OpenVPNProvider.Configuration.self, providerConfiguration) guard !cfg.prefersResolvedAddresses || !(cfg.resolvedAddresses?.isEmpty ?? true) else { - throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[prefersResolvedAddresses] is true but no [resolvedAddresses]") + throw OpenVPNProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[prefersResolvedAddresses] is true but no [resolvedAddresses]") } return cfg } @@ -280,7 +282,7 @@ extension OpenVPNTunnelProvider { - Parameter context: The keychain context where to look for the password reference. - Parameter username: The username to authenticate with. - Returns: The generated `NETunnelProviderProtocol` object. - - Throws: `ProviderError.credentials` if unable to store `credentials.password` to the `appGroup` keychain. + - Throws: `OpenVPNProviderError.credentials` if unable to store `credentials.password` to the `appGroup` keychain. */ public func generatedTunnelProtocol( withBundleIdentifier bundleIdentifier: String, @@ -302,7 +304,8 @@ extension OpenVPNTunnelProvider { return protocolConfiguration } - func print(appVersion: String?) { + /// :nodoc: + public func print(appVersion: String?) { if let appVersion = appVersion { log.info("App version: \(appVersion)") } @@ -315,15 +318,15 @@ extension OpenVPNTunnelProvider { // MARK: Modification -extension OpenVPNTunnelProvider.Configuration { +extension OpenVPNProvider.Configuration { /** - Returns a `OpenVPNTunnelProvider.ConfigurationBuilder` to use this configuration as a starting point for a new one. + Returns a `OpenVPNProvider.ConfigurationBuilder` to use this configuration as a starting point for a new one. - - Returns: An editable `OpenVPNTunnelProvider.ConfigurationBuilder` initialized with this configuration. + - Returns: An editable `OpenVPNProvider.ConfigurationBuilder` initialized with this configuration. */ - public func builder() -> OpenVPNTunnelProvider.ConfigurationBuilder { - var builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionConfiguration) + public func builder() -> OpenVPNProvider.ConfigurationBuilder { + var builder = OpenVPNProvider.ConfigurationBuilder(sessionConfiguration: sessionConfiguration) builder.prefersResolvedAddresses = prefersResolvedAddresses builder.resolvedAddresses = resolvedAddresses builder.shouldDebug = shouldDebug @@ -338,14 +341,14 @@ extension OpenVPNTunnelProvider.Configuration { public extension UserDefaults { @objc var dataCountArray: [Int]? { get { - return array(forKey: OpenVPNTunnelProvider.Configuration.dataCountKey) as? [Int] + return array(forKey: OpenVPNProvider.Configuration.dataCountKey) as? [Int] } set { - set(newValue, forKey: OpenVPNTunnelProvider.Configuration.dataCountKey) + set(newValue, forKey: OpenVPNProvider.Configuration.dataCountKey) } } func removeDataCountArray() { - removeObject(forKey: OpenVPNTunnelProvider.Configuration.dataCountKey) + removeObject(forKey: OpenVPNProvider.Configuration.dataCountKey) } } diff --git a/Sources/TunnelKitOpenVPNManager/OpenVPNProvider+Interaction.swift b/Sources/TunnelKitOpenVPNManager/OpenVPNProvider+Interaction.swift new file mode 100644 index 0000000..4347a27 --- /dev/null +++ b/Sources/TunnelKitOpenVPNManager/OpenVPNProvider+Interaction.swift @@ -0,0 +1,68 @@ +// +// OpenVPNProvider+Interaction.swift +// TunnelKit +// +// Created by Davide De Rosa on 9/24/17. +// Copyright (c) 2021 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 . +// +// This file incorporates work covered by the following copyright and +// permission notice: +// + +import Foundation + +extension OpenVPNProvider { + + /// The messages accepted by `OpenVPNProvider`. + public class Message: Equatable { + + /// Requests a snapshot of the latest debug log. Returns the log data decoded from UTF-8. + public static let requestLog = Message(0xff) + + /// Requests the current bytes count from data channel (if connected). + /// + /// Data is 16 bytes: low 8 = received, high 8 = sent. + public static let dataCount = Message(0xfe) + + /// Requests the configuration pulled from the server (if connected and available). + /// + /// Data is JSON (Decodable). + public static let serverConfiguration = Message(0xfd) + + /// The underlying raw message `Data` to forward to the tunnel via IPC. + public let data: Data + + private init(_ byte: UInt8) { + data = Data([byte]) + } + + /// :nodoc: + public init(_ data: Data) { + self.data = data + } + + // MARK: Equatable + + /// :nodoc: + public static func ==(lhs: Message, rhs: Message) -> Bool { + return (lhs.data == rhs.data) + } + } +} diff --git a/Sources/TunnelKitOpenVPN/OpenVPNProvider.swift b/Sources/TunnelKitOpenVPNManager/OpenVPNProvider.swift similarity index 95% rename from Sources/TunnelKitOpenVPN/OpenVPNProvider.swift rename to Sources/TunnelKitOpenVPNManager/OpenVPNProvider.swift index 912a6bf..0efa490 100644 --- a/Sources/TunnelKitOpenVPN/OpenVPNProvider.swift +++ b/Sources/TunnelKitOpenVPNManager/OpenVPNProvider.swift @@ -25,6 +25,7 @@ import Foundation import NetworkExtension +import TunnelKitOpenVPNCore import TunnelKitManager /// `VPNProvider` for OpenVPN protocol. @@ -105,7 +106,7 @@ public class OpenVPNProvider: VPNProvider, VPNProviderIPC { return } do { - try session.sendProviderMessage(OpenVPNTunnelProvider.Message.dataCount.data) { (data) in + try session.sendProviderMessage(Message.dataCount.data) { (data) in guard let data = data, data.count == 16 else { DispatchQueue.main.async { completionHandler(nil) @@ -135,7 +136,7 @@ public class OpenVPNProvider: VPNProvider, VPNProviderIPC { return } do { - try session.sendProviderMessage(OpenVPNTunnelProvider.Message.serverConfiguration.data) { (data) in + try session.sendProviderMessage(Message.serverConfiguration.data) { (data) in guard let data = data, let cfg = try? JSONDecoder().decode(OpenVPN.Configuration.self, from: data) else { DispatchQueue.main.async { completionHandler(nil) @@ -168,7 +169,7 @@ public class OpenVPNProvider: VPNProvider, VPNProviderIPC { private static func requestDebugLog(session: NETunnelProviderSession, completionHandler: @escaping (String?) -> Void) { do { - try session.sendProviderMessage(OpenVPNTunnelProvider.Message.requestLog.data) { (data) in + try session.sendProviderMessage(Message.requestLog.data) { (data) in guard let data = data, !data.isEmpty else { completionHandler(nil) return diff --git a/Sources/TunnelKitOpenVPNManager/OpenVPNProviderError.swift b/Sources/TunnelKitOpenVPNManager/OpenVPNProviderError.swift new file mode 100644 index 0000000..34e4b87 --- /dev/null +++ b/Sources/TunnelKitOpenVPNManager/OpenVPNProviderError.swift @@ -0,0 +1,111 @@ +// +// OpenVPNProviderError.swift +// TunnelKit +// +// Created by Davide De Rosa on 11/8/21. +// Copyright (c) 2021 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 . +// +// 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. +// + +import Foundation + +/// Mostly programming errors by host app. +public enum OpenVPNProviderConfigurationError: Error { + + /// A field in the `OpenVPNProvider.Configuration` provided is incorrect or incomplete. + case parameter(name: String) + + /// Credentials are missing or inaccessible. + case credentials(details: String) + + /// The pseudo-random number generator could not be initialized. + case prngInitialization + + /// The TLS certificate could not be serialized. + case certificateSerialization +} + +/// The errors causing a tunnel disconnection. +public enum OpenVPNProviderError: String, Error { + + /// Socket endpoint could not be resolved. + case dnsFailure + + /// No more protocols available to try. + case exhaustedProtocols + + /// Socket failed to reach active state. + case socketActivity + + /// Credentials authentication failed. + case authentication + + /// TLS could not be initialized (e.g. malformed CA or client PEMs). + case tlsInitialization + + /// TLS server verification failed. + case tlsServerVerification + + /// TLS handshake failed. + case tlsHandshake + + /// The encryption logic could not be initialized (e.g. PRNG, algorithms). + case encryptionInitialization + + /// Data encryption/decryption failed. + case encryptionData + + /// The LZO engine failed. + case lzo + + /// Server uses an unsupported compression algorithm. + case serverCompression + + /// Tunnel timed out. + case timeout + + /// An error occurred at the link level. + case linkError + + /// Network routing information is missing or incomplete. + case routing + + /// The current network changed (e.g. switched from WiFi to data connection). + case networkChanged + + /// Default gateway could not be attained. + case gatewayUnattainable + + /// Remove server has shut down. + case serverShutdown + + /// The server replied in an unexpected way. + case unexpectedReply +} diff --git a/Sources/TunnelKitOpenVPN/Authenticator.swift b/Sources/TunnelKitOpenVPNProtocol/Authenticator.swift similarity index 99% rename from Sources/TunnelKitOpenVPN/Authenticator.swift rename to Sources/TunnelKitOpenVPNProtocol/Authenticator.swift index 4ac317b..be27b9f 100644 --- a/Sources/TunnelKitOpenVPN/Authenticator.swift +++ b/Sources/TunnelKitOpenVPNProtocol/Authenticator.swift @@ -37,8 +37,9 @@ import Foundation import SwiftyBeaver import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import TunnelKitOpenVPNCore +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol private let log = SwiftyBeaver.self diff --git a/Sources/TunnelKitOpenVPN/ControlChannel.swift b/Sources/TunnelKitOpenVPNProtocol/ControlChannel.swift similarity index 99% rename from Sources/TunnelKitOpenVPN/ControlChannel.swift rename to Sources/TunnelKitOpenVPNProtocol/ControlChannel.swift index 6360a7b..ea237c5 100644 --- a/Sources/TunnelKitOpenVPN/ControlChannel.swift +++ b/Sources/TunnelKitOpenVPNProtocol/ControlChannel.swift @@ -26,8 +26,9 @@ import Foundation import SwiftyBeaver import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import TunnelKitOpenVPNCore +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol private let log = SwiftyBeaver.self diff --git a/Sources/TunnelKitOpenVPN/ControlChannelSerializer.swift b/Sources/TunnelKitOpenVPNProtocol/ControlChannelSerializer.swift similarity index 99% rename from Sources/TunnelKitOpenVPN/ControlChannelSerializer.swift rename to Sources/TunnelKitOpenVPNProtocol/ControlChannelSerializer.swift index 14f0d19..23e061d 100644 --- a/Sources/TunnelKitOpenVPN/ControlChannelSerializer.swift +++ b/Sources/TunnelKitOpenVPNProtocol/ControlChannelSerializer.swift @@ -26,8 +26,9 @@ import Foundation import SwiftyBeaver import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import TunnelKitOpenVPNCore +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol private let log = SwiftyBeaver.self diff --git a/Sources/TunnelKitOpenVPN/CoreConfiguration+OpenVPN.swift b/Sources/TunnelKitOpenVPNProtocol/CoreConfiguration+OpenVPN.swift similarity index 98% rename from Sources/TunnelKitOpenVPN/CoreConfiguration+OpenVPN.swift rename to Sources/TunnelKitOpenVPNProtocol/CoreConfiguration+OpenVPN.swift index a0af610..9f14a63 100644 --- a/Sources/TunnelKitOpenVPN/CoreConfiguration+OpenVPN.swift +++ b/Sources/TunnelKitOpenVPNProtocol/CoreConfiguration+OpenVPN.swift @@ -36,8 +36,8 @@ import Foundation import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol extension CoreConfiguration { struct OpenVPN { diff --git a/Sources/TunnelKitOpenVPN/EncryptionBridge.swift b/Sources/TunnelKitOpenVPNProtocol/EncryptionBridge.swift similarity index 98% rename from Sources/TunnelKitOpenVPN/EncryptionBridge.swift rename to Sources/TunnelKitOpenVPNProtocol/EncryptionBridge.swift index c5002e5..7dd0052 100644 --- a/Sources/TunnelKitOpenVPN/EncryptionBridge.swift +++ b/Sources/TunnelKitOpenVPNProtocol/EncryptionBridge.swift @@ -36,8 +36,9 @@ import Foundation import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import TunnelKitOpenVPNCore +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol extension OpenVPN { class EncryptionBridge { diff --git a/Sources/TunnelKitOpenVPN/OpenVPN.swift b/Sources/TunnelKitOpenVPNProtocol/OpenVPN+PRNG.swift similarity index 88% rename from Sources/TunnelKitOpenVPN/OpenVPN.swift rename to Sources/TunnelKitOpenVPNProtocol/OpenVPN+PRNG.swift index 98619b4..8644b7a 100644 --- a/Sources/TunnelKitOpenVPN/OpenVPN.swift +++ b/Sources/TunnelKitOpenVPNProtocol/OpenVPN+PRNG.swift @@ -1,8 +1,8 @@ // -// OpenVPN.swift +// OpenVPN+PRNG.swift // TunnelKit // -// Created by Davide De Rosa on 5/19/19. +// Created by Davide De Rosa on 11/8/21. // Copyright (c) 2021 Davide De Rosa. All rights reserved. // // https://github.com/passepartoutvpn @@ -25,11 +25,11 @@ import Foundation import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import TunnelKitOpenVPNCore +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol -/// Container for OpenVPN classes. -public class OpenVPN { +extension OpenVPN { /** Initializes the PRNG. Must be issued before using `OpenVPNSession`. @@ -45,5 +45,4 @@ public class OpenVPN { } return CryptoBox.preparePRNG(withSeed: seed.bytes, length: seed.count) } - } diff --git a/Sources/TunnelKitOpenVPN/OpenVPNSession+PIA.swift b/Sources/TunnelKitOpenVPNProtocol/OpenVPNSession+PIA.swift similarity index 99% rename from Sources/TunnelKitOpenVPN/OpenVPNSession+PIA.swift rename to Sources/TunnelKitOpenVPNProtocol/OpenVPNSession+PIA.swift index c66127f..7d9fdba 100644 --- a/Sources/TunnelKitOpenVPN/OpenVPNSession+PIA.swift +++ b/Sources/TunnelKitOpenVPNProtocol/OpenVPNSession+PIA.swift @@ -36,6 +36,7 @@ import Foundation import TunnelKitCore +import TunnelKitOpenVPNCore extension OpenVPNSession { struct PIAHardReset { diff --git a/Sources/TunnelKitOpenVPN/OpenVPNSession.swift b/Sources/TunnelKitOpenVPNProtocol/OpenVPNSession.swift similarity index 99% rename from Sources/TunnelKitOpenVPN/OpenVPNSession.swift rename to Sources/TunnelKitOpenVPNProtocol/OpenVPNSession.swift index aa49204..ba10138 100644 --- a/Sources/TunnelKitOpenVPN/OpenVPNSession.swift +++ b/Sources/TunnelKitOpenVPNProtocol/OpenVPNSession.swift @@ -37,8 +37,9 @@ import Foundation import SwiftyBeaver import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import TunnelKitOpenVPNCore +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol private let log = SwiftyBeaver.self diff --git a/Sources/TunnelKitOpenVPN/Packet.swift b/Sources/TunnelKitOpenVPNProtocol/Packet.swift similarity index 98% rename from Sources/TunnelKitOpenVPN/Packet.swift rename to Sources/TunnelKitOpenVPNProtocol/Packet.swift index fe39802..27d86bf 100644 --- a/Sources/TunnelKitOpenVPN/Packet.swift +++ b/Sources/TunnelKitOpenVPNProtocol/Packet.swift @@ -36,8 +36,9 @@ import Foundation import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import TunnelKitOpenVPNCore +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol /// :nodoc: extension ControlPacket { diff --git a/Sources/TunnelKitOpenVPN/ProtocolMacros.swift b/Sources/TunnelKitOpenVPNProtocol/ProtocolMacros.swift similarity index 98% rename from Sources/TunnelKitOpenVPN/ProtocolMacros.swift rename to Sources/TunnelKitOpenVPNProtocol/ProtocolMacros.swift index ff7c79b..0675c9f 100644 --- a/Sources/TunnelKitOpenVPN/ProtocolMacros.swift +++ b/Sources/TunnelKitOpenVPNProtocol/ProtocolMacros.swift @@ -35,6 +35,7 @@ // import Foundation +import TunnelKitOpenVPNCore extension OpenVPN { class ProtocolMacros { diff --git a/Sources/TunnelKitOpenVPN/PushReply.swift b/Sources/TunnelKitOpenVPNProtocol/PushReply.swift similarity index 99% rename from Sources/TunnelKitOpenVPN/PushReply.swift rename to Sources/TunnelKitOpenVPNProtocol/PushReply.swift index d4a7860..494c63d 100644 --- a/Sources/TunnelKitOpenVPN/PushReply.swift +++ b/Sources/TunnelKitOpenVPNProtocol/PushReply.swift @@ -35,6 +35,7 @@ // import Foundation +import TunnelKitOpenVPNCore extension OpenVPN { struct PushReply: CustomStringConvertible { diff --git a/Sources/TunnelKitOpenVPN/SessionKey.swift b/Sources/TunnelKitOpenVPNProtocol/SessionKey.swift similarity index 98% rename from Sources/TunnelKitOpenVPN/SessionKey.swift rename to Sources/TunnelKitOpenVPNProtocol/SessionKey.swift index 6adaa64..131d1ae 100644 --- a/Sources/TunnelKitOpenVPN/SessionKey.swift +++ b/Sources/TunnelKitOpenVPNProtocol/SessionKey.swift @@ -37,8 +37,9 @@ import Foundation import SwiftyBeaver import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import TunnelKitOpenVPNCore +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol private let log = SwiftyBeaver.self diff --git a/Sources/_TunnelKitUtils/Data+Manipulation.swift b/Sources/__TunnelKitUtils/Data+Manipulation.swift similarity index 100% rename from Sources/_TunnelKitUtils/Data+Manipulation.swift rename to Sources/__TunnelKitUtils/Data+Manipulation.swift diff --git a/Sources/_TunnelKitUtils/NSRegularExpression+Shortcuts.swift b/Sources/__TunnelKitUtils/NSRegularExpression+Shortcuts.swift similarity index 100% rename from Sources/_TunnelKitUtils/NSRegularExpression+Shortcuts.swift rename to Sources/__TunnelKitUtils/NSRegularExpression+Shortcuts.swift diff --git a/Sources/_TunnelKitUtils/Utils.swift b/Sources/__TunnelKitUtils/Utils.swift similarity index 100% rename from Sources/_TunnelKitUtils/Utils.swift rename to Sources/__TunnelKitUtils/Utils.swift diff --git a/Tests/TunnelKitCoreTests/RoutingTests.swift b/Tests/TunnelKitCoreTests/RoutingTests.swift index 76cfaf2..d1c43c7 100644 --- a/Tests/TunnelKitCoreTests/RoutingTests.swift +++ b/Tests/TunnelKitCoreTests/RoutingTests.swift @@ -24,7 +24,7 @@ // import XCTest -import _TunnelKitCoreObjC +import CTunnelKitCore class RoutingTests: XCTestCase { diff --git a/Tests/TunnelKitLZOTests/CompressionTests.swift b/Tests/TunnelKitLZOTests/CompressionTests.swift index 0504714..533f665 100644 --- a/Tests/TunnelKitLZOTests/CompressionTests.swift +++ b/Tests/TunnelKitLZOTests/CompressionTests.swift @@ -25,7 +25,7 @@ import XCTest @testable import TunnelKitCore -import _TunnelKitCoreObjC +import CTunnelKitCore import TunnelKitLZO class CompressionTests: XCTestCase { diff --git a/Tests/TunnelKitOpenVPNTests/AppExtensionTests.swift b/Tests/TunnelKitOpenVPNTests/AppExtensionTests.swift index 3d25a1b..c265d4f 100644 --- a/Tests/TunnelKitOpenVPNTests/AppExtensionTests.swift +++ b/Tests/TunnelKitOpenVPNTests/AppExtensionTests.swift @@ -36,9 +36,12 @@ import XCTest import NetworkExtension -@testable import TunnelKitCore -@testable import TunnelKitOpenVPN -@testable import TunnelKitAppExtension +import TunnelKitCore +import TunnelKitOpenVPNCore +import TunnelKitAppExtension +@testable import TunnelKitOpenVPNAppExtension +import TunnelKitManager +import TunnelKitOpenVPNManager class AppExtensionTests: XCTestCase { @@ -53,8 +56,8 @@ class AppExtensionTests: XCTestCase { } func testConfiguration() { - var builder: OpenVPNTunnelProvider.ConfigurationBuilder! - var cfg: OpenVPNTunnelProvider.Configuration! + var builder: OpenVPNProvider.ConfigurationBuilder! + var cfg: OpenVPNProvider.Configuration! let identifier = "com.example.Provider" let appGroup = "group.com.algoritmico.TunnelKit" @@ -69,7 +72,7 @@ class AppExtensionTests: XCTestCase { sessionBuilder.hostname = hostname sessionBuilder.endpointProtocols = [] sessionBuilder.mtu = 1230 - builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) + builder = OpenVPNProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) XCTAssertNotNil(builder) cfg = builder.build() @@ -147,7 +150,7 @@ class AppExtensionTests: XCTestCase { EndpointProtocol(.udp, 1111), EndpointProtocol(.udp4, 3333) ] - var builder2 = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: builder1.build()) + var builder2 = OpenVPNProvider.ConfigurationBuilder(sessionConfiguration: builder1.build()) builder2.prefersResolvedAddresses = true builder2.resolvedAddresses = [ "82.102.21.218", diff --git a/Tests/TunnelKitOpenVPNTests/ConfigurationParserTests.swift b/Tests/TunnelKitOpenVPNTests/ConfigurationParserTests.swift index dd0027e..1d845b2 100644 --- a/Tests/TunnelKitOpenVPNTests/ConfigurationParserTests.swift +++ b/Tests/TunnelKitOpenVPNTests/ConfigurationParserTests.swift @@ -25,7 +25,7 @@ import XCTest import TunnelKitCore -import TunnelKitOpenVPN +import TunnelKitOpenVPNCore class ConfigurationParserTests: XCTestCase { override func setUp() { diff --git a/Tests/TunnelKitOpenVPNTests/ControlChannelTests.swift b/Tests/TunnelKitOpenVPNTests/ControlChannelTests.swift index 87047d2..61c5735 100644 --- a/Tests/TunnelKitOpenVPNTests/ControlChannelTests.swift +++ b/Tests/TunnelKitOpenVPNTests/ControlChannelTests.swift @@ -25,9 +25,11 @@ import XCTest @testable import TunnelKitCore -import _TunnelKitCoreObjC -@testable import TunnelKitOpenVPN -import _TunnelKitOpenVPNObjC +@testable import TunnelKitOpenVPNCore +@testable import TunnelKitOpenVPNProtocol +@testable import TunnelKitOpenVPNAppExtension +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol class ControlChannelTests: XCTestCase { private let hex = "634a4d2d459d606c8e6abbec168fdcd1871462eaa2eaed84c8f403bdf8c7da737d81b5774cc35fe0a42b38aa053f1335fd4a22d721880433bbb20ae1f2d88315b2d186b3b377685506fa39d85d38da16c2ecc0d631bda64f9d8f5a8d073f18aab97ade23e49ea9e7de86784d1ed5fa356df5f7fa1d163e5537efa8d4ba61239dc301a9aa55de0e06e33a7545f7d0cc153405576464ba92942dafa5fb79c7a60663ff1e7da3122ae09d4561653bef3eeb312ad68b191e2f94cbcf4e21caff0b59f8be86567bd21787070c2dc10a8baf7e87ce2e07d7d7de25ead11bd6d6e6ec030c0a3fd50d2d0ca3c0378022bb642e954868d7b93e18a131ecbb12b0bbedb1ce" diff --git a/Tests/TunnelKitOpenVPNTests/DataPathEncryptionTests.swift b/Tests/TunnelKitOpenVPNTests/DataPathEncryptionTests.swift index 6e679ab..8283b36 100644 --- a/Tests/TunnelKitOpenVPNTests/DataPathEncryptionTests.swift +++ b/Tests/TunnelKitOpenVPNTests/DataPathEncryptionTests.swift @@ -36,8 +36,8 @@ import XCTest @testable import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol class DataPathEncryptionTests: XCTestCase { private let cipherKey = try! SecureRandom.safeData(length: 32) diff --git a/Tests/TunnelKitOpenVPNTests/DataPathPerformanceTests.swift b/Tests/TunnelKitOpenVPNTests/DataPathPerformanceTests.swift index 81a9cff..00e78cd 100644 --- a/Tests/TunnelKitOpenVPNTests/DataPathPerformanceTests.swift +++ b/Tests/TunnelKitOpenVPNTests/DataPathPerformanceTests.swift @@ -36,8 +36,10 @@ import XCTest @testable import TunnelKitCore -@testable import TunnelKitOpenVPN -import _TunnelKitOpenVPNObjC +@testable import TunnelKitOpenVPNCore +@testable import TunnelKitOpenVPNProtocol +@testable import TunnelKitOpenVPNAppExtension +import CTunnelKitOpenVPNProtocol class DataPathPerformanceTests: XCTestCase { private var dataPath: DataPath! diff --git a/Tests/TunnelKitOpenVPNTests/EncryptionPerformanceTests.swift b/Tests/TunnelKitOpenVPNTests/EncryptionPerformanceTests.swift index ce4f336..252d60f 100644 --- a/Tests/TunnelKitOpenVPNTests/EncryptionPerformanceTests.swift +++ b/Tests/TunnelKitOpenVPNTests/EncryptionPerformanceTests.swift @@ -36,8 +36,8 @@ import XCTest @testable import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol class EncryptionPerformanceTests: XCTestCase { private var cbcEncrypter: Encrypter! diff --git a/Tests/TunnelKitOpenVPNTests/EncryptionTests.swift b/Tests/TunnelKitOpenVPNTests/EncryptionTests.swift index 976b3e4..090e5fb 100644 --- a/Tests/TunnelKitOpenVPNTests/EncryptionTests.swift +++ b/Tests/TunnelKitOpenVPNTests/EncryptionTests.swift @@ -36,9 +36,9 @@ import XCTest @testable import TunnelKitCore -import _TunnelKitCoreObjC -import TunnelKitOpenVPN -import _TunnelKitOpenVPNObjC +@testable import TunnelKitOpenVPNCore +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol class EncryptionTests: XCTestCase { private var cipherEncKey: ZeroingData! diff --git a/Tests/TunnelKitOpenVPNTests/LinkTests.swift b/Tests/TunnelKitOpenVPNTests/LinkTests.swift index 16755cd..03e0cd8 100644 --- a/Tests/TunnelKitOpenVPNTests/LinkTests.swift +++ b/Tests/TunnelKitOpenVPNTests/LinkTests.swift @@ -36,7 +36,7 @@ import XCTest @testable import TunnelKitCore -@testable import _TunnelKitCoreObjC +@testable import CTunnelKitCore class LinkTests: XCTestCase { diff --git a/Tests/TunnelKitOpenVPNTests/PacketTests.swift b/Tests/TunnelKitOpenVPNTests/PacketTests.swift index 0a2b8d7..203a202 100644 --- a/Tests/TunnelKitOpenVPNTests/PacketTests.swift +++ b/Tests/TunnelKitOpenVPNTests/PacketTests.swift @@ -25,7 +25,7 @@ import XCTest @testable import TunnelKitCore -import _TunnelKitOpenVPNObjC +import CTunnelKitOpenVPNProtocol class PacketTests: XCTestCase { diff --git a/Tests/TunnelKitOpenVPNTests/PushTests.swift b/Tests/TunnelKitOpenVPNTests/PushTests.swift index 74ba70e..c3659f0 100644 --- a/Tests/TunnelKitOpenVPNTests/PushTests.swift +++ b/Tests/TunnelKitOpenVPNTests/PushTests.swift @@ -25,7 +25,9 @@ import XCTest @testable import TunnelKitCore -@testable import TunnelKitOpenVPN +@testable import TunnelKitOpenVPNCore +@testable import TunnelKitOpenVPNProtocol +@testable import TunnelKitOpenVPNAppExtension private extension OpenVPN.PushReply { func debug() { diff --git a/Tests/TunnelKitOpenVPNTests/StaticKeyTests.swift b/Tests/TunnelKitOpenVPNTests/StaticKeyTests.swift index 885f065..bb8d7e5 100644 --- a/Tests/TunnelKitOpenVPNTests/StaticKeyTests.swift +++ b/Tests/TunnelKitOpenVPNTests/StaticKeyTests.swift @@ -25,7 +25,7 @@ import XCTest @testable import TunnelKitCore -import TunnelKitOpenVPN +import TunnelKitOpenVPNCore class StaticKeyTests: XCTestCase { private let content = """ diff --git a/Tests/TunnelKitOpenVPNTests/TestUtils.swift b/Tests/TunnelKitOpenVPNTests/TestUtils.swift index 491fa8a..cf498e0 100644 --- a/Tests/TunnelKitOpenVPNTests/TestUtils.swift +++ b/Tests/TunnelKitOpenVPNTests/TestUtils.swift @@ -36,8 +36,8 @@ import Foundation @testable import TunnelKitCore -import _TunnelKitCoreObjC -import _TunnelKitOpenVPNObjC +import CTunnelKitCore +import CTunnelKitOpenVPNProtocol public class TestUtils { public static func uniqArray(_ v: [Int]) -> [Int] {