From: "cron2 (Code Review)" Date: Wed, 9 Apr 2025 12:48:35 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <05a1d7bb435bcb9bd41263aa23e399d1c19874c3-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="w8nBhWHRejw="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Also print key agreement when printing negotiated details List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: flichtenheld , openvpn-devel --w8nBhWHRejw= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/93= 8?usp=3Demail ) Change subject: Also print key agreement when printing negotiated details ...................................................................... Also print key agreement when printing negotiated details With TLS 1.0 to 1.2, the used key agreement was depended on the certificates themselves. With TLS 1.3 this is no longer the case but basically always X25519 was used. So this information has not been very interesting so far. With OpenSSL 3.5.0 and the new X25519MLKEM768 hybrid key agreement, the used key agreement group actually becomes interesting information. This commit adds printing this information for OpenSSL 3.0.0+ and uses a compat version for OpenSSL 3.0-3.1 to avoid an additional ifdef in the code itself. Example output with ML-DSA-65 certificates on the server (client output): Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 15616 bits ML-DSA-65, signature: id-ml-dsa-65, peer signing digest/type: mldsa65 id-ml-dsa-65, key agreement: X25519MLKEM768 with an secp384r1 certificate: Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 384 bits ECsecp384r1, signature: ecdsa-with-SHA256, peer signing digest/type: ecdsa_secp384r1_sha384 ECDSA, key agreement: X25519MLKEM768 Change-Id: I90d54853fe1b1d820661cc2c099e07ec5d31ed05 Signed-off-by: Arne Schwabe Acked-by: Gert Doering Message-Id: <20250409122409.17616-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31= 393.html Signed-off-by: Gert Doering --- M src/openvpn/openssl_compat.h M src/openvpn/ssl_openssl.c 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/openvpn/openssl_compat.h b/src/openvpn/openssl_compat.h index e2bd9bf..bd6f09c 100644 --- a/src/openvpn/openssl_compat.h +++ b/src/openvpn/openssl_compat.h @@ -197,6 +197,13 @@ } #endif /* if OPENSSL_VERSION_NUMBER < 0x30500000 && (!defined(LIBRESSL_VER= SION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3050400fL) */ - +#if OPENSSL_VERSION_NUMBER < 0x30200000L && OPENSSL_VERSION_NUMBER >=3D 0x= 30000000L +static inline const char * +SSL_get0_group_name(SSL *s) +{ + int nid =3D SSL_get_negotiated_group(s); + return SSL_group_to_name(s, nid); +} +#endif #endif /* OPENSSL_COMPAT_H_ */ diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 23b0266..d1d5d3e 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -2486,7 +2486,21 @@ peer_sig, peer_sig_type); } - +#if OPENSSL_VERSION_NUMBER >=3D 0x30000000L +void +print_tls_key_agreement_group(SSL *ssl, char *buf, size_t buflen) +{ + const char *groupname =3D SSL_get0_group_name(ssl); + if (!groupname) + { + snprintf(buf, buflen, ", key agreement: (error fetching group)"); + } + else + { + snprintf(buf, buflen, ", key agreement: %s", groupname); + } +} +#endif /* ************************************** * @@ -2503,8 +2517,9 @@ char s2[256]; char s3[256]; char s4[256]; + char s5[256]; - s1[0] =3D s2[0] =3D s3[0] =3D s4[0] =3D 0; + s1[0] =3D s2[0] =3D s3[0] =3D s4[0] =3D s5[0] =3D 0; ciph =3D SSL_get_current_cipher(ks_ssl->ssl); snprintf(s1, sizeof(s1), "%s %s, cipher %s %s", prefix, @@ -2520,8 +2535,11 @@ } print_server_tempkey(ks_ssl->ssl, s3, sizeof(s3)); print_peer_signature(ks_ssl->ssl, s4, sizeof(s4)); +#if OPENSSL_VERSION_NUMBER >=3D 0x30000000L + print_tls_key_agreement_group(ks_ssl->ssl, s5, sizeof(s5)); +#endif - msg(D_HANDSHAKE, "%s%s%s%s", s1, s2, s3, s4); + msg(D_HANDSHAKE, "%s%s%s%s%s", s1, s2, s3, s4, s5); } void -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/938?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I90d54853fe1b1d820661cc2c099e07ec5d31ed05 Gerrit-Change-Number: 938 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --w8nBhWHRejw= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Also print key agreement when printing negotia=
ted details

With TLS 1.0 to 1.2, the used key agreement was depended= on the certificates
themselves. With TLS 1.3 this is no longer the case= but basically always
X25519 was used. So this information has not been= very interesting so far.

