Print server temp key details
PATCH 1/3 Print server temp key details
--- src/openvpn/ssl_openssl.c | 56 ++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 12 deletions(-)
src/openvpn/ssl_openssl.c +44 -12
@@ -2050,18 +2050,11 @@ key_state_read_plaintext(struct key_state_ssl *ks_ssl, struct buffer *buf)return ret; } -/** -* Print human readable information about the certifcate into buf -* @param cert the certificate being used -* @param buf output buffer -* @param buflen output buffer length -*/ static void -print_cert_details (X509 *cert,char *buf,size_t buflen) +print_pkey_details (EVP_PKEY *pkey,char *buf,size_t buflen) {const char *curve ="" ;const char *type ="(error getting type)" ; -EVP_PKEY *pkey =X509_get_pubkey (cert);if (pkey ==NULL ) {
@@ -2124,6 +2117,23 @@ print_cert_details(X509 *cert, char *buf, size_t buflen)#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } +openvpn_snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); +} + +/** +* Print human readable information about the certifcate into buf +* @param cert the certificate being used +* @param buf output buffer +* @param buflen output buffer length +*/ +static void +print_cert_details (X509 *cert,char *buf,size_t buflen) +{ +EVP_PKEY *pkey =X509_get_pubkey (cert); +char pkeybuf[128 ] = {0 }; +print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); +char sig[128 ] = {0 };int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 )
@@ -2132,8 +2142,27 @@ print_cert_details(X509 *cert, char *buf, size_t buflen) OBJ_nid2sn(signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %d bit %s%s%s" , -EVP_PKEY_bits (pkey), type, curve, sig); +openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig); + +EVP_PKEY_free (pkey); +} + +static void +print_server_tempkey (SSL *ssl,char *buf,size_t buflen) +{ +EVP_PKEY *pkey =NULL ; +SSL_get_peer_tmp_key (ssl, &pkey); +if (!pkey) + { +return ; + } + +char pkeybuf[128 ] = {0 }; +print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); + +openvpn_snprintf (buf, buflen,", server temp key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2151,8 +2180,9 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix)const SSL_CIPHER *ciph;char s1[256 ];char s2[256 ]; +char s3[256 ]; - s1[0 ] = s2[0 ] =0 ; + s1[0 ] = s2[0 ] = s3[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); openvpn_snprintf(s1, sizeof(s1), "%s %s, cipher %s %s", prefix,
@@ -2166,7 +2196,9 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix)print_cert_details (cert, s2,sizeof (s2));X509_free (cert); } -msg (D_HANDSHAKE ,"%s%s" , s1, s2); +print_server_tempkey (ks_ssl->ssl, s3,sizeof (s3)); + +msg (D_HANDSHAKE ,"%s%s%s" , s1, s2, s3); }void
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH 2/3 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 certificate: 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 certificate: 384 bits ECsecp384r1, signature: ecdsa-with-SHA256, server temp key: 448 bits X448, peer signing digest/type: SHA384 ECDSA
--- src/openvpn/ssl_openssl.c | 80 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-)
src/openvpn/ssl_openssl.c +78 -2
@@ -2167,6 +2167,80 @@ print_server_tempkey(SSL *ssl, char *buf, size_t buflen)EVP_PKEY_free (pkey); } +#ifndef LIBRESSL_VERSION_NUMBER +/** +* Translate an OpenVPN 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 = NID_undef, peer_sig_type_nid = NID_undef; +const char *peer_sig ="" ; +const char *peer_sig_type ="" ; + +/* 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 != NID_undef) + { + peer_sig =OBJ_nid2sn (peer_sig_nid); + } + +#ifndef LIBRESSL_VERSION_NUMBER +/* LibreSSL 3.7.x and 3.8.0 weirdly implment 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 != NID_undef) + { + peer_sig_type =get_sigtype (peer_sig_type_nid); + } +#endif + +if (peer_sig_nid == NID_undef && peer_sig_type_nid == NID_undef) + { +return ; + } + +openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); +} + + +/* ************************************** * * Information functions
@@ -2181,8 +2255,9 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix)char s1[256 ];char s2[256 ];char s3[256 ]; +char s4[256 ]; - s1[0 ] = s2[0 ] = s3[0 ] =0 ; + s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); openvpn_snprintf(s1, sizeof(s1), "%s %s, cipher %s %s", prefix,
@@ -2197,8 +2272,9 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix)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
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH 3/3 Add warning for the --show-groups command that some groups are missing
In reply to Arne SchwabeOpenSSL has a weird way of only reporting EC curves that are implemented in a certain way in the list of all EC cruves. Note this fact and point out that also the very important curves X448 and X25519 are affected.
--- src/openvpn/ssl_openssl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
src/openvpn/ssl_openssl.c +4 -2
@@ -2355,8 +2355,10 @@ show_available_tls_ciphers_list(const char *cipher_list,void show_available_curves (void ) { -printf ("Consider using openssl 'ecparam -list_curves' as\n" -"alternative to running this command.\n" ); +printf ("Consider using 'openssl ecparam -list_curves' as alternative to running\n" +"this command.\n" +"Note this output does only list curves/group that OpenSSL considers as\n" +"builtin EC curves. It does not list additional curves nor X448 or X25519\n" );#ifndef OPENSSL_NO_EC EC_builtin_curve *curves =NULL ;size_t crv_len =0 ;
Signature · 1 line
2.39.2 (Apple Git-143)