Skip to contentSkip to conversation

Ensure n = 2 is set in key2 structer in tls_crypt_v2_unwrap_client_key

PATCH In review Arne Schwabe 3 participants 3 messages Mar 9, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Ensure n = 2 is set in key2 structer in tls_crypt_v2_unwrap_client_key

The ASSERT in xor_key2 assumes that all methods that load a key2 struct correctly set n=2. However, tls_crypt_v2_unwrap_client_key loads a key without setting n = 2, trigerring the assert.

Closes and reported in https://github.com/OpenVPN/openvpn/issues/272

Change-Id Iaeb163d83b95818e0b26faf9d25e7737dc8ecb23
---
 src/openvpn/tls_crypt.c | 1 +
 1 file changed, 1 insertion(+)
src/openvpn/tls_crypt.c +1 -0
index 8882d5de0..4f22f8af7 100644
@@ -533,6 +533,7 @@ tls_crypt_v2_unwrap_client_key(struct key2 *client_key, struct buffer *metadata,
     }
     memcpy(&client_key->keys, BPTR(&plaintext), sizeof(client_key->keys));
     ASSERT(buf_advance(&plaintext, sizeof(client_key->keys)));
+    client_key->n = 2;
 
     if (!buf_copy(metadata, &plaintext))
     {
Signature · 1 line
2.37.1 (Apple Git-137.1)
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 3 lines · Arne Schwabe

The ASSERT in xor_key2 assumes that all methods that load a key2 struct correctly set n=2. However, tls_crypt_v2_unwrap_client_key loads a key without setting n = 2, trigerring the assert.

trigerring -> triggering

Quoted 5 lines

Closes and reported in https://github.com/OpenVPN/openvpn/issues/272

Change-Id Iaeb163d83b95818e0b26faf9d25e7737dc8ecb23

I can easily reproduce the issue ad verify that indeed the patch fixes it.

By checking the code I can see that we set 'n' whenever we initialize the keys member. However, this was not happening in tls_crypt_v2_unwrap_client_key() thus leading to the assert being triggered.

Quoted 16 lines
---
  src/openvpn/tls_crypt.c | 1 +
  1 file changed, 1 insertion(+)
src/openvpn/tls_crypt.c +1 -0
index 8882d5de0..4f22f8af7 100644
@@ -533,6 +533,7 @@ tls_crypt_v2_unwrap_client_key(struct key2 *client_key, struct buffer *metadata,
      }
      memcpy(&client_key->keys, BPTR(&plaintext), sizeof(client_key->keys));
      ASSERT(buf_advance(&plaintext, sizeof(client_key->keys)));
+    client_key->n = 2;
 
      if (!buf_copy(metadata, &plaintext))
      {
Signature · 1 line
Antonio Quartulli
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: Ensure n = 2 is set in key2 struct in tls_crypt_v2_unwrap_client_key

In reply to Arne Schwabe

Trivial enough :-) - wording fixes applied ("structer", "trigerring").

Interesting that Antonio could reproduce this while it "just works" in my test beds.

Your patch has been applied to the master and release/2.6 branch.

commit 85832307fcb41c229ccb7ba83984726757eb32f7 (master) commit ae6068842854278de70264218516b0e4fcdfc6d9 (release/2.6)

Author: Arne Schwabe
Date:   Thu Mar 9 13:00:31 2023 +0100
     Ensure n = 2 is set in key2 struct in tls_crypt_v2_unwrap_client_key

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26363.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering