Skip to content

Commit

Permalink
Fix an SSL_trace bug
Browse files Browse the repository at this point in the history
Ensure that SSL_trace can print certificate data even with a non-default
libctx.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #20914)
  • Loading branch information
mattcaswell committed May 24, 2023
1 parent bfcf135 commit b946a3e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ssl/t1_trce.c
Expand Up @@ -1268,13 +1268,14 @@ static int ssl_print_server_keyex(BIO *bio, int indent, const SSL_CONNECTION *sc
return !msglen;
}

static int ssl_print_certificate(BIO *bio, int indent,
static int ssl_print_certificate(BIO *bio, const SSL_CONNECTION *sc, int indent,
const unsigned char **pmsg, size_t *pmsglen)
{
size_t msglen = *pmsglen;
size_t clen;
X509 *x;
const unsigned char *p = *pmsg, *q;
SSL_CTX *ctx = SSL_CONNECTION_GET_CTX(sc);

if (msglen < 3)
return 0;
Expand All @@ -1284,8 +1285,12 @@ static int ssl_print_certificate(BIO *bio, int indent,
q = p + 3;
BIO_indent(bio, indent, 80);
BIO_printf(bio, "ASN.1Cert, length=%d", (int)clen);
x = d2i_X509(NULL, &q, clen);
if (!x)
x = X509_new_ex(ctx->libctx, ctx->propq);
if (x != NULL && d2i_X509(&x, &q, clen) == NULL) {
X509_free(x);
x = NULL;
}
if (x == NULL)
BIO_puts(bio, "<UNPARSEABLE CERTIFICATE>\n");
else {
BIO_puts(bio, "\n------details-----\n");
Expand Down Expand Up @@ -1362,7 +1367,7 @@ static int ssl_print_certificates(BIO *bio, const SSL_CONNECTION *sc, int server
BIO_indent(bio, indent, 80);
BIO_printf(bio, "certificate_list, length=%d\n", (int)clen);
while (clen > 0) {
if (!ssl_print_certificate(bio, indent + 2, &msg, &clen))
if (!ssl_print_certificate(bio, sc, indent + 2, &msg, &clen))
return 0;
if (SSL_CONNECTION_IS_TLS13(sc)
&& !ssl_print_extensions(bio, indent + 2, server,
Expand Down

0 comments on commit b946a3e

Please sign in to comment.