Skip to content

Commit 0c85d54

Browse files
committed
Handle missing certificate names
1 parent 772bc22 commit 0c85d54

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- improved unauthenticated blob support (thanks to Asger Hautop Drewsen)
1313
- fixed support for multiple signerInfo contentType OIDs (CTL and Authenticode)
1414
- fixed tests for python-cryptography >= 43.0.0
15+
- improved UTF-8 handling for certificate subjects and issuers;
16+
missing names now print as "N/A"
1517

1618
### 2.9 (2024.06.29)
1719

osslsigncode.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,40 @@ static int print_time_t(const time_t time)
17491749

17501750
}
17511751

1752+
/*
1753+
* Convert an X509_NAME to a UTF-8 string
1754+
* [in] name: X509 name to convert
1755+
* [returns] allocated string; "N/A" on error
1756+
*/
1757+
static char *x509_name_to_utf8(const X509_NAME *name)
1758+
{
1759+
BIO *bio;
1760+
BUF_MEM *bptr;
1761+
char *str;
1762+
unsigned long flags;
1763+
1764+
if (!name)
1765+
return OPENSSL_strdup("N/A");
1766+
1767+
flags = XN_FLAG_RFC2253 | ASN1_STRFLGS_UTF8_CONVERT |
1768+
ASN1_STRFLGS_ESC_CTRL;
1769+
flags &= ~ASN1_STRFLGS_ESC_MSB;
1770+
1771+
bio = BIO_new(BIO_s_mem());
1772+
if (!bio)
1773+
return OPENSSL_strdup("N/A");
1774+
if (X509_NAME_print_ex(bio, name, 0, flags) < 0) {
1775+
BIO_free(bio);
1776+
return OPENSSL_strdup("N/A");
1777+
}
1778+
BIO_get_mem_ptr(bio, &bptr);
1779+
str = OPENSSL_strndup(bptr->data, bptr->length);
1780+
BIO_free(bio);
1781+
if (!str)
1782+
return OPENSSL_strdup("N/A");
1783+
return str;
1784+
}
1785+
17521786
/*
17531787
* Print certificate subject name, issuer name, serial number and expiration date
17541788
* [in] cert: X509 certificate
@@ -1762,8 +1796,8 @@ static void print_cert(X509 *cert, int i)
17621796

17631797
if (!cert)
17641798
return;
1765-
subject = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
1766-
issuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
1799+
subject = x509_name_to_utf8(X509_get_subject_name(cert));
1800+
issuer = x509_name_to_utf8(X509_get_issuer_name(cert));
17671801
serialbn = ASN1_INTEGER_to_BN(X509_get_serialNumber(cert), NULL);
17681802
serial = BN_bn2hex(serialbn);
17691803
printf("\t------------------\n");
@@ -2633,10 +2667,11 @@ static int print_cms_timestamp(CMS_ContentInfo *timestamp, time_t time)
26332667

26342668
if (!CMS_SignerInfo_get0_signer_id(si, NULL, &issuer, &serialno) || !issuer)
26352669
return 0; /* FAILED */
2636-
issuer_name = X509_NAME_oneline(issuer, NULL, 0);
2670+
issuer_name = x509_name_to_utf8(issuer);
26372671
serialbn = ASN1_INTEGER_to_BN(serialno, NULL);
26382672
serial = BN_bn2hex(serialbn);
2639-
printf("\tIssuer: %s\n\tSerial: %s\n", issuer_name, serial);
2673+
printf("\tIssuer: %s\n\tSerial: %s\n",
2674+
issuer_name, serial);
26402675
OPENSSL_free(issuer_name);
26412676
BN_free(serialbn);
26422677
OPENSSL_free(serial);

0 commit comments

Comments
 (0)