Parse compression from several places
- PUSH_REPLY - .ovpn configuration - TunnelKitProvider
This commit is contained in:
parent
4d6d51818d
commit
0eb0e3e478
@ -80,6 +80,10 @@
|
|||||||
0E58BF5722411F3E006FB157 /* LZO.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E58BF5522411F37006FB157 /* LZO.h */; };
|
0E58BF5722411F3E006FB157 /* LZO.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E58BF5522411F37006FB157 /* LZO.h */; };
|
||||||
0E58BF5922411FEF006FB157 /* LZO.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF5822411FEF006FB157 /* LZO.m */; };
|
0E58BF5922411FEF006FB157 /* LZO.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF5822411FEF006FB157 /* LZO.m */; };
|
||||||
0E58BF5A22411FEF006FB157 /* 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 */; };
|
0E58F1302138AC2F00A49F27 /* DNSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E58F12F2138AC2F00A49F27 /* DNSTests.swift */; };
|
||||||
0E749F5F2178885500BB2701 /* SessionProxy+PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E749F5E2178885500BB2701 /* SessionProxy+PIA.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 */; };
|
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 = "<group>"; };
|
0E58BF4922405C2F006FB157 /* StandardLZO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StandardLZO.m; sourceTree = "<group>"; };
|
||||||
0E58BF5522411F37006FB157 /* LZO.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LZO.h; sourceTree = "<group>"; };
|
0E58BF5522411F37006FB157 /* LZO.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LZO.h; sourceTree = "<group>"; };
|
||||||
0E58BF5822411FEF006FB157 /* LZO.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LZO.m; sourceTree = "<group>"; };
|
0E58BF5822411FEF006FB157 /* LZO.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LZO.m; sourceTree = "<group>"; };
|
||||||
|
0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompressionAlgorithmNative.h; sourceTree = "<group>"; };
|
||||||
|
0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+CompressionAlgorithm.swift"; sourceTree = "<group>"; };
|
||||||
0E58F12F2138AC2F00A49F27 /* DNSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSTests.swift; sourceTree = "<group>"; };
|
0E58F12F2138AC2F00A49F27 /* DNSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSTests.swift; sourceTree = "<group>"; };
|
||||||
0E6479DD212EAC96008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
0E6479DD212EAC96008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
0E6479E0212EACD6008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
0E6479E0212EACD6008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
@ -582,6 +588,7 @@
|
|||||||
0EFEB42E2006D3C800F81029 /* Allocation.h */,
|
0EFEB42E2006D3C800F81029 /* Allocation.h */,
|
||||||
0EFEB4462006D3C800F81029 /* Allocation.m */,
|
0EFEB4462006D3C800F81029 /* Allocation.m */,
|
||||||
0E12B2A421454F7F00B4BAE9 /* BidirectionalState.swift */,
|
0E12B2A421454F7F00B4BAE9 /* BidirectionalState.swift */,
|
||||||
|
0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */,
|
||||||
0E245D6B2137F73600B012A2 /* CompressionFramingNative.h */,
|
0E245D6B2137F73600B012A2 /* CompressionFramingNative.h */,
|
||||||
0E011F872196E2AB00BA59EE /* ConfigurationParser.swift */,
|
0E011F872196E2AB00BA59EE /* ConfigurationParser.swift */,
|
||||||
0E39BCE6214B2AB60035E9DE /* ControlPacket.h */,
|
0E39BCE6214B2AB60035E9DE /* ControlPacket.h */,
|
||||||
@ -625,6 +632,7 @@
|
|||||||
0E0C2123212ED29D008AB282 /* SessionError.swift */,
|
0E0C2123212ED29D008AB282 /* SessionError.swift */,
|
||||||
0EFEB43C2006D3C800F81029 /* SessionProxy.swift */,
|
0EFEB43C2006D3C800F81029 /* SessionProxy.swift */,
|
||||||
0EFEB43A2006D3C800F81029 /* SessionProxy+Authenticator.swift */,
|
0EFEB43A2006D3C800F81029 /* SessionProxy+Authenticator.swift */,
|
||||||
|
0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */,
|
||||||
0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */,
|
0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */,
|
||||||
0E0C2124212ED29D008AB282 /* SessionProxy+Configuration.swift */,
|
0E0C2124212ED29D008AB282 /* SessionProxy+Configuration.swift */,
|
||||||
0EFEB42A2006D3C800F81029 /* SessionProxy+EncryptionBridge.swift */,
|
0EFEB42A2006D3C800F81029 /* SessionProxy+EncryptionBridge.swift */,
|
||||||
@ -703,6 +711,7 @@
|
|||||||
0E58BF3722405410006FB157 /* minilzo.h in Headers */,
|
0E58BF3722405410006FB157 /* minilzo.h in Headers */,
|
||||||
0E07596E20EF79B400F38FD8 /* CryptoCBC.h in Headers */,
|
0E07596E20EF79B400F38FD8 /* CryptoCBC.h in Headers */,
|
||||||
0E58BF3522405410006FB157 /* lzodefs.h in Headers */,
|
0E58BF3522405410006FB157 /* lzodefs.h in Headers */,
|
||||||
|
0E58BF502240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */,
|
||||||
0E07596320EF733F00F38FD8 /* CryptoMacros.h in Headers */,
|
0E07596320EF733F00F38FD8 /* CryptoMacros.h in Headers */,
|
||||||
0EFEB46E2006D3C800F81029 /* TLSBox.h in Headers */,
|
0EFEB46E2006D3C800F81029 /* TLSBox.h in Headers */,
|
||||||
0E07596B20EF79AB00F38FD8 /* Crypto.h in Headers */,
|
0E07596B20EF79AB00F38FD8 /* Crypto.h in Headers */,
|
||||||
@ -730,6 +739,7 @@
|
|||||||
0E58BF3822405410006FB157 /* minilzo.h in Headers */,
|
0E58BF3822405410006FB157 /* minilzo.h in Headers */,
|
||||||
0E07596F20EF79B400F38FD8 /* CryptoCBC.h in Headers */,
|
0E07596F20EF79B400F38FD8 /* CryptoCBC.h in Headers */,
|
||||||
0E58BF3622405410006FB157 /* lzodefs.h in Headers */,
|
0E58BF3622405410006FB157 /* lzodefs.h in Headers */,
|
||||||
|
0E58BF512240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */,
|
||||||
0E07596420EF733F00F38FD8 /* CryptoMacros.h in Headers */,
|
0E07596420EF733F00F38FD8 /* CryptoMacros.h in Headers */,
|
||||||
0EEC49EA20B5F7F6008FEB91 /* ZeroingData.h in Headers */,
|
0EEC49EA20B5F7F6008FEB91 /* ZeroingData.h in Headers */,
|
||||||
0E07596C20EF79AB00F38FD8 /* Crypto.h in Headers */,
|
0E07596C20EF79AB00F38FD8 /* Crypto.h in Headers */,
|
||||||
@ -1178,6 +1188,7 @@
|
|||||||
0EFEB4782006D3C800F81029 /* TunnelKitProvider+Configuration.swift in Sources */,
|
0EFEB4782006D3C800F81029 /* TunnelKitProvider+Configuration.swift in Sources */,
|
||||||
0E3E0F212108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */,
|
0E3E0F212108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */,
|
||||||
0EFEB4752006D3C800F81029 /* Errors.m in Sources */,
|
0EFEB4752006D3C800F81029 /* Errors.m in Sources */,
|
||||||
|
0E58BF532240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */,
|
||||||
0E12B2A521454F7F00B4BAE9 /* BidirectionalState.swift in Sources */,
|
0E12B2A521454F7F00B4BAE9 /* BidirectionalState.swift in Sources */,
|
||||||
0EBBF2E52084FE6F00E36B40 /* GenericSocket.swift in Sources */,
|
0EBBF2E52084FE6F00E36B40 /* GenericSocket.swift in Sources */,
|
||||||
0EFEB4762006D3C800F81029 /* DataPath.m in Sources */,
|
0EFEB4762006D3C800F81029 /* DataPath.m in Sources */,
|
||||||
@ -1244,6 +1255,7 @@
|
|||||||
0EFEB4A42006D7F300F81029 /* DataPath.m in Sources */,
|
0EFEB4A42006D7F300F81029 /* DataPath.m in Sources */,
|
||||||
0EBBF2E62084FE6F00E36B40 /* GenericSocket.swift in Sources */,
|
0EBBF2E62084FE6F00E36B40 /* GenericSocket.swift in Sources */,
|
||||||
0E3E0F222108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */,
|
0E3E0F222108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */,
|
||||||
|
0E58BF542240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */,
|
||||||
0E12B2A621454F7F00B4BAE9 /* BidirectionalState.swift in Sources */,
|
0E12B2A621454F7F00B4BAE9 /* BidirectionalState.swift in Sources */,
|
||||||
0EFEB4912006D7F300F81029 /* TLSBox.m in Sources */,
|
0EFEB4912006D7F300F81029 /* TLSBox.m in Sources */,
|
||||||
0EFEB49D2006D7F300F81029 /* IOInterface.swift in Sources */,
|
0EFEB49D2006D7F300F81029 /* IOInterface.swift in Sources */,
|
||||||
|
@ -62,6 +62,7 @@ extension TunnelKitProvider {
|
|||||||
clientKey: nil,
|
clientKey: nil,
|
||||||
checksEKU: false,
|
checksEKU: false,
|
||||||
compressionFraming: .disabled,
|
compressionFraming: .disabled,
|
||||||
|
compressionAlgorithm: .disabled,
|
||||||
tlsWrap: nil,
|
tlsWrap: nil,
|
||||||
keepAliveInterval: nil,
|
keepAliveInterval: nil,
|
||||||
renegotiatesAfter: nil,
|
renegotiatesAfter: nil,
|
||||||
@ -178,6 +179,11 @@ extension TunnelKitProvider {
|
|||||||
} else {
|
} else {
|
||||||
sessionConfigurationBuilder.compressionFraming = ConfigurationBuilder.defaults.sessionConfiguration.compressionFraming
|
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 {
|
if let tlsWrapData = providerConfiguration[S.tlsWrap] as? Data {
|
||||||
do {
|
do {
|
||||||
sessionConfigurationBuilder.tlsWrap = try SessionProxy.TLSWrap.deserialized(tlsWrapData)
|
sessionConfigurationBuilder.tlsWrap = try SessionProxy.TLSWrap.deserialized(tlsWrapData)
|
||||||
@ -248,6 +254,8 @@ extension TunnelKitProvider {
|
|||||||
|
|
||||||
static let compressionFraming = "CompressionFraming"
|
static let compressionFraming = "CompressionFraming"
|
||||||
|
|
||||||
|
static let compressionAlgorithm = "CompressionAlgorithm"
|
||||||
|
|
||||||
static let tlsWrap = "TLSWrap"
|
static let tlsWrap = "TLSWrap"
|
||||||
|
|
||||||
static let keepAlive = "KeepAlive"
|
static let keepAlive = "KeepAlive"
|
||||||
@ -408,6 +416,9 @@ extension TunnelKitProvider {
|
|||||||
dict[S.resolvedAddresses] = resolvedAddresses
|
dict[S.resolvedAddresses] = resolvedAddresses
|
||||||
}
|
}
|
||||||
dict[S.compressionFraming] = sessionConfiguration.compressionFraming.rawValue
|
dict[S.compressionFraming] = sessionConfiguration.compressionFraming.rawValue
|
||||||
|
if let compressionAlgorithm = sessionConfiguration.compressionAlgorithm?.rawValue {
|
||||||
|
dict[S.compressionAlgorithm] = compressionAlgorithm
|
||||||
|
}
|
||||||
if let tlsWrapData = sessionConfiguration.tlsWrap?.serialized() {
|
if let tlsWrapData = sessionConfiguration.tlsWrap?.serialized() {
|
||||||
dict[S.tlsWrap] = tlsWrapData
|
dict[S.tlsWrap] = tlsWrapData
|
||||||
}
|
}
|
||||||
@ -479,6 +490,11 @@ extension TunnelKitProvider {
|
|||||||
}
|
}
|
||||||
log.info("\tMTU: \(mtu)")
|
log.info("\tMTU: \(mtu)")
|
||||||
log.info("\tCompression framing: \(sessionConfiguration.compressionFraming)")
|
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 {
|
if let keepAliveSeconds = sessionConfiguration.keepAliveInterval, keepAliveSeconds > 0 {
|
||||||
log.info("\tKeep-alive: \(keepAliveSeconds) seconds")
|
log.info("\tKeep-alive: \(keepAliveSeconds) seconds")
|
||||||
} else {
|
} else {
|
||||||
|
32
TunnelKit/Sources/Core/CompressionAlgorithmNative.h
Normal file
32
TunnelKit/Sources/Core/CompressionAlgorithmNative.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
typedef NS_ENUM(NSInteger, CompressionAlgorithmNative) {
|
||||||
|
CompressionAlgorithmNativeDisabled,
|
||||||
|
CompressionAlgorithmNativeLZO,
|
||||||
|
CompressionAlgorithmNativeOther
|
||||||
|
};
|
@ -141,6 +141,7 @@ public class ConfigurationParser {
|
|||||||
var cipher: SessionProxy.Cipher?
|
var cipher: SessionProxy.Cipher?
|
||||||
var digest: SessionProxy.Digest?
|
var digest: SessionProxy.Digest?
|
||||||
var compressionFraming: SessionProxy.CompressionFraming = .disabled
|
var compressionFraming: SessionProxy.CompressionFraming = .disabled
|
||||||
|
var compressionAlgorithm: SessionProxy.CompressionAlgorithm = .disabled
|
||||||
var optCA: CryptoContainer?
|
var optCA: CryptoContainer?
|
||||||
var clientCertificate: CryptoContainer?
|
var clientCertificate: CryptoContainer?
|
||||||
var clientKey: CryptoContainer?
|
var clientKey: CryptoContainer?
|
||||||
@ -296,6 +297,7 @@ public class ConfigurationParser {
|
|||||||
isHandled = true
|
isHandled = true
|
||||||
compressionFraming = .compLZO
|
compressionFraming = .compLZO
|
||||||
|
|
||||||
|
if !LZOIsSupported() {
|
||||||
guard let arg = $0.first else {
|
guard let arg = $0.first else {
|
||||||
warning = warning ?? .unsupportedConfiguration(option: line)
|
warning = warning ?? .unsupportedConfiguration(option: line)
|
||||||
return
|
return
|
||||||
@ -304,12 +306,17 @@ public class ConfigurationParser {
|
|||||||
unsupportedError = .unsupportedConfiguration(option: line)
|
unsupportedError = .unsupportedConfiguration(option: line)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
let arg = $0.first
|
||||||
|
compressionAlgorithm = (arg == "no") ? .disabled : .LZO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Regex.compress.enumerateArguments(in: line) {
|
Regex.compress.enumerateArguments(in: line) {
|
||||||
isHandled = true
|
isHandled = true
|
||||||
compressionFraming = .compress
|
compressionFraming = .compress
|
||||||
|
|
||||||
guard $0.isEmpty else {
|
guard $0.isEmpty else {
|
||||||
|
compressionAlgorithm = .other
|
||||||
unsupportedError = .unsupportedConfiguration(option: line)
|
unsupportedError = .unsupportedConfiguration(option: line)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -412,6 +419,7 @@ public class ConfigurationParser {
|
|||||||
sessionBuilder.cipher = cipher ?? .aes128cbc
|
sessionBuilder.cipher = cipher ?? .aes128cbc
|
||||||
sessionBuilder.digest = digest ?? .sha1
|
sessionBuilder.digest = digest ?? .sha1
|
||||||
sessionBuilder.compressionFraming = compressionFraming
|
sessionBuilder.compressionFraming = compressionFraming
|
||||||
|
sessionBuilder.compressionAlgorithm = compressionAlgorithm
|
||||||
sessionBuilder.tlsWrap = tlsWrap
|
sessionBuilder.tlsWrap = tlsWrap
|
||||||
sessionBuilder.clientCertificate = clientCertificate
|
sessionBuilder.clientCertificate = clientCertificate
|
||||||
sessionBuilder.clientKey = clientKey
|
sessionBuilder.clientKey = clientKey
|
||||||
|
@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
decrypter:(id<DataPathDecrypter>)decrypter
|
decrypter:(id<DataPathDecrypter>)decrypter
|
||||||
peerId:(uint32_t)peerId // 24-bit, discard most significant byte
|
peerId:(uint32_t)peerId // 24-bit, discard most significant byte
|
||||||
compressionFraming:(CompressionFramingNative)compressionFraming
|
compressionFraming:(CompressionFramingNative)compressionFraming
|
||||||
|
compressionAlgorithm:(CompressionAlgorithmNative)compressionAlgorithm
|
||||||
maxPackets:(NSInteger)maxPackets
|
maxPackets:(NSInteger)maxPackets
|
||||||
usesReplayProtection:(BOOL)usesReplayProtection;
|
usesReplayProtection:(BOOL)usesReplayProtection;
|
||||||
|
|
||||||
|
@ -82,7 +82,13 @@
|
|||||||
return (uint8_t *)addr;
|
return (uint8_t *)addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithEncrypter:(id<DataPathEncrypter>)encrypter decrypter:(id<DataPathDecrypter>)decrypter peerId:(uint32_t)peerId compressionFraming:(CompressionFramingNative)compressionFraming maxPackets:(NSInteger)maxPackets usesReplayProtection:(BOOL)usesReplayProtection
|
- (instancetype)initWithEncrypter:(id<DataPathEncrypter>)encrypter
|
||||||
|
decrypter:(id<DataPathDecrypter>)decrypter
|
||||||
|
peerId:(uint32_t)peerId
|
||||||
|
compressionFraming:(CompressionFramingNative)compressionFraming
|
||||||
|
compressionAlgorithm:(CompressionAlgorithmNative)compressionAlgorithm
|
||||||
|
maxPackets:(NSInteger)maxPackets
|
||||||
|
usesReplayProtection:(BOOL)usesReplayProtection
|
||||||
{
|
{
|
||||||
NSParameterAssert(encrypter);
|
NSParameterAssert(encrypter);
|
||||||
NSParameterAssert(decrypter);
|
NSParameterAssert(decrypter);
|
||||||
@ -111,8 +117,7 @@
|
|||||||
[self.decrypter setPeerId:peerId];
|
[self.decrypter setPeerId:peerId];
|
||||||
[self setCompressionFraming:compressionFraming];
|
[self setCompressionFraming:compressionFraming];
|
||||||
|
|
||||||
// FIXME: compress according to compression flag, not just framing
|
if (LZOIsSupported() && (compressionFraming == CompressionFramingNativeCompLZO) && (compressionAlgorithm == CompressionAlgorithmNativeLZO)) {
|
||||||
if (LZOIsSupported() && (compressionFraming == CompressionFramingNativeCompLZO)) {
|
|
||||||
self.lzo = LZOCreate();
|
self.lzo = LZOCreate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -156,6 +156,9 @@ extension SessionProxy {
|
|||||||
/// Sets compression framing, disabled by default.
|
/// Sets compression framing, disabled by default.
|
||||||
public var compressionFraming: CompressionFraming
|
public var compressionFraming: CompressionFraming
|
||||||
|
|
||||||
|
/// Sets compression algorithm, disabled by default.
|
||||||
|
public var compressionAlgorithm: CompressionAlgorithm?
|
||||||
|
|
||||||
/// The optional TLS wrapping.
|
/// The optional TLS wrapping.
|
||||||
public var tlsWrap: TLSWrap?
|
public var tlsWrap: TLSWrap?
|
||||||
|
|
||||||
@ -180,6 +183,7 @@ extension SessionProxy {
|
|||||||
clientKey = nil
|
clientKey = nil
|
||||||
checksEKU = false
|
checksEKU = false
|
||||||
compressionFraming = .disabled
|
compressionFraming = .disabled
|
||||||
|
compressionAlgorithm = .disabled
|
||||||
tlsWrap = nil
|
tlsWrap = nil
|
||||||
keepAliveInterval = nil
|
keepAliveInterval = nil
|
||||||
renegotiatesAfter = nil
|
renegotiatesAfter = nil
|
||||||
@ -201,6 +205,7 @@ extension SessionProxy {
|
|||||||
clientKey: clientKey,
|
clientKey: clientKey,
|
||||||
checksEKU: checksEKU,
|
checksEKU: checksEKU,
|
||||||
compressionFraming: compressionFraming,
|
compressionFraming: compressionFraming,
|
||||||
|
compressionAlgorithm: compressionAlgorithm,
|
||||||
tlsWrap: tlsWrap,
|
tlsWrap: tlsWrap,
|
||||||
keepAliveInterval: keepAliveInterval,
|
keepAliveInterval: keepAliveInterval,
|
||||||
renegotiatesAfter: renegotiatesAfter,
|
renegotiatesAfter: renegotiatesAfter,
|
||||||
@ -234,6 +239,9 @@ extension SessionProxy {
|
|||||||
/// - Seealso: `SessionProxy.ConfigurationBuilder.compressionFraming`
|
/// - Seealso: `SessionProxy.ConfigurationBuilder.compressionFraming`
|
||||||
public let compressionFraming: CompressionFraming
|
public let compressionFraming: CompressionFraming
|
||||||
|
|
||||||
|
/// - Seealso: `SessionProxy.ConfigurationBuilder.compressionAlgorithm`
|
||||||
|
public let compressionAlgorithm: CompressionAlgorithm?
|
||||||
|
|
||||||
/// - Seealso: `SessionProxy.ConfigurationBuilder.tlsWrap`
|
/// - Seealso: `SessionProxy.ConfigurationBuilder.tlsWrap`
|
||||||
public var tlsWrap: TLSWrap?
|
public var tlsWrap: TLSWrap?
|
||||||
|
|
||||||
@ -262,6 +270,7 @@ extension SessionProxy {
|
|||||||
builder.clientKey = clientKey
|
builder.clientKey = clientKey
|
||||||
builder.checksEKU = checksEKU
|
builder.checksEKU = checksEKU
|
||||||
builder.compressionFraming = compressionFraming
|
builder.compressionFraming = compressionFraming
|
||||||
|
builder.compressionAlgorithm = compressionAlgorithm
|
||||||
builder.tlsWrap = tlsWrap
|
builder.tlsWrap = tlsWrap
|
||||||
builder.keepAliveInterval = keepAliveInterval
|
builder.keepAliveInterval = keepAliveInterval
|
||||||
builder.renegotiatesAfter = renegotiatesAfter
|
builder.renegotiatesAfter = renegotiatesAfter
|
||||||
@ -282,6 +291,7 @@ extension SessionProxy {
|
|||||||
(lhs.clientKey == rhs.clientKey) &&
|
(lhs.clientKey == rhs.clientKey) &&
|
||||||
(lhs.checksEKU == rhs.checksEKU) &&
|
(lhs.checksEKU == rhs.checksEKU) &&
|
||||||
(lhs.compressionFraming == rhs.compressionFraming) &&
|
(lhs.compressionFraming == rhs.compressionFraming) &&
|
||||||
|
(lhs.compressionAlgorithm == rhs.compressionAlgorithm) &&
|
||||||
(lhs.keepAliveInterval == rhs.keepAliveInterval) &&
|
(lhs.keepAliveInterval == rhs.keepAliveInterval) &&
|
||||||
(lhs.renegotiatesAfter == rhs.renegotiatesAfter) &&
|
(lhs.renegotiatesAfter == rhs.renegotiatesAfter) &&
|
||||||
(lhs.usesPIAPatches == rhs.usesPIAPatches) &&
|
(lhs.usesPIAPatches == rhs.usesPIAPatches) &&
|
||||||
|
@ -150,8 +150,8 @@ public protocol SessionReply {
|
|||||||
/// The optional compression framing.
|
/// The optional compression framing.
|
||||||
var compressionFraming: SessionProxy.CompressionFraming? { get }
|
var compressionFraming: SessionProxy.CompressionFraming? { get }
|
||||||
|
|
||||||
/// True if uses compression.
|
/// The optional compression algorithm.
|
||||||
var usesCompression: Bool { get }
|
var compressionAlgorithm: SessionProxy.CompressionAlgorithm? { get }
|
||||||
|
|
||||||
/// The optional keep-alive interval.
|
/// The optional keep-alive interval.
|
||||||
var ping: Int? { get }
|
var ping: Int? { get }
|
||||||
@ -217,7 +217,7 @@ extension SessionProxy {
|
|||||||
|
|
||||||
let compressionFraming: SessionProxy.CompressionFraming?
|
let compressionFraming: SessionProxy.CompressionFraming?
|
||||||
|
|
||||||
let usesCompression: Bool
|
let compressionAlgorithm: SessionProxy.CompressionAlgorithm?
|
||||||
|
|
||||||
let ping: Int?
|
let ping: Int?
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ extension SessionProxy {
|
|||||||
|
|
||||||
var dnsServers: [String] = []
|
var dnsServers: [String] = []
|
||||||
var compressionFraming: SessionProxy.CompressionFraming?
|
var compressionFraming: SessionProxy.CompressionFraming?
|
||||||
var usesCompression = false
|
var compressionAlgorithm: SessionProxy.CompressionAlgorithm?
|
||||||
var ping: Int?
|
var ping: Int?
|
||||||
var authToken: String?
|
var authToken: String?
|
||||||
var peerId: UInt32?
|
var peerId: UInt32?
|
||||||
@ -395,11 +395,19 @@ extension SessionProxy {
|
|||||||
switch $0[0] {
|
switch $0[0] {
|
||||||
case "comp-lzo":
|
case "comp-lzo":
|
||||||
compressionFraming = .compLZO
|
compressionFraming = .compLZO
|
||||||
usesCompression = !(($0.count == 2) && ($0[1] == "no"))
|
if !(($0.count == 2) && ($0[1] == "no")) {
|
||||||
|
compressionAlgorithm = .LZO
|
||||||
|
} else {
|
||||||
|
compressionAlgorithm = .disabled
|
||||||
|
}
|
||||||
|
|
||||||
case "compress":
|
case "compress":
|
||||||
compressionFraming = .compress
|
compressionFraming = .compress
|
||||||
usesCompression = ($0.count > 1)
|
if $0.count > 1 {
|
||||||
|
compressionAlgorithm = .other
|
||||||
|
} else {
|
||||||
|
compressionAlgorithm = .disabled
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
@ -430,7 +438,7 @@ extension SessionProxy {
|
|||||||
|
|
||||||
self.dnsServers = dnsServers
|
self.dnsServers = dnsServers
|
||||||
self.compressionFraming = compressionFraming
|
self.compressionFraming = compressionFraming
|
||||||
self.usesCompression = usesCompression
|
self.compressionAlgorithm = compressionAlgorithm
|
||||||
self.ping = ping
|
self.ping = ping
|
||||||
self.authToken = authToken
|
self.authToken = authToken
|
||||||
self.peerId = peerId
|
self.peerId = peerId
|
||||||
|
@ -912,9 +912,21 @@ public class SessionProxy {
|
|||||||
reply = optionalReply
|
reply = optionalReply
|
||||||
log.debug("Received PUSH_REPLY: \"\(reply.maskedDescription)\"")
|
log.debug("Received PUSH_REPLY: \"\(reply.maskedDescription)\"")
|
||||||
|
|
||||||
if let framing = reply.compressionFraming, reply.usesCompression {
|
if let framing = reply.compressionFraming, let compression = reply.compressionAlgorithm, compression != .disabled {
|
||||||
log.error("Server has compression enabled and this is currently unsupported (\(framing))")
|
switch framing {
|
||||||
|
case .compress:
|
||||||
|
log.error("Server has new compression enabled and this is currently unsupported (\(framing))")
|
||||||
throw SessionError.serverCompression
|
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 {
|
} catch let e {
|
||||||
deferStop(.shutdown, e)
|
deferStop(.shutdown, e)
|
||||||
@ -1021,6 +1033,10 @@ public class SessionProxy {
|
|||||||
if let negFraming = pushedFraming {
|
if let negFraming = pushedFraming {
|
||||||
log.info("\tNegotiated compression framing: \(negFraming)")
|
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 {
|
if let negPing = pushReply.ping {
|
||||||
log.info("\tNegotiated keep-alive: \(negPing) seconds")
|
log.info("\tNegotiated keep-alive: \(negPing) seconds")
|
||||||
}
|
}
|
||||||
@ -1048,6 +1064,7 @@ public class SessionProxy {
|
|||||||
decrypter: bridge.decrypter(),
|
decrypter: bridge.decrypter(),
|
||||||
peerId: pushReply.peerId ?? PacketPeerIdDisabled,
|
peerId: pushReply.peerId ?? PacketPeerIdDisabled,
|
||||||
compressionFraming: (pushedFraming ?? configuration.compressionFraming).native,
|
compressionFraming: (pushedFraming ?? configuration.compressionFraming).native,
|
||||||
|
compressionAlgorithm: (pushedCompression ?? configuration.compressionAlgorithm ?? .disabled).native,
|
||||||
maxPackets: link?.packetBufferSize ?? 200,
|
maxPackets: link?.packetBufferSize ?? 200,
|
||||||
usesReplayProtection: CoreConfiguration.usesReplayProtection
|
usesReplayProtection: CoreConfiguration.usesReplayProtection
|
||||||
)
|
)
|
||||||
|
@ -45,6 +45,7 @@ module __TunnelKitNative {
|
|||||||
header "ControlPacket.h"
|
header "ControlPacket.h"
|
||||||
header "ReplayProtector.h"
|
header "ReplayProtector.h"
|
||||||
header "CompressionFramingNative.h"
|
header "CompressionFramingNative.h"
|
||||||
|
header "CompressionAlgorithmNative.h"
|
||||||
header "DataPath.h"
|
header "DataPath.h"
|
||||||
header "DataPathCrypto.h"
|
header "DataPathCrypto.h"
|
||||||
header "LZO.h"
|
header "LZO.h"
|
||||||
|
@ -57,9 +57,11 @@ class ConfigurationParserTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testCompression() throws {
|
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"]))
|
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"]))
|
XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["compress"]))
|
||||||
XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["compress lzo"]))
|
XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["compress lzo"]))
|
||||||
|
@ -92,6 +92,7 @@ class DataPathEncryptionTests: XCTestCase {
|
|||||||
decrypter: dec,
|
decrypter: dec,
|
||||||
peerId: peerId ?? PacketPeerIdDisabled,
|
peerId: peerId ?? PacketPeerIdDisabled,
|
||||||
compressionFraming: .disabled,
|
compressionFraming: .disabled,
|
||||||
|
compressionAlgorithm: .disabled,
|
||||||
maxPackets: 1000,
|
maxPackets: 1000,
|
||||||
usesReplayProtection: false
|
usesReplayProtection: false
|
||||||
)
|
)
|
||||||
|
@ -59,6 +59,7 @@ class DataPathPerformanceTests: XCTestCase {
|
|||||||
decrypter: decrypter,
|
decrypter: decrypter,
|
||||||
peerId: PacketPeerIdDisabled,
|
peerId: PacketPeerIdDisabled,
|
||||||
compressionFraming: .disabled,
|
compressionFraming: .disabled,
|
||||||
|
compressionAlgorithm: .disabled,
|
||||||
maxPackets: 200,
|
maxPackets: 200,
|
||||||
usesReplayProtection: false
|
usesReplayProtection: false
|
||||||
)
|
)
|
||||||
|
@ -28,8 +28,8 @@ import XCTest
|
|||||||
|
|
||||||
private extension SessionReply {
|
private extension SessionReply {
|
||||||
func debug() {
|
func debug() {
|
||||||
print("Compression framing: \(dnsServers)")
|
print("Compression framing: \(compressionFraming?.description ?? "none")")
|
||||||
print("Compression: \(usesCompression)")
|
print("Compression algorithm: \(compressionAlgorithm?.description ?? "none")")
|
||||||
print("IPv4: \(ipv4?.description ?? "none")")
|
print("IPv4: \(ipv4?.description ?? "none")")
|
||||||
print("IPv6: \(ipv6?.description ?? "none")")
|
print("IPv6: \(ipv6?.description ?? "none")")
|
||||||
print("DNS: \(dnsServers)")
|
print("DNS: \(dnsServers)")
|
||||||
@ -109,27 +109,27 @@ class PushTests: XCTestCase {
|
|||||||
reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo no"))!
|
reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo no"))!
|
||||||
reply.debug()
|
reply.debug()
|
||||||
XCTAssertEqual(reply.compressionFraming, .compLZO)
|
XCTAssertEqual(reply.compressionFraming, .compLZO)
|
||||||
XCTAssertFalse(reply.usesCompression)
|
XCTAssertEqual(reply.compressionAlgorithm, .disabled)
|
||||||
|
|
||||||
reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo"))!
|
reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo"))!
|
||||||
reply.debug()
|
reply.debug()
|
||||||
XCTAssertEqual(reply.compressionFraming, .compLZO)
|
XCTAssertEqual(reply.compressionFraming, .compLZO)
|
||||||
XCTAssertTrue(reply.usesCompression)
|
XCTAssertEqual(reply.compressionAlgorithm, .LZO)
|
||||||
|
|
||||||
reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo yes"))!
|
reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo yes"))!
|
||||||
reply.debug()
|
reply.debug()
|
||||||
XCTAssertEqual(reply.compressionFraming, .compLZO)
|
XCTAssertEqual(reply.compressionFraming, .compLZO)
|
||||||
XCTAssertTrue(reply.usesCompression)
|
XCTAssertEqual(reply.compressionAlgorithm, .LZO)
|
||||||
|
|
||||||
reply = try! SessionProxy.PushReply(message: msg.appending(",compress"))!
|
reply = try! SessionProxy.PushReply(message: msg.appending(",compress"))!
|
||||||
reply.debug()
|
reply.debug()
|
||||||
XCTAssertEqual(reply.compressionFraming, .compress)
|
XCTAssertEqual(reply.compressionFraming, .compress)
|
||||||
XCTAssertFalse(reply.usesCompression)
|
XCTAssertEqual(reply.compressionAlgorithm, .disabled)
|
||||||
|
|
||||||
reply = try! SessionProxy.PushReply(message: msg.appending(",compress lz4"))!
|
reply = try! SessionProxy.PushReply(message: msg.appending(",compress lz4"))!
|
||||||
reply.debug()
|
reply.debug()
|
||||||
XCTAssertEqual(reply.compressionFraming, .compress)
|
XCTAssertEqual(reply.compressionFraming, .compress)
|
||||||
XCTAssertTrue(reply.usesCompression)
|
XCTAssertEqual(reply.compressionAlgorithm, .other)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNCP() {
|
func testNCP() {
|
||||||
|
Loading…
Reference in New Issue
Block a user