]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
gnutls_x509_crt_print() will print the IDNA A-label names as well.
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 20 Aug 2014 13:47:32 +0000 (15:47 +0200)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 20 Aug 2014 13:47:32 +0000 (15:47 +0200)
lib/x509/Makefile.am
lib/x509/gnutls-idna.h [new file with mode: 0644]
lib/x509/hostname-verify.c
lib/x509/output.c

index 24a4524eeb550dd551ab93efb326c0e945063d37..9d6046d363c16dff7e5c8d85f4fafa64bed7caa9 100644 (file)
@@ -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 (file)
index 0000000..a425967
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef _GNUTLS_IDNA_H
+# define _GNUTLS_IDNA_H
+
+#include <config.h>
+
+#ifdef HAVE_LIBIDN
+# include <idna.h>
+#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
index 52467fa42fc16af7b2096b3a00a0d0acf1db0f5a..7a3abdb547c98d18bd3edd6fa1f97aa78796c6b5 100644 (file)
 #include <common.h>
 #include <gnutls_errors.h>
 #include <system.h>
-
-#ifdef HAVE_LIBIDN
-# include <idna.h>
-#endif
+#include <gnutls-idna.h>
 
 /**
  * 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)
index 3aaa2fe6b47917dd8a21f12c9b0463beee2d97d5..1a4d4807e482e1a11c5b6861686ac007ba9b4d67 100644 (file)
@@ -30,6 +30,8 @@
 #include <gnutls_num.h>
 #include <gnutls_errors.h>
 #include <extras/randomart.h>
+#include <c-ctype.h>
+#include <gnutls-idna.h>
 
 #ifdef HAVE_INET_NTOP
 # include <arpa/inet.h>
@@ -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;i<name->size;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: