diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2016-12-08 13:54:53 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2016-12-08 14:56:51 +0100 |
commit | 3f639a0f0bc607e8f4b3c33b68f29e3950da7a3a (patch) | |
tree | d79e98a45e6c14cf4f9646addc255d086d0de2e6 /tests | |
parent | 06bfba8ad77a9b34f96568bcc96320fa1923a1b5 (diff) | |
download | gnutls-3f639a0f0bc607e8f4b3c33b68f29e3950da7a3a.tar.gz |
tests: added check with failed verification on invalid UTF-8
That is, check whether raw UTF-8 in the certificate will fail
verification. Raw UTF-8 is prohibited by IETF PKIX (RFC5280) on a
certificate.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/cert-common.h | 33 | ||||
-rw-r--r-- | tests/cert_verify_inv_utf8.c | 157 | ||||
-rw-r--r-- | tests/utils.h | 1 |
4 files changed, 192 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index af82633352..2e92bebc8e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -116,7 +116,7 @@ ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \ multi-alerts naked-alerts pkcs7-cat-parse set_known_dh_params_x509 \ set_known_dh_params_anon set_known_dh_params_psk session-tickets-ok \ session-tickets-missing set_x509_key_file_legacy status-request-ext \ - rng-no-onload dtls1-2-mtu-check crl_apis + rng-no-onload dtls1-2-mtu-check crl_apis cert_verify_inv_utf8 if HAVE_SECCOMP_TESTS ctests += dtls-with-seccomp tls-with-seccomp dtls-client-with-seccomp tls-client-with-seccomp diff --git a/tests/cert-common.h b/tests/cert-common.h index 771ef4794b..ea74c96362 100644 --- a/tests/cert-common.h +++ b/tests/cert-common.h @@ -32,6 +32,7 @@ * IPv4 server: server_ca3_localhost_cert, server_ca3_key * IPv4 server: server_ca3_localhost_ecc_cert, server_ca3_ecc_key * IPv4 server: server_ca3_localhost_utf8_cert, server_ca3_key - UTF8 names + * IPv4 server: server_ca3_localhost_inv_utf8_cert, server_ca3_key - invalid UTF8 names * IPv4 server: insecure key: server_ca3_localhost_insecure_key, server_ca3_localhost_insecure_cert */ @@ -908,6 +909,38 @@ const gnutls_datum_t server_ca3_localhost_utf8_cert = { (void*)server_localhost_ sizeof(server_localhost_utf8_ca3_cert_pem)-1 }; +/* shared the server_ca3 key, uses raw UTF8 on DnsName */ +static char server_localhost_inv_utf8_ca3_cert_pem[] = + "-----BEGIN CERTIFICATE-----\n" + "MIIEQDCCAqigAwIBAgIMV9ZyrTt30lJ2pYe6MA0GCSqGSIb3DQEBCwUAMA8xDTAL\n" + "BgNVBAMTBENBLTMwHhcNMDQwMjI5MTUyMTQyWhcNMjQwMjI5MTUyMTQxWjANMQsw\n" + "CQYDVQQGEwJHUjCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBANk9eJmq\n" + "LPfAu7P4Hhmcm4KmEsRfuTXk1ylqYvf715riBfJ94VIdtJqKE9q4FRwMxVsv/B+S\n" + "HFiIlEJfvCociQkrgSfloTNIMNrqkj8IjmVJuJd00MZsUuHlvwa6+F/PLLyUOMU0\n" + "3LdpuR9TbvS2fMVjmaRjBiCO439GA+qHRvwxxP7FR433Hg+5JdeYwLWve/vLgm4z\n" + "ETxnMYOFbZpArkizpBi/RYQtLmFW8HwZ0/ldDBMnDgcfmL9gRLtMQ1XZEHLNFjyE\n" + "VD1JsrlgccaizNUkiUi7Gbm/w3YiDVxbq3u3cee5lsNhEMIREyISKAHPy8RlnIWw\n" + "wuDlnsmI0pIb9/4RH0LMMlceDEFy1X0QRzYqZFPU/0l4j/FlQ6X2UqWNz63ybRSb\n" + "cCzHl25abi1xmbsV5ydomJNcP+0QbripMpa0O6gjv5f0yMd7mW9/aAglPcKgpbbh\n" + "Gfo7V9z2gIKdUCLRXoUszhdobnRf00LrrpFUQWReKHxMcDWAL2b00kysPQIDAQAB\n" + "o4GdMIGaMAwGA1UdEwEB/wQCMAAwSgYDVR0RBEMwQYISd3d3Ls69zq/Ous6/z4Iu\n" + "Y29tghvnroDkvZPkuK3mlocuzrXOvs+Ez4HOsS5jb22CDmxvY2FsaG9zdC11dGY4\n" + "MB0GA1UdDgQWBBQzneEn04vV/OsF/LXHgWlPXjvZ1jAfBgNVHSMEGDAWgBT5qIYZ\n" + "Y7akFBNgdg8BmjU27/G0rzANBgkqhkiG9w0BAQsFAAOCAYEAkUgmFO2bdws049Nz\n" + "w55UaF7XxG8ER7kKzLCWgw8tuYjcIDKQ+/gD0hUuKBxCbuISdT32gfZTf+ZNKtEg\n" + "7f9Lhr935ZoDCvyYnal1ploqAOu0ZDEXz+cU+OzreJ58J95LYX2we1lPqCYz0qo0\n" + "6FeWrP6H6+azis2ee5XN+b20l/nRl3bNGZDnkl6+b3wPR6rIFaILcEZDl15SMgiW\n" + "PlzJ0s97szWAO2ywLvNPdB66ugOvJY34ivTQOkCDi9css5faN1LcwmqDAeAq4DZt\n" + "mZ8/504D1AUD9szneb2UgD9ZnPr4r45+qzE3lCtvmFGEddJ3c9zQVjnqEKljgG6S\n" + "FdlAVVfxbwoAc24kN6UUEpLiabFoL071pZt1WoHOFA68yBxnC6CO/3vfVSF9Ftg3\n" + "oUPldkvMs8+33YhojDKYXP5USoES2OPdofmq8LnTZj7c6ex+SvlRdOgHg4pd9lX2\n" + "Efwe6rFJaNbKv9C9tWpPIPHRk/YkUIe29VUQR2m7UUpToBca\n" + "-----END CERTIFICATE-----\n"; + +const gnutls_datum_t server_ca3_localhost_inv_utf8_cert = { (void*)server_localhost_inv_utf8_ca3_cert_pem, + sizeof(server_localhost_inv_utf8_ca3_cert_pem)-1 +}; + /* server_ca3_ecc_key */ static char server_localhost_ca3_ecc_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" diff --git a/tests/cert_verify_inv_utf8.c b/tests/cert_verify_inv_utf8.c new file mode 100644 index 0000000000..d43dfe80cc --- /dev/null +++ b/tests/cert_verify_inv_utf8.c @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2016 Red Hat, Inc. + * + * Author: Nikos Mavrogiannopoulos + * + * This file is part of GnuTLS. + * + * GnuTLS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuTLS 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GnuTLS; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* Parts copied from GnuTLS example programs. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#if !defined(_WIN32) +#include <netinet/in.h> +#include <sys/socket.h> +#include <sys/wait.h> +#include <arpa/inet.h> +#endif +#include <unistd.h> +#include <assert.h> +#include <time.h> +#include <gnutls/gnutls.h> +#include <gnutls/abstract.h> +#include <gnutls/x509.h> + +#include "cert-common.h" +#include "utils.h" + +/* Test for handshake with invalid UTF8 certificate + * + */ + +static void tls_log_func(int level, const char *str) +{ + fprintf(stderr, "<%d>| %s", level, str); +} + +static time_t mytime(time_t * t) +{ + time_t then = 1473674242; + if (t) + *t = then; + + return then; +} + +static void auto_parse(void) +{ + gnutls_certificate_credentials_t x509_cred, clicred; + gnutls_pcert_st pcert_list[16]; + gnutls_privkey_t key; + gnutls_pcert_st second_pcert[2]; + gnutls_privkey_t second_key; + unsigned pcert_list_size; + int ret; + + /* this must be called once in the program + */ + global_init(); + + gnutls_global_set_time_function(mytime); + + gnutls_global_set_log_function(tls_log_func); + if (debug) + gnutls_global_set_log_level(6); + + assert(gnutls_certificate_allocate_credentials(&x509_cred)>=0); + assert(gnutls_privkey_init(&key)>=0); + + assert(gnutls_certificate_allocate_credentials(&clicred) >= 0); + + ret = gnutls_certificate_set_x509_trust_mem(clicred, &ca3_cert, GNUTLS_X509_FMT_PEM); + if (ret < 0) + fail("set_x509_trust_file failed: %s\n", gnutls_strerror(ret)); + + pcert_list_size = sizeof(pcert_list)/sizeof(pcert_list[0]); + ret = gnutls_pcert_list_import_x509_raw(pcert_list, &pcert_list_size, + &server_ca3_localhost_cert_chain, GNUTLS_X509_FMT_PEM, 0); + if (ret < 0) { + fail("error in gnutls_pcert_list_import_x509_raw: %s\n", gnutls_strerror(ret)); + } + + ret = gnutls_privkey_import_x509_raw(key, &server_ca3_key, GNUTLS_X509_FMT_PEM, NULL, 0); + if (ret < 0) { + fail("error in key import: %s\n", gnutls_strerror(ret)); + } + + ret = gnutls_certificate_set_key(x509_cred, NULL, 0, pcert_list, + pcert_list_size, key); + if (ret < 0) { + fail("error in gnutls_certificate_set_key: %s\n", gnutls_strerror(ret)); + exit(1); + } + + /* set the key with UTF8 names */ + assert(gnutls_privkey_init(&second_key)>=0); + + pcert_list_size = 2; + ret = gnutls_pcert_list_import_x509_raw(second_pcert, &pcert_list_size, + &server_ca3_localhost_inv_utf8_cert, GNUTLS_X509_FMT_PEM, 0); + if (ret < 0) { + fail("error in gnutls_pcert_list_import_x509_raw: %s\n", gnutls_strerror(ret)); + } + + ret = gnutls_privkey_import_x509_raw(second_key, &server_ca3_key, GNUTLS_X509_FMT_PEM, NULL, 0); + if (ret < 0) { + fail("error in key import: %s\n", gnutls_strerror(ret)); + } + + ret = gnutls_certificate_set_key(x509_cred, NULL, 0, second_pcert, + 1, second_key); + if (ret < 0) { + fail("error in gnutls_certificate_set_key: %s\n", gnutls_strerror(ret)); + exit(1); + } + + test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", 0, 0); + test_cli_serv_vf(x509_cred, clicred, "NORMAL", "www.νίκοσ.com"); + test_cli_serv_vf(x509_cred, clicred, "NORMAL", "www.νίκος.com"); + test_cli_serv_vf(x509_cred, clicred, "NORMAL", "raw:www.νίκος.com"); + + gnutls_certificate_free_credentials(x509_cred); + gnutls_certificate_free_credentials(clicred); + + gnutls_global_deinit(); + + if (debug) + success("success"); +} + +void doit(void) +{ +#ifndef HAVE_LIBIDN + exit(77); +#endif + auto_parse(); +} diff --git a/tests/utils.h b/tests/utils.h index f5d11476b4..9b06df8e7c 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -105,6 +105,7 @@ test_cli_serv_expect(gnutls_certificate_credentials_t server_cred, const char *serv_prio, const char *cli_prio, const char *host, int serv_err, int cli_err); +/* verification failed */ unsigned test_cli_serv_vf(gnutls_certificate_credentials_t server_cred, gnutls_certificate_credentials_t client_cred, |