Skip to content

Commit b6e6d4f

Browse files
ajbozarthbagder
authored andcommitted
OpenSSL: Include SIG and KEM algorithms in verbose
Currently the verbose output does not include which algorithms are used for the signature and key exchange when using OpenSSL. Including the algorithms used will enable better debugging when working on using new algorithm implementations. Know what algorithms are used has become more important with the fast growing research into new quantum-safe algorithms. This implementation includes a build time check for the OpenSSL version to use a new function that will be included in OpenSSL 3.2 that was introduced in openssl/openssl@6866824 Based-on-patch-by: Martin Schmatz <[email protected]> Closes #12030
1 parent 19a82c1 commit b6e6d4f

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

lib/vtls/openssl.c

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
#include <openssl/bio.h>
8080
#include <openssl/buffer.h>
8181
#include <openssl/pkcs12.h>
82+
#include <openssl/tls1.h>
83+
#include <openssl/evp.h>
8284

8385
#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_OCSP)
8486
#include <openssl/ocsp.h>
@@ -3986,13 +3988,28 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf,
39863988
}
39873989
}
39883990
else {
3991+
int psigtype_nid = NID_undef;
3992+
const char *negotiated_group_name = NULL;
3993+
39893994
/* we connected fine, we're not waiting for anything else. */
39903995
connssl->connecting_state = ssl_connect_3;
39913996

3997+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
3998+
SSL_get_peer_signature_type_nid(backend->handle, &psigtype_nid);
3999+
#if (OPENSSL_VERSION_NUMBER >= 0x30200000L)
4000+
negotiated_group_name = SSL_get0_group_name(backend->handle);
4001+
#else
4002+
negotiated_group_name =
4003+
OBJ_nid2sn(SSL_get_negotiated_group(backend->handle) & 0x0000FFFF);
4004+
#endif
4005+
#endif
4006+
39924007
/* Informational message */
3993-
infof(data, "SSL connection using %s / %s",
4008+
infof(data, "SSL connection using %s / %s / %s / %s",
39944009
SSL_get_version(backend->handle),
3995-
SSL_get_cipher(backend->handle));
4010+
SSL_get_cipher(backend->handle),
4011+
negotiated_group_name == NULL ? NULL : negotiated_group_name,
4012+
OBJ_nid2sn(psigtype_nid));
39964013

39974014
#ifdef HAS_ALPN
39984015
/* Sets data and len to negotiated protocol, len is 0 if no protocol was
@@ -4068,6 +4085,60 @@ static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert,
40684085

40694086
return result;
40704087
}
4088+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) && \
4089+
!defined(CURL_DISABLE_VERBOSE_STRINGS)
4090+
static void infof_certstack(struct Curl_easy *data, const SSL *ssl)
4091+
{
4092+
STACK_OF(X509) *certstack;
4093+
long verify_result;
4094+
int num_cert_levels;
4095+
int cert_level;
4096+
4097+
verify_result = SSL_get_verify_result(ssl);
4098+
if(verify_result != X509_V_OK)
4099+
certstack = SSL_get_peer_cert_chain(ssl);
4100+
else
4101+
certstack = SSL_get0_verified_chain(ssl);
4102+
num_cert_levels = sk_X509_num(certstack);
4103+
OpenSSL_add_all_algorithms();
4104+
OpenSSL_add_all_digests();
4105+
4106+
for(cert_level = 0; cert_level < num_cert_levels; cert_level++) {
4107+
char cert_algorithm[80] = "";
4108+
char group_name[80] = "";
4109+
char group_name_final[80] = "";
4110+
const X509_ALGOR *palg_cert = NULL;
4111+
const ASN1_OBJECT *paobj_cert = NULL;
4112+
X509 *current_cert;
4113+
EVP_PKEY *current_pkey;
4114+
int key_bits;
4115+
int key_sec_bits;
4116+
int get_group_name;
4117+
4118+
current_cert = sk_X509_value(certstack, cert_level);
4119+
4120+
X509_get0_signature(NULL, &palg_cert, current_cert);
4121+
X509_ALGOR_get0(&paobj_cert, NULL, NULL, palg_cert);
4122+
OBJ_obj2txt(cert_algorithm, sizeof(cert_algorithm), paobj_cert, 0);
4123+
4124+
current_pkey = X509_get0_pubkey(current_cert);
4125+
key_bits = EVP_PKEY_bits(current_pkey);
4126+
key_sec_bits = EVP_PKEY_get_security_bits(current_pkey);
4127+
get_group_name = EVP_PKEY_get_group_name(current_pkey, group_name,
4128+
sizeof(group_name), NULL);
4129+
msnprintf(group_name_final, sizeof(group_name_final), "/%s", group_name);
4130+
4131+
infof(data,
4132+
" Certificate level %d: "
4133+
"Public key type %s%s (%d/%d Bits/secBits), signed using %s",
4134+
cert_level, EVP_PKEY_get0_type_name(current_pkey),
4135+
get_group_name == 0 ? "" : group_name_final,
4136+
key_bits, key_sec_bits, cert_algorithm);
4137+
}
4138+
}
4139+
#else
4140+
#define infof_certstack(data, ssl)
4141+
#endif
40714142

40724143
/*
40734144
* Get the server cert, verify it and show it, etc., only call failf() if the
@@ -4258,6 +4329,8 @@ static CURLcode servercert(struct Curl_cfilter *cf,
42584329
infof(data, " SSL certificate verify ok.");
42594330
}
42604331

4332+
infof_certstack(data, backend->handle);
4333+
42614334
#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_TLSEXT) && \
42624335
!defined(OPENSSL_NO_OCSP)
42634336
if(conn_config->verifystatus) {

0 commit comments

Comments
 (0)