diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2017-01-24 08:50:54 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-01-26 16:11:30 +0100 |
commit | e8c37b0e805b007a70c89700b4b68dac6ad11606 (patch) | |
tree | 3132cd9b5ca03ba61ed40065e710640c299684e7 | |
parent | a4f10eb0c4c52c2bc2581fa20bd737c202c05538 (diff) | |
download | gnutls-e8c37b0e805b007a70c89700b4b68dac6ad11606.tar.gz |
Exported gnutls_idna_map() and gnutls_idna_reverse_map()
Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
-rw-r--r-- | lib/includes/gnutls/gnutls.h.in | 5 | ||||
-rw-r--r-- | lib/libgnutls.map | 4 | ||||
-rw-r--r-- | lib/str-unicode.c | 59 | ||||
-rw-r--r-- | lib/str.h | 21 | ||||
-rw-r--r-- | lib/x509/output.c | 2 |
5 files changed, 47 insertions, 44 deletions
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in index dbac6a3046..fa863506d3 100644 --- a/lib/includes/gnutls/gnutls.h.in +++ b/lib/includes/gnutls/gnutls.h.in @@ -1967,6 +1967,11 @@ int gnutls_random_art(gnutls_random_art_t type, const char *key_type, unsigned int key_size, void *fpr, size_t fpr_size, gnutls_datum_t * art); +/* IDNA */ +#define GNUTLS_IDNA_FORCE_2008 (1<<1) +int gnutls_idna_map(const char * input, unsigned ilen, gnutls_datum_t *out, unsigned flags);; +int gnutls_idna_reverse_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags); + /* SRP */ diff --git a/lib/libgnutls.map b/lib/libgnutls.map index 04b55d9b1a..7ccb18d0a6 100644 --- a/lib/libgnutls.map +++ b/lib/libgnutls.map @@ -1132,6 +1132,8 @@ GNUTLS_3_4 gnutls_x509_crl_get_issuer_dn3; gnutls_x509_crq_get_dn3; gnutls_utf8_password_normalize; + gnutls_idna_map; + gnutls_idna_reverse_map; local: *; }; @@ -1198,6 +1200,4 @@ GNUTLS_PRIVATE_3_4 { # Internal symbols needed by tests/name-constraints-merge: _gnutls_x509_name_constraints_merge; _gnutls_server_name_set_raw; - _gnutls_idna_map; - _gnutls_idna_reverse_map; }; diff --git a/lib/str-unicode.c b/lib/str-unicode.c index bd5373303e..4ca7d2e5e2 100644 --- a/lib/str-unicode.c +++ b/lib/str-unicode.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Red Hat, Inc. + * Copyright (C) 2016, 2017 Red Hat, Inc. * * Author: Nikos Mavrogiannopoulos * @@ -295,24 +295,31 @@ int gnutls_utf8_password_normalize(const unsigned char *password, unsigned plen, } #if defined HAVE_LIBIDN2 || defined HAVE_LIBIDN -/*- - * _gnutls_idna_map: +/** + * gnutls_idna_map: * @input: contain the UTF-8 formatted domain name * @ilen: the length of the provided string * @out: the result in an null-terminated allocated string * @flags: should be zero * * This function will convert the provided UTF-8 domain name, to - * its IDNA2003 mapping. + * its IDNA mapping in an allocated variable. Note that depending on the flags the used gnutls + * library was compiled with, the output of this function may vary (i.e., + * may be IDNA2008, or IDNA2003). * - * If GnuTLS is compiled without libidn2 support, then this function - * will return %GNUTLS_E_UNIMPLEMENTED_FEATURE. + * To force IDNA2008 specify the flag %GNUTLS_IDNA_FORCE_2008. In + * the case GnuTLS is not compiled with the necessary dependencies, + * %GNUTLS_E_UNIMPLEMENTED_FEATURE will be returned to indicate that + * gnutls is unable to perform the requested conversion. + * + * Note also, that this function will return an empty string if an + * empty string is provided as input. * * Returns: %GNUTLS_E_INVALID_UTF8_STRING on invalid UTF-8 data, or 0 on success. * - * Since: 3.5.7 - -*/ -int _gnutls_idna_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags) + * Since: 3.5.8 + **/ +int gnutls_idna_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags) { char *idna = NULL; int rc, ret; @@ -330,6 +337,11 @@ int _gnutls_idna_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsi return _gnutls_set_strdatum(out, input, ilen); } +#ifndef HAVE_LIBIDN2 + if (flags & GNUTLS_IDNA_FORCE_2008) + return gnutls_assert_val(GNUTLS_E_UNIMPLEMENTED_FEATURE); +#endif + ret = _gnutls_set_strdatum(&istr, input, ilen); if (ret < 0) { gnutls_assert(); @@ -454,23 +466,26 @@ static int _idn2_to_unicode_8z8z(const char *src, char **dst) } #endif -/*- - * _gnutls_idna_reverse_map: +/** + * gnutls_idna_reverse_map: * @input: contain the ACE (IDNA) formatted domain name * @ilen: the length of the provided string * @out: the result in an null-terminated allocated UTF-8 string * @flags: should be zero * - * This function will convert the IDNA2003 ACE name to a UTF-8 domain name. + * This function will convert an ACE (ASCII-encoded) domain name to a UTF-8 domain name. * - * If GnuTLS is compiled without libidn2 support, then this function + * If GnuTLS is compiled without IDNA support, then this function * will return %GNUTLS_E_UNIMPLEMENTED_FEATURE. * + * Note also, that this function will return an empty string if an + * empty string is provided as input. + * * Returns: A negative error code on error, or 0 on success. * - * Since: 3.5.7 - -*/ -int _gnutls_idna_reverse_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags) + * Since: 3.5.8 + **/ +int gnutls_idna_reverse_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags) { char *u8 = NULL; int rc, ret; @@ -530,12 +545,16 @@ int _gnutls_idna_reverse_map(const char *input, unsigned ilen, gnutls_datum_t *o #else # undef gnutls_idna_map -int _gnutls_idna_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags) +int gnutls_idna_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags) { - return gnutls_assert_val(GNUTLS_E_UNIMPLEMENTED_FEATURE); + if (!_gnutls_str_is_print(input, ilen)) { + return gnutls_assert_val(GNUTLS_E_UNIMPLEMENTED_FEATURE); + } + + return _gnutls_set_strdatum(out, input, ilen); } -int _gnutls_idna_reverse_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags) +int gnutls_idna_reverse_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags) { return gnutls_assert_val(GNUTLS_E_UNIMPLEMENTED_FEATURE); } @@ -560,7 +579,7 @@ int _gnutls_idna_email_map(const char *input, unsigned ilen, gnutls_datum_t *out int ret; gnutls_datum_t domain; - ret = _gnutls_idna_map(p+1, ilen-name_part-1, &domain, 0); + ret = gnutls_idna_map(p+1, ilen-name_part-1, &domain, 0); if (ret < 0) return gnutls_assert_val(ret); @@ -48,27 +48,6 @@ int gnutls_utf8_password_normalize(const uint8_t *password, unsigned password_le int _gnutls_idna_email_map(const char *input, unsigned ilen, gnutls_datum_t *output); -#if !defined HAVE_LIBIDN2 && !defined HAVE_LIBIDN -inline static -int __gnutls_idna_map(const char *input, unsigned ilen, gnutls_datum_t *out, unsigned flags) -{ - /* no call to gnutls_assert() due to header dependency issues */ - out->data = gnutls_malloc(ilen+1); - if (out->data == NULL) - return GNUTLS_E_MEMORY_ERROR; - out->size = ilen; - memcpy(out->data, input, ilen); - out->data[ilen] = 0; - return 0; -} -# define gnutls_idna_map __gnutls_idna_map -#else -# define gnutls_idna_map _gnutls_idna_map -int _gnutls_idna_map(const char * input, unsigned ilen, gnutls_datum_t *out, unsigned flags); -#endif - -int _gnutls_idna_reverse_map(const char * input, unsigned ilen, gnutls_datum_t *out, unsigned flags); - inline static unsigned _gnutls_str_is_print(const char *str, unsigned size) { unsigned i; diff --git a/lib/x509/output.c b/lib/x509/output.c index 24817ed678..194c7bfafe 100644 --- a/lib/x509/output.c +++ b/lib/x509/output.c @@ -79,7 +79,7 @@ gnutls_datum_t out; } } else { if (strstr((char*)name->data, "xn--") != NULL) { - ret = _gnutls_idna_reverse_map((char*)name->data, name->size, &out, 0); + 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); |