diff --git a/TunnelKit.xcodeproj/project.pbxproj b/TunnelKit.xcodeproj/project.pbxproj index 1bed74a..cf0827f 100644 --- a/TunnelKit.xcodeproj/project.pbxproj +++ b/TunnelKit.xcodeproj/project.pbxproj @@ -80,6 +80,10 @@ 0E58BF5722411F3E006FB157 /* LZO.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E58BF5522411F37006FB157 /* LZO.h */; }; 0E58BF5922411FEF006FB157 /* LZO.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF5822411FEF006FB157 /* LZO.m */; }; 0E58BF5A22411FEF006FB157 /* LZO.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF5822411FEF006FB157 /* LZO.m */; }; + 0E58BF502240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */; }; + 0E58BF512240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */; }; + 0E58BF532240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */; }; + 0E58BF542240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */; }; 0E58F1302138AC2F00A49F27 /* DNSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E58F12F2138AC2F00A49F27 /* DNSTests.swift */; }; 0E749F5F2178885500BB2701 /* SessionProxy+PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E749F5E2178885500BB2701 /* SessionProxy+PIA.swift */; }; 0E749F602178885500BB2701 /* SessionProxy+PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E749F5E2178885500BB2701 /* SessionProxy+PIA.swift */; }; @@ -296,6 +300,8 @@ 0E58BF4922405C2F006FB157 /* StandardLZO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StandardLZO.m; sourceTree = ""; }; 0E58BF5522411F37006FB157 /* LZO.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LZO.h; sourceTree = ""; }; 0E58BF5822411FEF006FB157 /* LZO.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LZO.m; sourceTree = ""; }; + 0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompressionAlgorithmNative.h; sourceTree = ""; }; + 0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+CompressionAlgorithm.swift"; sourceTree = ""; }; 0E58F12F2138AC2F00A49F27 /* DNSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSTests.swift; sourceTree = ""; }; 0E6479DD212EAC96008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 0E6479E0212EACD6008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -582,6 +588,7 @@ 0EFEB42E2006D3C800F81029 /* Allocation.h */, 0EFEB4462006D3C800F81029 /* Allocation.m */, 0E12B2A421454F7F00B4BAE9 /* BidirectionalState.swift */, + 0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */, 0E245D6B2137F73600B012A2 /* CompressionFramingNative.h */, 0E011F872196E2AB00BA59EE /* ConfigurationParser.swift */, 0E39BCE6214B2AB60035E9DE /* ControlPacket.h */, @@ -625,6 +632,7 @@ 0E0C2123212ED29D008AB282 /* SessionError.swift */, 0EFEB43C2006D3C800F81029 /* SessionProxy.swift */, 0EFEB43A2006D3C800F81029 /* SessionProxy+Authenticator.swift */, + 0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */, 0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */, 0E0C2124212ED29D008AB282 /* SessionProxy+Configuration.swift */, 0EFEB42A2006D3C800F81029 /* SessionProxy+EncryptionBridge.swift */, @@ -703,6 +711,7 @@ 0E58BF3722405410006FB157 /* minilzo.h in Headers */, 0E07596E20EF79B400F38FD8 /* CryptoCBC.h in Headers */, 0E58BF3522405410006FB157 /* lzodefs.h in Headers */, + 0E58BF502240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */, 0E07596320EF733F00F38FD8 /* CryptoMacros.h in Headers */, 0EFEB46E2006D3C800F81029 /* TLSBox.h in Headers */, 0E07596B20EF79AB00F38FD8 /* Crypto.h in Headers */, @@ -730,6 +739,7 @@ 0E58BF3822405410006FB157 /* minilzo.h in Headers */, 0E07596F20EF79B400F38FD8 /* CryptoCBC.h in Headers */, 0E58BF3622405410006FB157 /* lzodefs.h in Headers */, + 0E58BF512240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */, 0E07596420EF733F00F38FD8 /* CryptoMacros.h in Headers */, 0EEC49EA20B5F7F6008FEB91 /* ZeroingData.h in Headers */, 0E07596C20EF79AB00F38FD8 /* Crypto.h in Headers */, @@ -1178,6 +1188,7 @@ 0EFEB4782006D3C800F81029 /* TunnelKitProvider+Configuration.swift in Sources */, 0E3E0F212108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */, 0EFEB4752006D3C800F81029 /* Errors.m in Sources */, + 0E58BF532240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */, 0E12B2A521454F7F00B4BAE9 /* BidirectionalState.swift in Sources */, 0EBBF2E52084FE6F00E36B40 /* GenericSocket.swift in Sources */, 0EFEB4762006D3C800F81029 /* DataPath.m in Sources */, @@ -1244,6 +1255,7 @@ 0EFEB4A42006D7F300F81029 /* DataPath.m in Sources */, 0EBBF2E62084FE6F00E36B40 /* GenericSocket.swift in Sources */, 0E3E0F222108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */, + 0E58BF542240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */, 0E12B2A621454F7F00B4BAE9 /* BidirectionalState.swift in Sources */, 0EFEB4912006D7F300F81029 /* TLSBox.m in Sources */, 0EFEB49D2006D7F300F81029 /* IOInterface.swift in Sources */, diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift index 1a0702c..d465506 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift @@ -62,6 +62,7 @@ extension TunnelKitProvider { clientKey: nil, checksEKU: false, compressionFraming: .disabled, + compressionAlgorithm: .disabled, tlsWrap: nil, keepAliveInterval: nil, renegotiatesAfter: nil, @@ -178,6 +179,11 @@ extension TunnelKitProvider { } else { sessionConfigurationBuilder.compressionFraming = ConfigurationBuilder.defaults.sessionConfiguration.compressionFraming } + if let compressionAlgorithmValue = providerConfiguration[S.compressionAlgorithm] as? Int, let compressionAlgorithm = SessionProxy.CompressionAlgorithm(rawValue: compressionAlgorithmValue) { + sessionConfigurationBuilder.compressionAlgorithm = compressionAlgorithm + } else { + sessionConfigurationBuilder.compressionAlgorithm = ConfigurationBuilder.defaults.sessionConfiguration.compressionAlgorithm + } if let tlsWrapData = providerConfiguration[S.tlsWrap] as? Data { do { sessionConfigurationBuilder.tlsWrap = try SessionProxy.TLSWrap.deserialized(tlsWrapData) @@ -248,6 +254,8 @@ extension TunnelKitProvider { static let compressionFraming = "CompressionFraming" + static let compressionAlgorithm = "CompressionAlgorithm" + static let tlsWrap = "TLSWrap" static let keepAlive = "KeepAlive" @@ -408,6 +416,9 @@ extension TunnelKitProvider { dict[S.resolvedAddresses] = resolvedAddresses } dict[S.compressionFraming] = sessionConfiguration.compressionFraming.rawValue + if let compressionAlgorithm = sessionConfiguration.compressionAlgorithm?.rawValue { + dict[S.compressionAlgorithm] = compressionAlgorithm + } if let tlsWrapData = sessionConfiguration.tlsWrap?.serialized() { dict[S.tlsWrap] = tlsWrapData } @@ -479,6 +490,11 @@ extension TunnelKitProvider { } log.info("\tMTU: \(mtu)") log.info("\tCompression framing: \(sessionConfiguration.compressionFraming)") + if let compressionAlgorithm = sessionConfiguration.compressionAlgorithm, compressionAlgorithm != .disabled { + log.info("\tCompression algorithm: \(compressionAlgorithm)") + } else { + log.info("\tCompression algorithm: disabled") + } if let keepAliveSeconds = sessionConfiguration.keepAliveInterval, keepAliveSeconds > 0 { log.info("\tKeep-alive: \(keepAliveSeconds) seconds") } else { diff --git a/TunnelKit/Sources/Core/CompressionAlgorithmNative.h b/TunnelKit/Sources/Core/CompressionAlgorithmNative.h new file mode 100644 index 0000000..36a0bdd --- /dev/null +++ b/TunnelKit/Sources/Core/CompressionAlgorithmNative.h @@ -0,0 +1,32 @@ +// +// CompressionFramingNative.h +// TunnelKit +// +// Created by Davide De Rosa on 3/19/19. +// Copyright (c) 2019 Davide De Rosa. All rights reserved. +// +// https://github.com/keeshux +// +// This file is part of TunnelKit. +// +// TunnelKit is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// TunnelKit is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with TunnelKit. If not, see . +// + +#import + +typedef NS_ENUM(NSInteger, CompressionAlgorithmNative) { + CompressionAlgorithmNativeDisabled, + CompressionAlgorithmNativeLZO, + CompressionAlgorithmNativeOther +}; diff --git a/TunnelKit/Sources/Core/ConfigurationParser.swift b/TunnelKit/Sources/Core/ConfigurationParser.swift index ad2df9b..0a3ef19 100644 --- a/TunnelKit/Sources/Core/ConfigurationParser.swift +++ b/TunnelKit/Sources/Core/ConfigurationParser.swift @@ -141,6 +141,7 @@ public class ConfigurationParser { var cipher: SessionProxy.Cipher? var digest: SessionProxy.Digest? var compressionFraming: SessionProxy.CompressionFraming = .disabled + var compressionAlgorithm: SessionProxy.CompressionAlgorithm = .disabled var optCA: CryptoContainer? var clientCertificate: CryptoContainer? var clientKey: CryptoContainer? @@ -296,13 +297,18 @@ public class ConfigurationParser { isHandled = true compressionFraming = .compLZO - guard let arg = $0.first else { - warning = warning ?? .unsupportedConfiguration(option: line) - return - } - guard arg == "no" else { - unsupportedError = .unsupportedConfiguration(option: line) - return + if !LZOIsSupported() { + guard let arg = $0.first else { + warning = warning ?? .unsupportedConfiguration(option: line) + return + } + guard arg == "no" else { + unsupportedError = .unsupportedConfiguration(option: line) + return + } + } else { + let arg = $0.first + compressionAlgorithm = (arg == "no") ? .disabled : .LZO } } Regex.compress.enumerateArguments(in: line) { @@ -310,6 +316,7 @@ public class ConfigurationParser { compressionFraming = .compress guard $0.isEmpty else { + compressionAlgorithm = .other unsupportedError = .unsupportedConfiguration(option: line) return } @@ -412,6 +419,7 @@ public class ConfigurationParser { sessionBuilder.cipher = cipher ?? .aes128cbc sessionBuilder.digest = digest ?? .sha1 sessionBuilder.compressionFraming = compressionFraming + sessionBuilder.compressionAlgorithm = compressionAlgorithm sessionBuilder.tlsWrap = tlsWrap sessionBuilder.clientCertificate = clientCertificate sessionBuilder.clientKey = clientKey diff --git a/TunnelKit/Sources/Core/DataPath.h b/TunnelKit/Sources/Core/DataPath.h index 36a7003..b55d11f 100644 --- a/TunnelKit/Sources/Core/DataPath.h +++ b/TunnelKit/Sources/Core/DataPath.h @@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN decrypter:(id)decrypter peerId:(uint32_t)peerId // 24-bit, discard most significant byte compressionFraming:(CompressionFramingNative)compressionFraming + compressionAlgorithm:(CompressionAlgorithmNative)compressionAlgorithm maxPackets:(NSInteger)maxPackets usesReplayProtection:(BOOL)usesReplayProtection; diff --git a/TunnelKit/Sources/Core/DataPath.m b/TunnelKit/Sources/Core/DataPath.m index 8e9b2a7..2af19c9 100644 --- a/TunnelKit/Sources/Core/DataPath.m +++ b/TunnelKit/Sources/Core/DataPath.m @@ -82,7 +82,13 @@ return (uint8_t *)addr; } -- (instancetype)initWithEncrypter:(id)encrypter decrypter:(id)decrypter peerId:(uint32_t)peerId compressionFraming:(CompressionFramingNative)compressionFraming maxPackets:(NSInteger)maxPackets usesReplayProtection:(BOOL)usesReplayProtection +- (instancetype)initWithEncrypter:(id)encrypter + decrypter:(id)decrypter + peerId:(uint32_t)peerId + compressionFraming:(CompressionFramingNative)compressionFraming + compressionAlgorithm:(CompressionAlgorithmNative)compressionAlgorithm + maxPackets:(NSInteger)maxPackets + usesReplayProtection:(BOOL)usesReplayProtection { NSParameterAssert(encrypter); NSParameterAssert(decrypter); @@ -111,8 +117,7 @@ [self.decrypter setPeerId:peerId]; [self setCompressionFraming:compressionFraming]; - // FIXME: compress according to compression flag, not just framing - if (LZOIsSupported() && (compressionFraming == CompressionFramingNativeCompLZO)) { + if (LZOIsSupported() && (compressionFraming == CompressionFramingNativeCompLZO) && (compressionAlgorithm == CompressionAlgorithmNativeLZO)) { self.lzo = LZOCreate(); } } diff --git a/TunnelKit/Sources/Core/SessionProxy+CompressionAlgorithm.swift b/TunnelKit/Sources/Core/SessionProxy+CompressionAlgorithm.swift new file mode 100644 index 0000000..916555f --- /dev/null +++ b/TunnelKit/Sources/Core/SessionProxy+CompressionAlgorithm.swift @@ -0,0 +1,66 @@ +// +// SessionProxy+CompressionAlgorithm.swift +// TunnelKit +// +// Created by Davide De Rosa on 3/19/19. +// Copyright (c) 2019 Davide De Rosa. All rights reserved. +// +// https://github.com/keeshux +// +// This file is part of TunnelKit. +// +// TunnelKit is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// TunnelKit is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with TunnelKit. If not, see . +// + +import Foundation +import __TunnelKitNative + +extension SessionProxy { + + /// Defines the type of compression algorithm. + public enum CompressionAlgorithm: Int, Codable, CustomStringConvertible { + + /// No compression. + case disabled + + /// LZO compression. + case LZO + + /// Any other compression algorithm (unsupported). + case other + + var native: CompressionAlgorithmNative { + guard let val = CompressionAlgorithmNative(rawValue: rawValue) else { + fatalError("Unhandled CompressionAlgorithm bridging") + } + return val + } + + // MARK: CustomStringConvertible + + /// :nodoc: + public var description: String { + switch self { + case .disabled: + return "disabled" + + case .LZO: + return "lzo" + + case .other: + return "other" + } + } + } +} diff --git a/TunnelKit/Sources/Core/SessionProxy+Configuration.swift b/TunnelKit/Sources/Core/SessionProxy+Configuration.swift index 54b9068..d1f0225 100644 --- a/TunnelKit/Sources/Core/SessionProxy+Configuration.swift +++ b/TunnelKit/Sources/Core/SessionProxy+Configuration.swift @@ -156,6 +156,9 @@ extension SessionProxy { /// Sets compression framing, disabled by default. public var compressionFraming: CompressionFraming + /// Sets compression algorithm, disabled by default. + public var compressionAlgorithm: CompressionAlgorithm? + /// The optional TLS wrapping. public var tlsWrap: TLSWrap? @@ -180,6 +183,7 @@ extension SessionProxy { clientKey = nil checksEKU = false compressionFraming = .disabled + compressionAlgorithm = .disabled tlsWrap = nil keepAliveInterval = nil renegotiatesAfter = nil @@ -201,6 +205,7 @@ extension SessionProxy { clientKey: clientKey, checksEKU: checksEKU, compressionFraming: compressionFraming, + compressionAlgorithm: compressionAlgorithm, tlsWrap: tlsWrap, keepAliveInterval: keepAliveInterval, renegotiatesAfter: renegotiatesAfter, @@ -234,6 +239,9 @@ extension SessionProxy { /// - Seealso: `SessionProxy.ConfigurationBuilder.compressionFraming` public let compressionFraming: CompressionFraming + /// - Seealso: `SessionProxy.ConfigurationBuilder.compressionAlgorithm` + public let compressionAlgorithm: CompressionAlgorithm? + /// - Seealso: `SessionProxy.ConfigurationBuilder.tlsWrap` public var tlsWrap: TLSWrap? @@ -262,6 +270,7 @@ extension SessionProxy { builder.clientKey = clientKey builder.checksEKU = checksEKU builder.compressionFraming = compressionFraming + builder.compressionAlgorithm = compressionAlgorithm builder.tlsWrap = tlsWrap builder.keepAliveInterval = keepAliveInterval builder.renegotiatesAfter = renegotiatesAfter @@ -282,6 +291,7 @@ extension SessionProxy { (lhs.clientKey == rhs.clientKey) && (lhs.checksEKU == rhs.checksEKU) && (lhs.compressionFraming == rhs.compressionFraming) && + (lhs.compressionAlgorithm == rhs.compressionAlgorithm) && (lhs.keepAliveInterval == rhs.keepAliveInterval) && (lhs.renegotiatesAfter == rhs.renegotiatesAfter) && (lhs.usesPIAPatches == rhs.usesPIAPatches) && diff --git a/TunnelKit/Sources/Core/SessionProxy+PushReply.swift b/TunnelKit/Sources/Core/SessionProxy+PushReply.swift index 773f8dd..8d4baa0 100644 --- a/TunnelKit/Sources/Core/SessionProxy+PushReply.swift +++ b/TunnelKit/Sources/Core/SessionProxy+PushReply.swift @@ -150,8 +150,8 @@ public protocol SessionReply { /// The optional compression framing. var compressionFraming: SessionProxy.CompressionFraming? { get } - /// True if uses compression. - var usesCompression: Bool { get } + /// The optional compression algorithm. + var compressionAlgorithm: SessionProxy.CompressionAlgorithm? { get } /// The optional keep-alive interval. var ping: Int? { get } @@ -217,7 +217,7 @@ extension SessionProxy { let compressionFraming: SessionProxy.CompressionFraming? - let usesCompression: Bool + let compressionAlgorithm: SessionProxy.CompressionAlgorithm? let ping: Int? @@ -246,7 +246,7 @@ extension SessionProxy { var dnsServers: [String] = [] var compressionFraming: SessionProxy.CompressionFraming? - var usesCompression = false + var compressionAlgorithm: SessionProxy.CompressionAlgorithm? var ping: Int? var authToken: String? var peerId: UInt32? @@ -395,11 +395,19 @@ extension SessionProxy { switch $0[0] { case "comp-lzo": compressionFraming = .compLZO - usesCompression = !(($0.count == 2) && ($0[1] == "no")) + if !(($0.count == 2) && ($0[1] == "no")) { + compressionAlgorithm = .LZO + } else { + compressionAlgorithm = .disabled + } case "compress": compressionFraming = .compress - usesCompression = ($0.count > 1) + if $0.count > 1 { + compressionAlgorithm = .other + } else { + compressionAlgorithm = .disabled + } default: break @@ -430,7 +438,7 @@ extension SessionProxy { self.dnsServers = dnsServers self.compressionFraming = compressionFraming - self.usesCompression = usesCompression + self.compressionAlgorithm = compressionAlgorithm self.ping = ping self.authToken = authToken self.peerId = peerId diff --git a/TunnelKit/Sources/Core/SessionProxy.swift b/TunnelKit/Sources/Core/SessionProxy.swift index 6a712d9..59358ee 100644 --- a/TunnelKit/Sources/Core/SessionProxy.swift +++ b/TunnelKit/Sources/Core/SessionProxy.swift @@ -912,9 +912,21 @@ public class SessionProxy { reply = optionalReply log.debug("Received PUSH_REPLY: \"\(reply.maskedDescription)\"") - if let framing = reply.compressionFraming, reply.usesCompression { - log.error("Server has compression enabled and this is currently unsupported (\(framing))") - throw SessionError.serverCompression + if let framing = reply.compressionFraming, let compression = reply.compressionAlgorithm, compression != .disabled { + switch framing { + case .compress: + log.error("Server has new compression enabled and this is currently unsupported (\(framing))") + throw SessionError.serverCompression + + case .compLZO: + if !LZOIsSupported() { + log.error("Server has legacy LZO compression enabled and this was not built into the library (\(framing))") + throw SessionError.serverCompression + } + + default: + break + } } } catch let e { deferStop(.shutdown, e) @@ -1021,6 +1033,10 @@ public class SessionProxy { if let negFraming = pushedFraming { log.info("\tNegotiated compression framing: \(negFraming)") } + let pushedCompression = pushReply.compressionAlgorithm + if let negCompression = pushedCompression { + log.info("\tNegotiated compression algorithm: \(negCompression)") + } if let negPing = pushReply.ping { log.info("\tNegotiated keep-alive: \(negPing) seconds") } @@ -1048,6 +1064,7 @@ public class SessionProxy { decrypter: bridge.decrypter(), peerId: pushReply.peerId ?? PacketPeerIdDisabled, compressionFraming: (pushedFraming ?? configuration.compressionFraming).native, + compressionAlgorithm: (pushedCompression ?? configuration.compressionAlgorithm ?? .disabled).native, maxPackets: link?.packetBufferSize ?? 200, usesReplayProtection: CoreConfiguration.usesReplayProtection ) diff --git a/TunnelKit/Sources/Core/module.modulemap b/TunnelKit/Sources/Core/module.modulemap index b19319e..c17afba 100644 --- a/TunnelKit/Sources/Core/module.modulemap +++ b/TunnelKit/Sources/Core/module.modulemap @@ -45,6 +45,7 @@ module __TunnelKitNative { header "ControlPacket.h" header "ReplayProtector.h" header "CompressionFramingNative.h" + header "CompressionAlgorithmNative.h" header "DataPath.h" header "DataPathCrypto.h" header "LZO.h" diff --git a/TunnelKitTests/ConfigurationParserTests.swift b/TunnelKitTests/ConfigurationParserTests.swift index 3dbf510..61bb49d 100644 --- a/TunnelKitTests/ConfigurationParserTests.swift +++ b/TunnelKitTests/ConfigurationParserTests.swift @@ -57,9 +57,11 @@ class ConfigurationParserTests: XCTestCase { } func testCompression() throws { - XCTAssertNotNil(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo"]).warning) +// XCTAssertNotNil(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo"]).warning) + XCTAssertNil(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo"]).warning) XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo no"])) - XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo yes"])) + XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo yes"])) +// XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo yes"])) XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["compress"])) XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["compress lzo"])) diff --git a/TunnelKitTests/DataPathEncryptionTests.swift b/TunnelKitTests/DataPathEncryptionTests.swift index e38d0d5..e794ec7 100644 --- a/TunnelKitTests/DataPathEncryptionTests.swift +++ b/TunnelKitTests/DataPathEncryptionTests.swift @@ -92,6 +92,7 @@ class DataPathEncryptionTests: XCTestCase { decrypter: dec, peerId: peerId ?? PacketPeerIdDisabled, compressionFraming: .disabled, + compressionAlgorithm: .disabled, maxPackets: 1000, usesReplayProtection: false ) diff --git a/TunnelKitTests/DataPathPerformanceTests.swift b/TunnelKitTests/DataPathPerformanceTests.swift index 1f3d72e..4614c4a 100644 --- a/TunnelKitTests/DataPathPerformanceTests.swift +++ b/TunnelKitTests/DataPathPerformanceTests.swift @@ -59,6 +59,7 @@ class DataPathPerformanceTests: XCTestCase { decrypter: decrypter, peerId: PacketPeerIdDisabled, compressionFraming: .disabled, + compressionAlgorithm: .disabled, maxPackets: 200, usesReplayProtection: false ) diff --git a/TunnelKitTests/PushTests.swift b/TunnelKitTests/PushTests.swift index 6d04723..7075b13 100644 --- a/TunnelKitTests/PushTests.swift +++ b/TunnelKitTests/PushTests.swift @@ -28,8 +28,8 @@ import XCTest private extension SessionReply { func debug() { - print("Compression framing: \(dnsServers)") - print("Compression: \(usesCompression)") + print("Compression framing: \(compressionFraming?.description ?? "none")") + print("Compression algorithm: \(compressionAlgorithm?.description ?? "none")") print("IPv4: \(ipv4?.description ?? "none")") print("IPv6: \(ipv6?.description ?? "none")") print("DNS: \(dnsServers)") @@ -109,27 +109,27 @@ class PushTests: XCTestCase { reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo no"))! reply.debug() XCTAssertEqual(reply.compressionFraming, .compLZO) - XCTAssertFalse(reply.usesCompression) + XCTAssertEqual(reply.compressionAlgorithm, .disabled) reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo"))! reply.debug() XCTAssertEqual(reply.compressionFraming, .compLZO) - XCTAssertTrue(reply.usesCompression) + XCTAssertEqual(reply.compressionAlgorithm, .LZO) reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo yes"))! reply.debug() XCTAssertEqual(reply.compressionFraming, .compLZO) - XCTAssertTrue(reply.usesCompression) + XCTAssertEqual(reply.compressionAlgorithm, .LZO) reply = try! SessionProxy.PushReply(message: msg.appending(",compress"))! reply.debug() XCTAssertEqual(reply.compressionFraming, .compress) - XCTAssertFalse(reply.usesCompression) + XCTAssertEqual(reply.compressionAlgorithm, .disabled) reply = try! SessionProxy.PushReply(message: msg.appending(",compress lz4"))! reply.debug() XCTAssertEqual(reply.compressionFraming, .compress) - XCTAssertTrue(reply.usesCompression) + XCTAssertEqual(reply.compressionAlgorithm, .other) } func testNCP() {