From b51bbb0531a04f9b99509b7bddb63f8857a85362 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 26 Aug 2015 11:51:09 +0200 Subject: x509: tolerate missing subject or issuer fields --- lib/x509/output.c | 66 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/lib/x509/output.c b/lib/x509/output.c index 3dd386dd24..3398062460 100644 --- a/lib/x509/output.c +++ b/lib/x509/output.c @@ -1250,10 +1250,13 @@ print_cert(gnutls_buffer_st * str, gnutls_x509_crt_t cert, int err; err = gnutls_x509_crt_get_issuer_dn(cert, NULL, &dn_size); - if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) - addf(str, "error: get_issuer_dn: %s\n", - gnutls_strerror(err)); - else { + if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) { + if (err == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) + addf(str, _("\tIssuer:\n")); + else + addf(str, "error: get_issuer_dn: %s\n", + gnutls_strerror(err)); + } else { dn = gnutls_malloc(dn_size); if (!dn) addf(str, "error: malloc (%d): %s\n", @@ -1325,10 +1328,13 @@ print_cert(gnutls_buffer_st * str, gnutls_x509_crt_t cert, int err; err = gnutls_x509_crt_get_dn(cert, NULL, &dn_size); - if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) - addf(str, "error: get_dn: %s\n", - gnutls_strerror(err)); - else { + if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) { + if (err == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) + addf(str, _("\tSubject:\n")); + else + addf(str, "error: get_dn: %s\n", + gnutls_strerror(err)); + } else { dn = gnutls_malloc(dn_size); if (!dn) addf(str, "error: malloc (%d): %s\n", @@ -1507,10 +1513,13 @@ static void print_oneline(gnutls_buffer_st * str, gnutls_x509_crt_t cert) size_t dn_size = 0; err = gnutls_x509_crt_get_dn(cert, NULL, &dn_size); - if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) - addf(str, "unknown subject (%s), ", - gnutls_strerror(err)); - else { + if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) { + if (err == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) + addf(str, _("no subject,")); + else + addf(str, "unknown subject (%s), ", + gnutls_strerror(err)); + } else { dn = gnutls_malloc(dn_size); if (!dn) addf(str, "unknown subject (%s), ", @@ -1536,10 +1545,13 @@ static void print_oneline(gnutls_buffer_st * str, gnutls_x509_crt_t cert) size_t dn_size = 0; err = gnutls_x509_crt_get_issuer_dn(cert, NULL, &dn_size); - if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) - addf(str, "unknown issuer (%s), ", - gnutls_strerror(err)); - else { + if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) { + if (err == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) + addf(str, _("no issuer,")); + else + addf(str, "unknown issuer (%s), ", + gnutls_strerror(err)); + } else { dn = gnutls_malloc(dn_size); if (!dn) addf(str, "unknown issuer (%s), ", @@ -1754,10 +1766,13 @@ print_crl(gnutls_buffer_st * str, gnutls_x509_crl_t crl, int notsigned) int err; err = gnutls_x509_crl_get_issuer_dn(crl, NULL, &dn_size); - if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) - addf(str, "error: get_issuer_dn: %s\n", - gnutls_strerror(err)); - else { + if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) { + if (err == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) + addf(str, _("\tIssuer:\n")); + else + addf(str, "error: get_issuer_dn: %s\n", + gnutls_strerror(err)); + } else { dn = gnutls_malloc(dn_size); if (!dn) addf(str, "error: malloc (%d): %s\n", @@ -2122,10 +2137,13 @@ print_crq(gnutls_buffer_st * str, gnutls_x509_crq_t cert, int err; err = gnutls_x509_crq_get_dn(cert, NULL, &dn_size); - if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) - addf(str, "error: get_dn: %s\n", - gnutls_strerror(err)); - else { + if (err != GNUTLS_E_SHORT_MEMORY_BUFFER) { + if (err == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) + addf(str, _("\tSubject:\n")); + else + addf(str, "error: get_dn: %s\n", + gnutls_strerror(err)); + } else { dn = gnutls_malloc(dn_size); if (!dn) addf(str, "error: malloc (%d): %s\n", -- cgit v1.2.1