From 7571fbdbfb1ab17ed617183282c146d179903501 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 8 Jan 2020 16:39:30 -0800 Subject: [PATCH] Maintenance: X509 1. Fix for issue #2718. Added a flag to the X509 structure when someone sets the issuer name. 2. When making a certificate out of the X509, if the issuer name is set clear the self-signed flag in the cert. 3. Propigate the flat X509_NAMEs to the string the cert building code uses. --- src/ssl.c | 9 ++++++++- wolfssl/internal.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ssl.c b/src/ssl.c index a04a10bbf..99da25cd0 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -37157,6 +37157,8 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl) } /* copy over Name structures */ + if (x509->issuerSet) + cert->selfSigned = 0; if ((ret = CopyX509NameToCertName(&(x509->issuer), &(cert->issuer))) != WOLFSSL_SUCCESS) { WOLFSSL_MSG("Error copying over issuer names"); @@ -38517,7 +38519,7 @@ err: if (dName->fullName != NULL) XFREE(dName->fullName, NULL, DYNAMIC_TYPE_X509); dName->fullName = fullName; - dName->fullNameLen = idx; + dName->fullNameLen = idx + 1; return 0; } @@ -47919,6 +47921,8 @@ int wolfSSL_X509_set_subject_name(WOLFSSL_X509 *cert, WOLFSSL_X509_NAME *name) wolfSSL_X509_NAME_add_entry(&cert->subject, ne, i, 1); } cert->subject.x509 = cert; + cert->subject.name = cert->subject.fullName.fullName; + cert->subject.sz = cert->subject.fullName.fullNameLen; return WOLFSSL_SUCCESS; } @@ -47949,6 +47953,9 @@ int wolfSSL_X509_set_issuer_name(WOLFSSL_X509 *cert, WOLFSSL_X509_NAME *name) wolfSSL_X509_NAME_add_entry(&cert->issuer, ne, i, 1); } cert->issuer.x509 = cert; + cert->issuer.name = cert->issuer.fullName.fullName; + cert->issuer.sz = cert->issuer.fullName.fullNameLen; + cert->issuerSet = 1; return WOLFSSL_SUCCESS; } diff --git a/wolfssl/internal.h b/wolfssl/internal.h index 2b00a3749..0521a7dad 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -3646,6 +3646,7 @@ struct WOLFSSL_X509 { WOLFSSL_X509_ALGOR algor; WOLFSSL_X509_PUBKEY key; #endif + byte issuerSet:1; };