diff options
-rw-r--r-- | lib/priority.c | 2 | ||||
-rw-r--r-- | lib/x509/verify.c | 19 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/priority-mix.c | 172 |
4 files changed, 185 insertions, 10 deletions
diff --git a/lib/priority.c b/lib/priority.c index 8ebdee0158..6bc8b9b656 100644 --- a/lib/priority.c +++ b/lib/priority.c @@ -575,7 +575,7 @@ gnutls_priority_set(gnutls_session_t session, gnutls_priority_t priority) session->internals.priorities.compression.algorithms == 0) return gnutls_assert_val(GNUTLS_E_NO_PRIORITIES_WERE_SET); - session->internals.additional_verify_flags |= priority->additional_verify_flags; + session->internals.additional_verify_flags = priority->additional_verify_flags; return 0; } diff --git a/lib/x509/verify.c b/lib/x509/verify.c index e645c58bb1..84746d4e85 100644 --- a/lib/x509/verify.c +++ b/lib/x509/verify.c @@ -365,20 +365,24 @@ int is_broken_allowed(gnutls_sign_algorithm_t sig, unsigned int flags) hash = gnutls_sign_get_hash_algorithm(sigalg); \ entry = mac_to_entry(hash); \ if (hash <= 0 || entry == NULL) { \ + _gnutls_cert_log("cert", crt); \ _gnutls_debug_log(#level": certificate's signature hash is unknown\n"); \ return gnutls_assert_val(0); \ } \ if (entry->secure == 0 || entry->output_size*8/2 < sym_bits) { \ + _gnutls_cert_log("cert", crt); \ _gnutls_debug_log(#level": certificate's signature hash strength is unacceptable (is %u bits, needed %u)\n", entry->output_size*8/2, sym_bits); \ return gnutls_assert_val(0); \ } \ sp = gnutls_pk_bits_to_sec_param(pkalg, bits); \ if (sp < level) { \ + _gnutls_cert_log("cert", crt); \ _gnutls_debug_log(#level": certificate's security level is unacceptable\n"); \ return gnutls_assert_val(0); \ } \ sp = gnutls_pk_bits_to_sec_param(issuer_pkalg, issuer_bits); \ if (sp < level) { \ + _gnutls_cert_log("issuer", issuer); \ _gnutls_debug_log(#level": certificate's issuer security level is unacceptable\n"); \ return gnutls_assert_val(0); \ } \ @@ -396,14 +400,13 @@ static unsigned is_level_acceptable( gnutls_x509_crt_t crt, gnutls_x509_crt_t issuer, gnutls_sign_algorithm_t sigalg, unsigned flags) { -gnutls_certificate_verification_profiles_t profile = GNUTLS_VFLAGS_TO_PROFILE(flags); -const mac_entry_st *entry; -int issuer_pkalg, pkalg, ret; -unsigned bits = 0, issuer_bits = 0, sym_bits = 0; -gnutls_pk_params_st params; -gnutls_sec_param_t sp; - -int hash; + gnutls_certificate_verification_profiles_t profile = GNUTLS_VFLAGS_TO_PROFILE(flags); + const mac_entry_st *entry; + int issuer_pkalg, pkalg, ret; + unsigned bits = 0, issuer_bits = 0, sym_bits = 0; + gnutls_pk_params_st params; + gnutls_sec_param_t sp; + int hash; if (profile == 0) return 1; diff --git a/tests/Makefile.am b/tests/Makefile.am index 4128560f67..2e37ad01f7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -120,7 +120,7 @@ ctests = mini-record-2 simple gc set_pkcs12_cred cert certuniqueid \ 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 cert_verify_inv_utf8 \ - hostname-check-utf8 pkcs8-key-decode-encrypted + hostname-check-utf8 pkcs8-key-decode-encrypted priority-mix if HAVE_SECCOMP_TESTS ctests += dtls-with-seccomp tls-with-seccomp dtls-client-with-seccomp tls-client-with-seccomp diff --git a/tests/priority-mix.c b/tests/priority-mix.c new file mode 100644 index 0000000000..ff9393738e --- /dev/null +++ b/tests/priority-mix.c @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2008-2012 Free Software Foundation, Inc. + * 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 + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <gnutls/gnutls.h> +#include <assert.h> +#include "utils.h" +#include "eagain-common.h" +#include "cert-common.h" + +const char *side; + +static void tls_log_func(int level, const char *str) +{ + fprintf(stderr, "%s|<%d>| %s", side, level, str); +} + +static time_t mytime(time_t * t) +{ + time_t then = 1461671166; + + if (t) + *t = then; + + return then; +} + +/* Tests whether multiple calls to gnutls_priority_set_direct() would work + * as intended. */ + +void doit(void) +{ + int exit_code = EXIT_SUCCESS; + int ret; + /* Server stuff. */ + gnutls_certificate_credentials_t serverx509cred; + gnutls_session_t server; + int sret = GNUTLS_E_AGAIN; + /* Client stuff. */ + gnutls_certificate_credentials_t clientx509cred; + gnutls_session_t client; + int cret = GNUTLS_E_AGAIN; + + /* General init. */ + global_init(); + gnutls_global_set_log_function(tls_log_func); + if (debug) + gnutls_global_set_log_level(6); + + gnutls_global_set_time_function(mytime); + + /* Init server */ + gnutls_certificate_allocate_credentials(&serverx509cred); + gnutls_certificate_set_x509_key_mem(serverx509cred, + &server_cert, &server_key, + GNUTLS_X509_FMT_PEM); + + gnutls_init(&server, GNUTLS_SERVER); + gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE, + serverx509cred); + assert(gnutls_priority_set_direct(server, + "SECURE256", + NULL) >= 0); + assert(gnutls_priority_set_direct(server, + "NORMAL", + NULL) >= 0); + gnutls_transport_set_push_function(server, server_push); + gnutls_transport_set_pull_function(server, server_pull); + gnutls_transport_set_ptr(server, server); + + /* Init client */ + ret = gnutls_certificate_allocate_credentials(&clientx509cred); + if (ret < 0) + exit(1); + + ret = gnutls_certificate_set_x509_trust_mem(clientx509cred, &ca_cert, GNUTLS_X509_FMT_PEM); + if (ret < 0) + exit(1); + + ret = gnutls_init(&client, GNUTLS_CLIENT); + if (ret < 0) + exit(1); + + ret = gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE, + clientx509cred); + if (ret < 0) + exit(1); + + assert(gnutls_priority_set_direct(client, + "PFS:%PROFILE_ULTRA", + NULL) >= 0); + assert(gnutls_priority_set_direct(client, + "NORMAL", + NULL) >= 0); + gnutls_transport_set_push_function(client, client_push); + gnutls_transport_set_pull_function(client, client_pull); + gnutls_transport_set_ptr(client, client); + + HANDSHAKE(client, server); + + /* check gnutls_certificate_get_ours() - client side */ + { + const gnutls_datum_t *mcert; + + mcert = gnutls_certificate_get_ours(client); + if (mcert != NULL) { + fail("gnutls_certificate_get_ours(): failed\n"); + exit(1); + } + } + + /* check the number of certificates received and verify */ + { + unsigned status; + + ret = gnutls_certificate_verify_peers3(client, "localhost", &status); + if (ret < 0) { + fail("could not verify certificate: %s\n", gnutls_strerror(ret)); + exit(1); + } + + if (status != 0) { + fail("could not verify certificate: %.4x\n", status); + exit(1); + } + } + + gnutls_bye(client, GNUTLS_SHUT_RDWR); + gnutls_bye(server, GNUTLS_SHUT_RDWR); + + gnutls_deinit(client); + gnutls_deinit(server); + + gnutls_certificate_free_credentials(serverx509cred); + gnutls_certificate_free_credentials(clientx509cred); + + gnutls_global_deinit(); + + if (debug > 0) { + if (exit_code == 0) + puts("Self-test successful"); + else + puts("Self-test failed"); + } +} |