Fix port-share option with TLS-Crypt v2
PATCH 1/1 Fix port-share option with TLS-Crypt v2
The port-share option assumed that all openvpn initial reset packets are between 14 and 255 bytes long. This is not true for tls-crypt-v2.
--- src/openvpn/ps.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-)
src/openvpn/ps.c +30 -4
@@ -983,10 +983,36 @@ is_openvpn_protocol(const struct buffer *buf)const int len =BLEN (buf);if (len >=3 ) { -return p[0 ] ==0 - && p[1 ] >=14 - && (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V2 <<P_OPCODE_SHIFT ) - || p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V3 <<P_OPCODE_SHIFT )); +if (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V3 <<P_OPCODE_SHIFT )) + { +/* WKc is at least 306 byte (not including metadata): +* +* 16 bit len + 256 bit HMAC + 128 bit IV + 2048 bit Kc = 2448 bit +* +* This is increased by the normal length of client handshake + +* tls-crypt overhead (32) +* +* For metadata tls-crypt-v2.txt does not explicitly specify +* an upper limit but we also have TLS_CRYPT_V2_MAX_WKC_LEN +* as 1024 bytes. We err on the safe side with 255 extra overhead +* +* We don't do the 2 byte check for tls-crypt-v2 because it is very +* unrealistic to have only 2 bytes available. +*/ +int plen = (p[0 ] <<8 ) | p[1 ]; + +return (plen >=352 && plen < (1024 +255 )); + } +else + { +/* first two bytes are the size field. This is an openvpn packet +* between 14 bytes and 255 (otherwise p[1] would be 01 or larger. +* on the hard reset packet key_id is zero, so only the opcode +* part is non-null */ +return p[0 ] ==0 + && p[1 ] >=14 + && (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V2 <<P_OPCODE_SHIFT )); + } }else if (len >=2 ) {
Signature · 1 line
2.26.2
Hi,
Quoted 2 lines · Arne Schwabe
The port-share option assumed that all openvpn initial reset packets are between 14 and 255 bytes long. This is not true for tls-crypt-v2.
Good catch, I totally missed this in the tls-crypt-v2 patch set.
Quoted 11 lines
--- src/openvpn/ps.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-)src/openvpn/ps.c +0
-0@@ -983,10 +983,36 @@ is_openvpn_protocol(const struct buffer *buf)const int len =BLEN (buf);if (len >=3 )
src/openvpn/ps.c is_openvpn_protocol(const struct buffer *buf) · line 990
Quoted 10 lines
src/openvpn/ps.c +5
-4{ -return p[0 ] ==0 - && p[1 ] >=14 - && (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V2 <<P_OPCODE_SHIFT ) - || p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V3 <<P_OPCODE_SHIFT )); +if (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V3 <<P_OPCODE_SHIFT )) + { +/* WKc is at least 306 byte (not including metadata): +* +* 16 bit len + 256 bit HMAC + 128 bit IV + 2048 bit Kc = 2448 bit
The IV is part of the HMAC, so does not need to be counted here. So this this be 2320 bits / 290 bytes.
Quoted 11 lines
src/openvpn/ps.c +11
-0+* +* This is increased by the normal length of client handshake + +* tls-crypt overhead (32) +* +* For metadata tls-crypt-v2.txt does not explicitly specify +* an upper limit but we also have TLS_CRYPT_V2_MAX_WKC_LEN +* as 1024 bytes. We err on the safe side with 255 extra overhead +* +* We don't do the 2 byte check for tls-crypt-v2 because it is very +* unrealistic to have only 2 bytes available. +*/
src/openvpn/ps.c is_openvpn_protocol(const struct buffer *buf) · line 1011
Quoted 10 lines
src/openvpn/ps.c +10
-0+int plen = (p[0 ] <<8 ) | p[1 ]; + +return (plen >=352 && plen < (1024 +255 )); + } +else + { +/* first two bytes are the size field. This is an openvpn packet +* between 14 bytes and 255 (otherwise p[1] would be 01 or larger. +* on the hard reset packet key_id is zero, so only the opcode +* part is non-null */
Instead of explaining the length field in the comment, why not just move the "int plen = (p[0] << 8) | p[1];" outside the if to have the code explain that by itself?
src/openvpn/ps.c is_openvpn_protocol(const struct buffer *buf) · line 1018
Quoted 8 lines
src/openvpn/ps.c +4
-0+return p[0 ] ==0 + && p[1 ] >=14 + && (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V2 <<P_OPCODE_SHIFT )); + } }else if (len >=2 ) {
Thanks,
-Steffan
PATCH v2 1/1 Fix port-share option with TLS-Crypt v2
In reply to Arne SchwabeThe port-share option assumed that all openvpn initial reset packets are between 14 and 255 bytes long. This is not true for tls-crypt-v2.
Patch V2: use correct length for TLS-Crypt v2, use length variable
non-tlscryptv2 test
--- src/openvpn/ps.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)
src/openvpn/ps.c +29 -5
@@ -983,14 +983,38 @@ is_openvpn_protocol(const struct buffer *buf)const int len =BLEN (buf);if (len >=3 ) { -return p[0 ] ==0 - && p[1 ] >=14 - && (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V2 <<P_OPCODE_SHIFT ) - || p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V3 <<P_OPCODE_SHIFT )); +int plen = (p[0 ] <<8 ) | p[1 ]; + +if (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V3 <<P_OPCODE_SHIFT )) + { +/* WKc is at least 290 byte (not including metadata): +* +* 16 bit len + 256 bit HMAC + 2048 bit Kc = 2320 bit +* +* This is increased by the normal length of client handshake + +* tls-crypt overhead (32) +* +* For metadata tls-crypt-v2.txt does not explicitly specify +* an upper limit but we also have TLS_CRYPT_V2_MAX_WKC_LEN +* as 1024 bytes. We err on the safe side with 255 extra overhead +* +* We don't do the 2 byte check for tls-crypt-v2 because it is very +* unrealistic to have only 2 bytes available. +*/ +return (plen >=336 && plen < (1024 +255 )); + } +else + { +/* For non tls-crypt2 we assume the packet length to valid between +* 14 and 255 */ +return plen >=14 && plen <=255 + && (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V2 <<P_OPCODE_SHIFT )); + } }else if (len >=2 ) { -return p[0 ] ==0 && p[1 ] >=14 ; +int plen = (p[0 ] <<8 ) | p[1 ]; +return plen >=14 && plen <=255 ; }else {
Signature · 1 line
2.26.2
Hi,
Quoted 50 lines · Arne Schwabe
The port-share option assumed that all openvpn initial reset packets are between 14 and 255 bytes long. This is not true for tls-crypt-v2.
Patch V2: use correct length for TLS-Crypt v2, use length variable
non-tlscryptv2 testSigned-off-by Arne Schwabe <[email protected]...>--- src/openvpn/ps.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)src/openvpn/ps.c +26
-4@@ -983,14 +983,38 @@ is_openvpn_protocol(const struct buffer *buf)const int len =BLEN (buf);if (len >=3 ) { -return p[0 ] ==0 - && p[1 ] >=14 - && (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V2 <<P_OPCODE_SHIFT ) - || p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V3 <<P_OPCODE_SHIFT )); +int plen = (p[0 ] <<8 ) | p[1 ]; + +if (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V3 <<P_OPCODE_SHIFT )) + { +/* WKc is at least 290 byte (not including metadata): +* +* 16 bit len + 256 bit HMAC + 2048 bit Kc = 2320 bit +* +* This is increased by the normal length of client handshake + +* tls-crypt overhead (32) +* +* For metadata tls-crypt-v2.txt does not explicitly specify +* an upper limit but we also have TLS_CRYPT_V2_MAX_WKC_LEN +* as 1024 bytes. We err on the safe side with 255 extra overhead +* +* We don't do the 2 byte check for tls-crypt-v2 because it is very +* unrealistic to have only 2 bytes available. +*/ +return (plen >=336 && plen < (1024 +255 )); + } +else + { +/* For non tls-crypt2 we assume the packet length to valid between +* 14 and 255 */ +return plen >=14 && plen <=255 + && (p[2 ] == (P_CONTROL_HARD_RESET_CLIENT_V2 <<P_OPCODE_SHIFT ));
src/openvpn/ps.c is_openvpn_protocol(const struct buffer *buf) · line 1020
Quoted 10 lines
src/openvpn/ps.c +3
-1+ } }else if (len >=2 ) { -return p[0 ] ==0 && p[1 ] >=14 ; +int plen = (p[0 ] <<8 ) | p[1 ]; +return plen >=14 && plen <=255 ; }else {
Thanks. This looks good to me now.
Ran some tests to check that this correctly resolves the issue when using --tls-crypt-v2 in combination with --port-share.
-Steffan
Magic heuristics... but if Arne and Steffan agree that this is correct, who am I to dispute it :-) - it passes client tests and is not "obviously wrong".
Your patch has been applied to the master and release/2.5 branch.
commit 1387f52682dcd3789c56c9979ccedca281ff88f4 (master) commit c27f97dc0ac99344659cca57bd048543a9899266 (release/2.5)
Author: Arne Schwabe Date: Mon Nov 30 13:38:13 2020 +0100
Fix port-share option with TLS-Crypt v2
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Steffan Karger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21290.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering