From: "plaisthos (Code Review)" Date: Sat, 7 Oct 2023 13:39:03 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <56953870cdd157eab41f06312be9b46c4828a4e0-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="RJlu0hp7/ms="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Print SSL peer signature information in handshake debug details List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --RJlu0hp7/ms= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld,=20 I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/365?usp=3Demail to look at the new patch set (#2). Change subject: Print SSL peer signature information in handshake debug det= ails ...................................................................... Print SSL peer signature information in handshake debug details This is more SSL debug information that most people do not really need or care about. OpenSSL's own s_client also logs them: Peer signing digest: SHA256 Peer signature type: ECDSA The complete message looks like this: Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer ce= rtificate: 2048 bits RSA, signature: RSA-SHA256, server temp key: 253 bits = X25519, peer signing digest/type: SHA256 RSASSA-PSS or when forcing a specific group via tls-groups X448 with a ECDSA server: Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer ce= rtificate: 384 bits ECsecp384r1, signature: ecdsa-with-SHA256, server temp = key: 448 bits X448, peer signing digest/type: SHA384 ECDSA Change-Id: Ib5fc0c4b8f164596681ac5ad73002068ec6de1e5 --- M src/openvpn/openssl_compat.h M src/openvpn/ssl_openssl.c 2 files changed, 80 insertions(+), 3 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/65/365/2 diff --git a/src/openvpn/openssl_compat.h b/src/openvpn/openssl_compat.h index efc85d4..ca52145 100644 --- a/src/openvpn/openssl_compat.h +++ b/src/openvpn/openssl_compat.h @@ -117,6 +117,7 @@ #define EVP_CIPHER_CTX_reset EVP_CIPHER_CTX_init #define X509_get0_notBefore X509_get_notBefore #define X509_get0_notAfter X509_get_notAfter +#define SSL_get_peer_tmp_key SSL_get_server_tmp_key /** * Reset a HMAC context diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index b91ea07..1f51adf 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -2163,12 +2163,86 @@ char pkeybuf[128] =3D { 0 }; print_pkey_details(pkey, pkeybuf, sizeof(pkeybuf)); - openvpn_snprintf(buf, buflen, ", server temp key: %s", + openvpn_snprintf(buf, buflen, ", peer temporary key: %s", pkeybuf); EVP_PKEY_free(pkey); } +#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >=3D 0x10= 10000fL +/** + * Translate an OpenSSL NID into a more human readable name + * @param nid + * @return + */ +static const char * +get_sigtype(int nid) +{ + /* Fix a few OpenSSL names to be better understandable */ + switch (nid) + { + case EVP_PKEY_RSA: + /* will otherwise say rsaEncryption */ + return "RSA"; + + case EVP_PKEY_DSA: + /* dsaEncryption otherwise */ + return "DSA"; + + case EVP_PKEY_EC: + /* will say id-ecPublicKey */ + return "ECDSA"; + + case -1: + return "(error getting name)"; + + default: + return OBJ_nid2sn(nid); + } +} +#endif /* ifndef LIBRESSL_VERSION_NUMBER */ + +/** + * Get the type of the signature that is used by the peer during the + * TLS handshake + */ +static void +print_peer_signature(SSL *ssl, char *buf, size_t buflen) +{ + int peer_sig_nid =3D NID_undef, peer_sig_type_nid =3D NID_undef; + const char *peer_sig =3D ""; + const char *peer_sig_type =3D ""; + + /* Even though these methods use the deprecated NIDs instead of using + * string as new OpenSSL APIs do, there seem to be no API that replaces + * it yet */ + if (SSL_get_peer_signature_nid(ssl, &peer_sig_nid) + && peer_sig_nid !=3D NID_undef) + { + peer_sig =3D OBJ_nid2sn(peer_sig_nid); + } + +#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >=3D 0x101= 0000fL + /* LibreSSL 3.7.x and 3.8.0 weirdly implement this function but fail on + * linking with an unresolved symbol */ + if (SSL_get_peer_signature_type_nid(ssl, &peer_sig_type_nid) + && peer_sig_type_nid !=3D NID_undef) + { + peer_sig_type =3D get_sigtype(peer_sig_type_nid); + } +#endif + + if (peer_sig_nid =3D=3D NID_undef && peer_sig_type_nid =3D=3D NID_unde= f) + { + return; + } + + openvpn_snprintf(buf, buflen, ", peer signing digest/type: %s %s", + peer_sig, peer_sig_type); +} + + + /* ************************************** * * Information functions @@ -2183,8 +2257,9 @@ char s1[256]; char s2[256]; char s3[256]; + char s4[256]; - s1[0] =3D s2[0] =3D s3[0] =3D 0; + s1[0] =3D s2[0] =3D s3[0] =3D s4[0] =3D 0; ciph =3D SSL_get_current_cipher(ks_ssl->ssl); openvpn_snprintf(s1, sizeof(s1), "%s %s, cipher %s %s", prefix, @@ -2199,8 +2274,9 @@ X509_free(cert); } print_server_tempkey(ks_ssl->ssl, s3, sizeof(s3)); + print_peer_signature(ks_ssl->ssl, s4, sizeof(s4)); - msg(D_HANDSHAKE, "%s%s%s", s1, s2, s3); + msg(D_HANDSHAKE, "%s%s%s%s", s1, s2, s3, s4); } void -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/365?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: Ib5fc0c4b8f164596681ac5ad73002068ec6de1e5 Gerrit-Change-Number: 365 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --RJlu0hp7/ms= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos uploaded patch set #2 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/365?usp=3Demail">View Chang= e

Print SSL peer signature information in handshake debug details
This is more SSL debug information that most people do not really needor care about. OpenSSL's own s_client also logs them:

Peer sign= ing digest: SHA256
Peer signature type: ECDSA

The complete messag= e looks like this:

Control Channel: TLSv1.3, cipher TLSv1.3 TLS_A= ES_256_GCM_SHA384, peer certificate: 2048 bits RSA, signature: RSA-SHA256, = server temp key: 253 bits X25519, peer signing digest/type: SHA256 RSASSA-P= SS

or when forcing a specific group via tls-groups X448 with a ECDSA= server:

Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM= _SHA384, peer certificate: 384 bits ECsecp384r1, signature: ecdsa-with-SHA2= 56, server temp key: 448 bits X448, peer signing digest/type: SHA384 ECDSA<= br>
Change-Id: Ib5fc0c4b8f164596681ac5ad73002068ec6de1e5
---
M src= /openvpn/openssl_compat.h
M src/openvpn/ssl_openssl.c
2 files changed= , 80 insertions(+), 3 deletions(-)

git pull ssh://gerrit.openvpn.=
net:29418/openvpn refs/changes/65/365/2
diff --git a/src/openvpn/op=
enssl_compat.h b/src/openvpn/openssl_compat.h
index efc85d4= ..ca52145 100644
--- a/src/openvpn/openssl_compat.h<= br>+++ b/src/openvpn/openssl_compat.h
@@ -117,6 +117,= 7 @@
#define EVP_CIPHER_CTX_reset EVP_CIPHER_CTX_init
#define X509_get0_notBefore X509_get_notBefore
#define X509_get0_notAfter X509_get_notAfter

+#define SSL_get_peer_tmp_key SSL_get_server_tmp_= key

/**
* Reset a HMAC= context
diff --git a/src/openvpn/ssl_openssl.c b/src/openv= pn/ssl_openssl.c
index b91ea07..1f51adf 100644
--- a/src/openvpn/ssl_openssl.c
+++ b/src/openvpn/ssl_o= penssl.c
@@ -2163,12 +2163,86 @@
char = pkeybuf[128] =3D { 0 };
print_pkey_details(pkey, pkeyb= uf, sizeof(pkeybuf));

- openvpn_snprintf(buf, buflen, ", server temp key= : %s",
+ open= vpn_snprintf(buf, buflen, ", peer temporary key: %s",
<= span> pkeybuf);

= EVP_PKEY_free(pkey);
}

+#if !defined(LIBRESSL_VERSION_NUMBER= ) && OPENSSL_VERSION_NUMBER >=3D 0x1010000fL
+/**
+ * Translate an OpenSSL NID into a more human readable= name
+ * @param nid<= /span>
+ * @return+ */
+static const char *
+get_sigtype(int nid)
+{
+ /* Fix a few OpenSSL names to be better understandable */<= /span>
+ switch (nid)
+ {
+ case EVP_PKEY_RSA:
= + /* will otherwise = say rsaEncryption */
= + return "RSA";
+
+ = case EVP_PKEY_DSA:
+ /* dsaEncryption otherwise */
+ return "DSA";
+

+ case EVP_PKEY_EC:
+ /* will say id-ecPublicKey */
+ return &quo= t;ECDSA";
+
+ case -1:<= br>+ return "(e= rror getting name)";
+
+ defau= lt:
+ retu= rn OBJ_nid2sn(nid);
+= }
+}
+#endif /* ifndef LIBRESSL_VERSIO= N_NUMBER */

+<= br>+/**
+ * Get the type of the signature that is = used by the peer during the
+ * TLS handshake
+ */
+static void=
+print_peer_signatur= e(SSL *ssl, char *buf, size_t buflen)
+{
+= int peer_sig_nid =3D NID_undef, peer_sig_type_nid =3D NID_undef;=
+ const char *peer_sig = =3D "";
+ = const char *peer_sig_type =3D "";
+
+ /* Even though these methods use the deprecated NIDs instead of = using
+ * string = as new OpenSSL APIs do, there seem to be no API that replaces
+ * it yet */

+ if (SSL_get_peer_signature_nid(s= sl, &peer_sig_nid)
+ {
+ peer_sig =3D OBJ_nid2sn(peer_sig_nid);
<= span style=3D"color: hsl(120, 100%, 40%);">+ }

+
+#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION= _NUMBER >=3D 0x1010000fL
+ /* LibreSSL 3.7.x and 3.8.0 weirdly implement this function but= fail on
+ * link= ing with an unresolved symbol */
+ if (SSL_get_peer_signature_type_nid(ssl, &peer_sig_typ= e_nid)
+ &= & peer_sig_type_nid !=3D NID_undef)
+ {
+ peer_sig_type =3D get_sigtype(peer_sig_type_nid);
<= span style=3D"color: hsl(120, 100%, 40%);">+ }

+#endif
+
+ = if (peer_sig_nid =3D=3D NID_undef && peer_sig_type_nid =3D=3D NID= _undef)
+ {=
+ return;
= + }
+
+ openvpn_snprintf(buf, buflen, ", peer signing digest/t= ype: %s %s",
+ = peer_sig, peer_sig_type);
+}
+
+
<= span style=3D"color: hsl(120, 100%, 40%);">+
/* **********= ****************************
*
* Inform= ation functions
@@ -2183,8 +2257,9 @@
= char s1[256];
char s2[256];
char = s3[256];
+ char s4= [256];

+ s1[0] =3D s2[0] =3D s3[0] =3D s4[0] =3D 0; ciph =3D SSL_get_current_cipher(ks_ssl->ssl);
openvpn_snprintf(s1, sizeof(s1), "%s %s, cipher %s %s",
prefix,
@@ -2199,8 +22= 74,9 @@
X509_free(cert);
}

print_server_tempkey(ks_ssl->ssl, s3, sizeof(s3));
+ print_peer_signatu= re(ks_ssl->ssl, s4, sizeof(s4));

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

void

To v= iew, visit change 365. To unsubscribe, or for help writing mail filters, visit <= a href=3D"http://gerrit.openvpn.net/settings">settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib5fc0c4b8f164596681ac5ad730= 02068ec6de1e5
Gerrit-Change-Number: 365
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--RJlu0hp7/ms=--