Skip to content

Commit

Permalink
OpenSSL: Include SIG and KEM algorithms in verbose
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ajbozarth authored and bagder committed Oct 23, 2023
1 parent 19a82c1 commit b6e6d4f
Showing 1 changed file with 75 additions and 2 deletions.
77 changes: 75 additions & 2 deletions lib/vtls/openssl.c
Expand Up @@ -79,6 +79,8 @@
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/pkcs12.h>
#include <openssl/tls1.h>
#include <openssl/evp.h>

#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_OCSP)
#include <openssl/ocsp.h>
Expand Down Expand Up @@ -3986,13 +3988,28 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf,
}
}
else {
int psigtype_nid = NID_undef;
const char *negotiated_group_name = NULL;

/* we connected fine, we're not waiting for anything else. */
connssl->connecting_state = ssl_connect_3;

#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
SSL_get_peer_signature_type_nid(backend->handle, &psigtype_nid);
#if (OPENSSL_VERSION_NUMBER >= 0x30200000L)
negotiated_group_name = SSL_get0_group_name(backend->handle);
#else
negotiated_group_name =
OBJ_nid2sn(SSL_get_negotiated_group(backend->handle) & 0x0000FFFF);
#endif
#endif

/* Informational message */
infof(data, "SSL connection using %s / %s",
infof(data, "SSL connection using %s / %s / %s / %s",
SSL_get_version(backend->handle),
SSL_get_cipher(backend->handle));
SSL_get_cipher(backend->handle),
negotiated_group_name == NULL ? NULL : negotiated_group_name,
OBJ_nid2sn(psigtype_nid));

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

return result;
}
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) && \
!defined(CURL_DISABLE_VERBOSE_STRINGS)
static void infof_certstack(struct Curl_easy *data, const SSL *ssl)
{
STACK_OF(X509) *certstack;
long verify_result;
int num_cert_levels;
int cert_level;

verify_result = SSL_get_verify_result(ssl);
if(verify_result != X509_V_OK)
certstack = SSL_get_peer_cert_chain(ssl);
else
certstack = SSL_get0_verified_chain(ssl);
num_cert_levels = sk_X509_num(certstack);
OpenSSL_add_all_algorithms();
OpenSSL_add_all_digests();

for(cert_level = 0; cert_level < num_cert_levels; cert_level++) {
char cert_algorithm[80] = "";
char group_name[80] = "";
char group_name_final[80] = "";
const X509_ALGOR *palg_cert = NULL;
const ASN1_OBJECT *paobj_cert = NULL;
X509 *current_cert;
EVP_PKEY *current_pkey;
int key_bits;
int key_sec_bits;
int get_group_name;

current_cert = sk_X509_value(certstack, cert_level);

X509_get0_signature(NULL, &palg_cert, current_cert);
X509_ALGOR_get0(&paobj_cert, NULL, NULL, palg_cert);
OBJ_obj2txt(cert_algorithm, sizeof(cert_algorithm), paobj_cert, 0);

current_pkey = X509_get0_pubkey(current_cert);
key_bits = EVP_PKEY_bits(current_pkey);
key_sec_bits = EVP_PKEY_get_security_bits(current_pkey);
get_group_name = EVP_PKEY_get_group_name(current_pkey, group_name,
sizeof(group_name), NULL);
msnprintf(group_name_final, sizeof(group_name_final), "/%s", group_name);

infof(data,
" Certificate level %d: "
"Public key type %s%s (%d/%d Bits/secBits), signed using %s",
cert_level, EVP_PKEY_get0_type_name(current_pkey),
get_group_name == 0 ? "" : group_name_final,
key_bits, key_sec_bits, cert_algorithm);
}
}
#else
#define infof_certstack(data, ssl)
#endif

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

infof_certstack(data, backend->handle);

#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_TLSEXT) && \
!defined(OPENSSL_NO_OCSP)
if(conn_config->verifystatus) {
Expand Down

0 comments on commit b6e6d4f

Please sign in to comment.