diff options
-rw-r--r-- | lib/gnutls_datum.c | 21 | ||||
-rw-r--r-- | lib/gnutls_datum.h | 3 | ||||
-rw-r--r-- | lib/x509/gnutls-idna.c | 41 | ||||
-rw-r--r-- | lib/x509/x509_ext.c | 4 |
4 files changed, 67 insertions, 2 deletions
diff --git a/lib/gnutls_datum.c b/lib/gnutls_datum.c index 2ce139350c..545e090f27 100644 --- a/lib/gnutls_datum.c +++ b/lib/gnutls_datum.c @@ -49,6 +49,27 @@ _gnutls_set_datum(gnutls_datum_t * dat, const void *data, size_t data_size) return 0; } +/* ensures that the data set are null-terminated */ +int +_gnutls_set_strdatum(gnutls_datum_t * dat, const void *data, size_t data_size) +{ + if (data_size == 0 || data == NULL) { + dat->data = NULL; + dat->size = 0; + return 0; + } + + dat->data = gnutls_malloc(data_size+1); + if (dat->data == NULL) + return GNUTLS_E_MEMORY_ERROR; + + dat->size = data_size; + memcpy(dat->data, data, data_size); + dat->data[data_size] = 0; + + return 0; +} + int _gnutls_datum_append(gnutls_datum_t * dst, const void *data, size_t data_size) diff --git a/lib/gnutls_datum.h b/lib/gnutls_datum.h index d6cb91be59..4f7205863e 100644 --- a/lib/gnutls_datum.h +++ b/lib/gnutls_datum.h @@ -28,6 +28,9 @@ int _gnutls_set_datum(gnutls_datum_t * dat, const void *data, size_t data_size); +int _gnutls_set_strdatum(gnutls_datum_t * dat, const void *data, + size_t data_size); + int _gnutls_datum_append(gnutls_datum_t * dat, const void *data, size_t data_size); diff --git a/lib/x509/gnutls-idna.c b/lib/x509/gnutls-idna.c new file mode 100644 index 0000000000..62ec5f394e --- /dev/null +++ b/lib/x509/gnutls-idna.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 Nikos Mavrogiannopoulos + * + * 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/> + * + */ + +#include <gnutls-idna.h> +#include <stringprep.h> +#include <idna.h> + +int safe_idna_to_ascii_8z (const char *input, unsigned ilen, char **output, int flags) +{ + uint32_t *ucs4; + size_t ucs4len; + int rc; + + ucs4 = stringprep_utf8_to_ucs4 (input, ilen, &ucs4len); + if (!ucs4) + return IDNA_ICONV_ERROR; + + rc = idna_to_ascii_4z (ucs4, output, flags); + free (ucs4); + + return rc; +} diff --git a/lib/x509/x509_ext.c b/lib/x509/x509_ext.c index 6f09438b80..2e69ed0bcb 100644 --- a/lib/x509/x509_ext.c +++ b/lib/x509/x509_ext.c @@ -184,7 +184,7 @@ int gnutls_subject_alt_names_set(gnutls_subject_alt_names_t sans, gnutls_datum_t copy; char *ooc; - ret = _gnutls_set_datum(©, san->data, san->size); + ret = _gnutls_set_strdatum(©, san->data, san->size); if (ret < 0) return gnutls_assert_val(ret); @@ -766,7 +766,7 @@ int gnutls_x509_aki_set_cert_issuer(gnutls_x509_aki_t aki, aki->cert_issuer.names[aki->cert_issuer.size].type = san_type; - ret = _gnutls_set_datum(&t_san, san->data, san->size); + ret = _gnutls_set_strdatum(&t_san, san->data, san->size); if (ret < 0) return gnutls_assert_val(ret); |