Skip to contentSkip to conversation

protocol_dump: support tls-crypt

PATCH In review Reynir 3 participants 3 messages Oct 30, 2023 – Nov 20, 2023

lore
Share & tools
lore

Reynir

author
#0 lore raw

PATCH 1/1 protocol_dump: support tls-crypt

Dear list,

Please find attached a patch to add support for tls-crypt packets in protocol_dump. Currently, protocol_dump will print garbage for tls-crypt packets.

This patch makes protocol_dump print the clear text parts of the packet such as the auth tag and replay packet id. It does not try to print the wKc for HARD_RESET_CLIENT_V3 or CONTROL_WKC_V1 packets. A previous iteration, not submitted to the list, printed ENCRYPTED placeholders for ack list and DATA, but I decided to cut down on the noise instead.

This is my first patch submitted to openvpn so please bear with me.

Best,
Reynir Björnsson

From 11926a6234b860a09965e5a074460abe4b4f6e71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= <[email protected]>
Date: Thu, 26 Oct 2023 16:55:32 +0200
Subject: [PATCH] protocol_dump: tls-crypt support

---
 src/openvpn/openvpn.h |  3 ++-
 src/openvpn/ssl.c     | 26 ++++++++++++++++++++++++++
 src/openvpn/ssl.h     |  1 +
 3 files changed, 29 insertions(+), 1 deletion(-)
src/openvpn/openvpn.h +2 -1
index 077effeb..0816360d 100644
@@ -544,7 +544,8 @@ struct context
 #define PROTO_DUMP(buf, gc) protocol_dump((buf), \
                                           PROTO_DUMP_FLAGS   \
                                           |(c->c2.tls_multi ? PD_TLS : 0)   \
-                                          |(c->options.tls_auth_file ? md_kt_size(c->c1.ks.key_type.digest) : 0), \
+                                          |(c->options.tls_auth_file ? md_kt_size(c->c1.ks.key_type.digest) : 0) \
+                                          |(c->options.tls_crypt_file || c->options.tls_crypt_v2_file ? PD_TLS_CRYPT : 0), \
                                           gc)
 
 /* this represents "disabled peer-id" */
src/openvpn/ssl.c +26 -0
index 5e6205cc..8bd3cb00 100644
@@ -4202,6 +4202,32 @@ protocol_dump(struct buffer *buffer, unsigned int flags, struct gc_arena *gc)
         }
         buf_printf(&out, " pid=%s", packet_id_net_print(&pin, (flags & PD_VERBOSE), gc));
     }
+    /*
+     * packet_id + tls-crypt hmac
+     */
+    if (flags & PD_TLS_CRYPT)
+    {
+        struct packet_id_net pin;
+        uint8_t tls_crypt_hmac[TLS_CRYPT_TAG_SIZE];
+
+        if (!packet_id_read(&pin, &buf, true))
+        {
+            goto done;
+        }
+        buf_printf(&out, " pid=%s", packet_id_net_print(&pin, (flags & PD_VERBOSE), gc));
+        if (!buf_read(&buf, tls_crypt_hmac, TLS_CRYPT_TAG_SIZE))
+        {
+            goto done;
+        }
+        if (flags & PD_VERBOSE)
+        {
+            buf_printf(&out, " tls_crypt_hmac=%s", format_hex(tls_crypt_hmac, TLS_CRYPT_TAG_SIZE, 0, gc));
+        }
+        /*
+         * Remainder is encrypted and optional wKc
+         */
+        goto done;
+    }
 
     /*
      * ACK list
src/openvpn/ssl.h +1 -0
index 3c40fbed..e8427461 100644
@@ -525,6 +525,7 @@ tls_set_single_session(struct tls_multi *multi)
 #define PD_SHOW_DATA               (1<<8)
 #define PD_TLS                     (1<<9)
 #define PD_VERBOSE                 (1<<10)
+#define PD_TLS_CRYPT               (1<<11)
 
 const char *protocol_dump(struct buffer *buffer,
                           unsigned int flags,
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw

Am 30.10.23 um 11:58 schrieb Reynir:

Quoted 8 lines

Dear list,

Please find attached a patch to add support for tls-crypt packets in protocol_dump. Currently, protocol_dump will print garbage for tls-crypt packets.

This patch makes protocol_dump print the clear text parts of the packet such as the auth tag and replay packet id. It does not try to print the wKc for HARD_RESET_CLIENT_V3 or CONTROL_WKC_V1 packets. A previous iteration, not submitted to the list, printed ENCRYPTED placeholders for ack list and DATA, but I decided to cut down on the noise instead.

This is my first patch submitted to openvpn so please bear with me.

Code looks good and works fine here.

#2 lore raw

[Openvpn-devel] [PATCH applied] Re: protocol_dump: tls-crypt support

In reply to Reynir

Your patch has been applied to the master and release/2.6 branch ("printing garbage" is arguably a bug that needs fixing).

I have taken parts of the "mail mail" into the commit message, and added the "signed-off-by:" that the OpenVPN project wants.

I haven't actually tested it beyond "does it compile" - it looks good, and Arne is the current authority on tls-crypt anyway.

commit 227799b8345128dd3adf2029323457804209fe93 (master) commit 0a39d1c1e2582330db09052bcf0e32bbf5bafde2 (release/2.6)

Author: Reynir Björnsson
Date:   Thu Oct 26 16:55:32 2023 +0200
     protocol_dump: tls-crypt support

     Signed-off-by: Reynir Björnsson <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg27310.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering