From: Nikos Mavrogiannopoulos Date: Wed, 20 Aug 2014 13:47:32 +0000 (+0200) Subject: gnutls_x509_crt_print() will print the IDNA A-label names as well. X-Git-Tag: gnutls_3_4_0~1057 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9044b04ba0b8beaf0e43f465e40c26a896bbdd8d;p=thirdparty%2Fgnutls.git gnutls_x509_crt_print() will print the IDNA A-label names as well. --- diff --git a/lib/x509/Makefile.am b/lib/x509/Makefile.am index 24a4524eeb..9d6046d363 100644 --- a/lib/x509/Makefile.am +++ b/lib/x509/Makefile.am @@ -34,6 +34,7 @@ noinst_LTLIBRARIES = libgnutls_x509.la libgnutls_x509_la_SOURCES = \ common.c key_encode.c \ common.h key_decode.c \ + gnutls-idna.h \ crl.c \ crl_write.c \ crq.c \ diff --git a/lib/x509/gnutls-idna.h b/lib/x509/gnutls-idna.h new file mode 100644 index 0000000000..a425967f5b --- /dev/null +++ b/lib/x509/gnutls-idna.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 Red Hat + * + * Author: Nikos Mavrogiannopoulos + * + * This file is part of GnuTLS. + * + * The GnuTLS is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + * + */ + +#ifndef _GNUTLS_IDNA_H +# define _GNUTLS_IDNA_H + +#include + +#ifdef HAVE_LIBIDN +# include +#endif + +#ifndef HAVE_LIBIDN +#define IDNA_SUCCESS 0 + +static inline +int idna_to_ascii_8z(const char * input, char ** output, int flags) +{ + *output = input; + return 0; +} + +#define idna_free(x) + +static inline +const char *idna_strerror(int ret) +{ + return ""; +} +#else +# define idna_free(x) free(x) +#endif + +#endif diff --git a/lib/x509/hostname-verify.c b/lib/x509/hostname-verify.c index 52467fa42f..7a3abdb547 100644 --- a/lib/x509/hostname-verify.c +++ b/lib/x509/hostname-verify.c @@ -25,10 +25,7 @@ #include #include #include - -#ifdef HAVE_LIBIDN -# include -#endif +#include /** * gnutls_x509_crt_check_hostname: @@ -87,27 +84,6 @@ check_ip(gnutls_x509_crt_t cert, const void *ip, unsigned ip_size, unsigned flag return 0; } -#ifndef HAVE_LIBIDN -#define IDNA_SUCCESS 0 - -static inline -int idna_to_ascii_8z(const char * input, char ** output, int flags) -{ - *output = input; - return 0; -} - -#define idna_free(x) - -static inline -const char *idna_strerror(int ret) -{ - return ""; -} -#else -# define idna_free(x) free(x) -#endif - static int has_embedded_null(const char *str, unsigned size) { if (strlen(str) != size) diff --git a/lib/x509/output.c b/lib/x509/output.c index 3aaa2fe6b4..1a4d4807e4 100644 --- a/lib/x509/output.c +++ b/lib/x509/output.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #ifdef HAVE_INET_NTOP # include @@ -94,6 +96,7 @@ print_name(gnutls_buffer_st *str, const char *prefix, unsigned type, gnutls_datu char *sname = (char*)name->data; char str_ip[64]; const char *p; +unsigned non_ascii = 0, i; if ((type == GNUTLS_SAN_DNSNAME || type == GNUTLS_SAN_RFC822NAME @@ -107,7 +110,30 @@ const char *p; switch (type) { case GNUTLS_SAN_DNSNAME: - addf(str, _("%sDNSname: %.*s\n"), prefix, name->size, NON_NULL(name->data)); +#ifdef HAVE_LIBIDN + for (i=0;isize;i++) { + if (c_isascii(name->data[i]) == 0) { + non_ascii = 1; + break; + } + } +#endif + + if (non_ascii != 0) { + char *s; + int rc; + + rc = idna_to_ascii_8z((char*)name->data, &s, 0); + if (rc == IDNA_SUCCESS) { + addf(str, _("%sDNSname: %.*s (%s)\n"), prefix, name->size, NON_NULL(name->data), s); + idna_free(s); + } else { + adds(str, _("note: DNSname is not in UTF-8.\n")); + addf(str, _("%sDNSname: %.*s\n"), prefix, name->size, NON_NULL(name->data)); + } + } else { + addf(str, _("%sDNSname: %.*s\n"), prefix, name->size, NON_NULL(name->data)); + } break; case GNUTLS_SAN_RFC822NAME: