Merge branch 'support-stub-v2'

This commit is contained in:
Davide De Rosa 2021-07-18 22:50:30 +02:00
commit 7a6e97da36
6 changed files with 70 additions and 6 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Added
- Support for `--compress stub-v2`.
### Fixed
- Return error in install completion handler. [#206](https://github.com/passepartoutvpn/tunnelkit/issues/206)

View File

@ -40,6 +40,9 @@ extension OpenVPN {
/// Framing compatible with 2.4 `compress`.
case compress
/// Framing compatible with 2.4 `compress` (version 2, e.g. stub-v2).
case compressV2
var native: CompressionFramingNative {
guard let val = CompressionFramingNative(rawValue: rawValue) else {
fatalError("Unhandled CompressionFraming bridging")
@ -58,6 +61,9 @@ extension OpenVPN {
case .compress:
return "compress"
case .compressV2:
return "compress"
case .compLZO:
return "comp-lzo"
}

View File

@ -28,5 +28,6 @@
typedef NS_ENUM(NSInteger, CompressionFramingNative) {
CompressionFramingNativeDisabled,
CompressionFramingNativeCompLZO,
CompressionFramingNativeCompress
CompressionFramingNativeCompress,
CompressionFramingNativeCompressV2
};

View File

@ -412,7 +412,20 @@ extension OpenVPN {
}
} else {
if let arg = $0.first {
optCompressionAlgorithm = (arg == "lzo") ? .LZO : .other
switch arg {
case "lzo":
optCompressionAlgorithm = .LZO
case "stub":
optCompressionAlgorithm = .disabled
case "stub-v2":
optCompressionFraming = .compressV2
optCompressionAlgorithm = .disabled
default:
optCompressionAlgorithm = .other
}
} else {
optCompressionAlgorithm = .disabled
}

View File

@ -195,13 +195,31 @@
*payloadOffset = 1;
break;
default:
// @"Expected NO_COMPRESS (found %X != %X)", payload[0], DataPacketNoCompress);
case DataPacketV2Indicator:
if (compressionFraming == CompressionFramingNativeCompressV2) {
if (payload[1] != DataPacketV2Uncompressed) {
if (error) {
*error = TunnelKitErrorWithCode(TunnelKitErrorCodeDataPathCompression);
}
return NO;
}
*payloadOffset = 2;
} else {
*payloadOffset = 0;
*headerLength = 0;
}
break;
default:
// @"Expected NO_COMPRESS (found %X != %X)", payload[0], DataPacketNoCompress);
// if (error) {
// *error = TunnelKitErrorWithCode(TunnelKitErrorCodeDataPathCompression);
// }
// return NO;
*payloadOffset = 0;
*headerLength = 0;
break;
}
return YES;
};
@ -244,6 +262,25 @@
self.parsePayloadBlock = parseCompressedBlock;
break;
}
case CompressionFramingNativeCompressV2: {
self.assemblePayloadBlock = ^(uint8_t * packetDest, NSInteger * packetLengthOffset, NSData * payload) {
// assume no compression (v2 algorithms unsupported)
// prepend headers only in case of byte ambiguity
const uint8_t first = *(uint8_t *)payload.bytes;
if (first == DataPacketV2Indicator) {
*packetLengthOffset = 2;
packetDest[0] = DataPacketV2Indicator;
packetDest[1] = DataPacketV2Uncompressed;
} else {
*packetLengthOffset = 0;
}
memcpy(packetDest + *packetLengthOffset, payload.bytes, payload.length);
};
self.parsePayloadBlock = parseCompressedBlock;
break;
}
case CompressionFramingNativeCompLZO: {
self.assemblePayloadBlock = ^(uint8_t * packetDest, NSInteger * packetLengthOffset, NSData * payload) {
NSData *compressedPayload = [weakSelf.lzo compressedDataWithData:payload error:NULL];

View File

@ -62,6 +62,9 @@ typedef NS_ENUM(uint8_t, PacketCode) {
#define DataPacketNoCompressSwap 0xfb
#define DataPacketLZOCompress 0x66
#define DataPacketV2Indicator 0x50
#define DataPacketV2Uncompressed 0x00
extern const uint8_t DataPacketPingData[16];
static inline void PacketOpcodeGet(const uint8_t *from, PacketCode *_Nullable code, uint8_t *_Nullable key)