From 4679723537c72b38b0d8b7a9c19d97137aefae4a Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Fri, 25 Nov 2016 11:58:14 +0100 Subject: x509: when printing ACE DNSnames ensure the actual name is also printed --- lib/x509/output.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/x509/output.c b/lib/x509/output.c index 117848f288..1eff3a38b6 100644 --- a/lib/x509/output.c +++ b/lib/x509/output.c @@ -47,7 +47,9 @@ char *sname = (char*)name->data; char str_ip[64]; const char *p; unsigned printable = 1; +unsigned is_printed; int ret; +gnutls_datum_t out; if ((type == GNUTLS_SAN_DNSNAME || type == GNUTLS_SAN_OTHERNAME_XMPP || type == GNUTLS_SAN_OTHERNAME_KRB5PRINCIPAL @@ -67,20 +69,28 @@ int ret; printable = 0; #endif + is_printed = 0; if (!printable) { - gnutls_datum_t out; - ret = gnutls_idna_map((char*)name->data, name->size, &out, 0); - if (ret < 0) { - adds(str, _("note: DNSname is not in UTF-8.\n")); - addf(str, _("%sDNSname: %.*s\n"), prefix, name->size, NON_NULL(name->data)); - } else { + if (ret >= 0) { addf(str, _("%sDNSname: %.*s (%s)\n"), prefix, name->size, NON_NULL(name->data), (char*)out.data); gnutls_free(out.data); + is_printed = 1; } } else { - addf(str, _("%sDNSname: %.*s\n"), prefix, name->size, NON_NULL(name->data)); + if (strstr((char*)name->data, "xn--") != NULL) { + ret = _gnutls_idna_reverse_map((char*)name->data, name->size, &out, 0); + if (ret >= 0) { + addf(str, _("%sDNSname: %.*s (%s)\n"), prefix, name->size, NON_NULL(name->data), out.data); + gnutls_free(out.data); + is_printed = 1; + } + } + } + if (!is_printed) + addf(str, _("%sDNSname: %.*s\n"), prefix, name->size, NON_NULL(name->data)); + break; case GNUTLS_SAN_RFC822NAME: -- cgit v1.2.1