With OpenSSL 3.5.0 and the new X25519MLKEM= 768 hybrid key agreement, the used
key agreement group actually becomes = interesting information.

This commit adds printing this information = for OpenSSL 3.0.0+ and uses
a compat version for OpenSSL 3.0-3.1 to avoi= d an additional ifdef in the
code itself.

Example output with ML-= DSA-65 certificates on the server (client output):

Control Channe= l: TLSv1.3, cipher
TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: = 15616
bits ML-DSA-65, signature: id-ml-dsa-65, peer signing
dig= est/type: mldsa65 id-ml-dsa-65,
key agreement: X25519MLKEM768

= with an secp384r1 certificate:

Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 384
bits ECsecp38= 4r1, signature: ecdsa-with-SHA256, peer signing
digest/type: ecdsa_sec= p384r1_sha384 ECDSA,
key agreement: X25519MLKEM768

Change-Id: I= 90d54853fe1b1d820661cc2c099e07ec5d31ed05
Signed-off-by: Arne Schwabe <= ;arne@...1227...>
Acked-by: Gert Doering <gert@...1296...>
M= essage-Id: <20250409122409.17616-1-gert@...1296...>
URL: https://w= ww.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31393.html
Si= gned-off-by: Gert Doering <gert@...1296...>
---
M src/openvpn/o= penssl_compat.h
M src/openvpn/ssl_openssl.c
2 files changed, 29 inser= tions(+), 4 deletions(-)

diff --git a/src/openvpn/openssl_compat.h b/src/openvpn/openssl_compat.h=

index e2bd9bf..bd6f09c 100644
--- a/src/op= envpn/openssl_compat.h
+++ b/src/openvpn/openssl_compat.h
@@ -197,6 +197,13 @@
}
#en= dif /* if OPENSSL_VERSION_NUMBER < 0x30500000 && (!defined(LIBRE= SSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3050400fL) */<= br>
-
= +#if OPENSSL_VERSION_NUMBER <= ; 0x30200000L && OPENSSL_VERSION_NUMBER >=3D 0x30000000L<= br>+static inline const char *<= /span>
+SSL_get0_group_name(= SSL *s)
+{
= + int nid =3D SSL_get_negoti= ated_group(s);
+ r= eturn SSL_group_to_name(s, nid);
+}
+#endi= f

#endif /* OPENSSL_COMPAT_H_ */<= br>diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c=
index 23b0266..d1d5d3e 100644
--- a/src/op= envpn/ssl_openssl.c
+++ b/src/openvpn/ssl_openssl.c<= br>@@ -2486,7 +2486,21 @@
peer_sig, pee= r_sig_type);
}

-
+#if OPENSSL_VERSION_NUMBER >=3D 0x30000000L
+void
+print_tls_key_agreement_group(SSL *ssl, char *buf, siz= e_t buflen)
+{=
+ const char *groupname = =3D SSL_get0_group_name(ssl);
+ if (!groupname)
+ {
+ = snprintf(buf, buflen, ", key agreement: (error fetching group)&quo= t;);
+ }+ else
+ {
+ snprintf(buf, buflen, ", key agreement: %= s", groupname);
= + }
+}
<= span style=3D"color: hsl(120, 100%, 40%);">+#endif

=
/* **************************************
*
@@ -2503,8 +2517,9 @@
char s2[256];
char s3[256];
char s4[256];+ char s5[256];
<= span>

- s1[0] =3D s= 2[0] =3D s3[0] =3D s4[0] =3D 0;
+ s1[0] =3D s2[0] =3D s3[0] =3D s4[0] =3D s5[0] =3D 0;=
ciph =3D SSL_get_current_cipher(ks_ssl->ssl);
<= span> snprintf(s1, sizeof(s1), "%s %s, cipher %s %s",
<= br> prefix,
@@ -2520,8 +2535,11 @@
}
print_server_tempkey(ks_ssl->ssl,= s3, sizeof(s3));
print_peer_signature(ks_ssl->ssl,= s4, sizeof(s4));
+#i= f OPENSSL_VERSION_NUMBER >=3D 0x30000000L
+ print_tls_key_agreement_group(ks_ssl->ssl, = s5, sizeof(s5));
+#en= dif

-= msg(D_HANDSHAKE, "%s%s%s%s", s1, s2, s3, s4);
+ msg(D_HANDSHAKE, "%s%s%s%s= %s", s1, s2, s3, s4, s5);

}
<= br> void

To view, visit change 938. = To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I90d54853fe1b1d820661cc2c099= e07ec5d31ed05
Gerrit-Change-Number: 938
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--w8nBhWHRejw=--