diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2017-06-25 15:32:52 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2017-07-10 07:25:58 +0000 |
commit | 11f9f31deb0d43db29ff63a245bcb67ec11dd3c2 (patch) | |
tree | ff3a0d67c54a6b68ae5f0a96bd59166f580c202a /tests | |
parent | 4bfaf67cb04375a51caea3ee5fef55a0c7ba956c (diff) | |
download | gnutls-11f9f31deb0d43db29ff63a245bcb67ec11dd3c2.tar.gz |
tests: added unit testing for server/client cipher negotiation
This verifies that the expected algorithm (cipher) is negotiated.
Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/cipher-neg-common.c | 93 | ||||
-rw-r--r-- | tests/ssl30-cipher-neg.c | 133 | ||||
-rw-r--r-- | tests/tls10-cipher-neg.c | 129 | ||||
-rw-r--r-- | tests/tls11-cipher-neg.c | 129 | ||||
-rw-r--r-- | tests/tls12-cipher-neg.c | 205 |
6 files changed, 691 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index e2724a54b9..74a2bf4b46 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -35,7 +35,7 @@ EXTRA_DIST = suppressions.valgrind eagain-common.h cert-common.h test-chains.h \ starttls-lmtp.txt starttls-pop3.txt starttls-nntp.txt starttls-sieve.txt \ rsa-md5-collision/colliding-chain-md5-2.pem rsa-md5-collision/colliding-chain-md5-1.pem \ ocsp-tests/certs/ocsp-amazon.com.der ocsp-tests/certs/chain-amazon.com.pem \ - ocsp-tests/certs/chain-amazon.com-unsorted.pem \ + ocsp-tests/certs/chain-amazon.com-unsorted.pem cipher-neg-common.c \ ocsp-tests/certs/chain-akamai.com.pem ocsp-tests/certs/ocsp-akamai.com.der \ certs-interesting/README.md certs-interesting/cert1.der certs-interesting/cert1.der.err \ certs-interesting/cert2.der certs-interesting/cert2.der.err certs-interesting/cert3.der \ @@ -93,6 +93,7 @@ ctests = mini-record-2 simple gc set_pkcs12_cred cert certuniqueid \ hostname-check cve-2008-4989 pkcs12_s2k chainverify record-sizes-range \ crq_key_id x509sign-verify sign-verify cve-2009-1415 cve-2009-1416 \ tls10-server-kx-neg tls11-server-kx-neg tls12-server-kx-neg ssl30-server-kx-neg \ + tls12-cipher-neg tls11-cipher-neg tls10-cipher-neg ssl30-cipher-neg \ crq_apis init_roundtrip pkcs12_s2k_pem dn2 mini-eagain tls-rehandshake-cert-3 \ nul-in-x509-names x509_altname pkcs12_encode mini-x509 ocsp-resp \ tls-rehandshake-cert rng-fork mini-eagain-dtls resume-dtls \ diff --git a/tests/cipher-neg-common.c b/tests/cipher-neg-common.c new file mode 100644 index 0000000000..1ddbad612d --- /dev/null +++ b/tests/cipher-neg-common.c @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2017 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 Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/> + */ +#include <assert.h> + +typedef struct test_case_st { + const char *name; + int cipher; + const char *client_prio; + const char *server_prio; + unsigned not_on_fips; +} test_case_st; + +static void try(test_case_st *test) +{ + int sret, cret; + gnutls_certificate_credentials_t s_cert_cred; + gnutls_certificate_credentials_t c_cert_cred; + gnutls_session_t server, client; + + if (test->not_on_fips && gnutls_fips140_mode_enabled()) { + success("Skipping %s...\n", test->name); + return; + } + + success("Running %s...\n", test->name); + + assert(gnutls_certificate_allocate_credentials(&s_cert_cred) >= 0); + assert(gnutls_certificate_allocate_credentials(&c_cert_cred) >= 0); + + assert(gnutls_init(&server, GNUTLS_SERVER)>=0); + assert(gnutls_init(&client, GNUTLS_CLIENT)>=0); + + gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE, s_cert_cred); + gnutls_certificate_set_known_dh_params(s_cert_cred, GNUTLS_SEC_PARAM_MEDIUM); + + assert(gnutls_certificate_set_x509_key_mem(s_cert_cred, &server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key, GNUTLS_X509_FMT_PEM) >= 0); + assert(gnutls_certificate_set_x509_key_mem(s_cert_cred, &server_ca3_localhost_ecc_cert, &server_ca3_ecc_key, GNUTLS_X509_FMT_PEM) >= 0); + assert(gnutls_certificate_set_x509_key_mem(s_cert_cred, &server_ca3_localhost_rsa_sign_cert, &server_ca3_key, GNUTLS_X509_FMT_PEM) >= 0); + + gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE, c_cert_cred); + + gnutls_transport_set_push_function(server, server_push); + gnutls_transport_set_pull_function(server, server_pull); + gnutls_transport_set_ptr(server, server); + assert(gnutls_priority_set_direct(server, test->server_prio, 0) >= 0); + + gnutls_transport_set_push_function(client, client_push); + gnutls_transport_set_pull_function(client, client_pull); + gnutls_transport_set_ptr(client, client); + assert(gnutls_priority_set_direct(client, test->client_prio, 0) >= 0); + + HANDSHAKE(client, server); + + sret = gnutls_cipher_get(client); + cret = gnutls_cipher_get(server); + + if (sret != cret) { + fail("%s: client negotiated different cipher than server (%s, %s)!\n", + test->name, gnutls_cipher_get_name(cret), + gnutls_cipher_get_name(sret)); + } + + if (cret != test->cipher) { + fail("%s: negotiated cipher diffs the expected (%s, %s)!\n", + test->name, gnutls_cipher_get_name(cret), + gnutls_cipher_get_name(test->cipher)); + } + + gnutls_deinit(server); + gnutls_deinit(client); + gnutls_certificate_free_credentials(s_cert_cred); + gnutls_certificate_free_credentials(c_cert_cred); + + reset_buffers(); +} diff --git a/tests/ssl30-cipher-neg.c b/tests/ssl30-cipher-neg.c new file mode 100644 index 0000000000..51807af7c0 --- /dev/null +++ b/tests/ssl30-cipher-neg.c @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2017 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 Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/> + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +/* This program tests the ciphersuite negotiation for various key exchange + * methods and options. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <gnutls/gnutls.h> +#include "utils.h" +#include "cert-common.h" +#include "eagain-common.h" + +#include "cipher-neg-common.c" + +test_case_st tests[] = { + { + .name = "server SSL 3.0: AES-128-CBC (server)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+VERS-SSL3.0:+AES-128-CBC" + }, + { + .name = "both SSL 3.0: AES-128-CBC (server)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-CBC:+VERS-SSL3.0" + }, + { + .name = "client SSL 3.0: AES-128-CBC (client)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:+VERS-SSL3.0:+AES-128-CBC", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0" + }, + { + .name = "both SSL 3.0: AES-128-CBC (client)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:+AES-128-CBC:+VERS-SSL3.0", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0" + }, + { + .name = "server SSL 3.0: 3DES-CBC (server)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+VERS-SSL3.0:+3DES-CBC" + }, + { + .name = "both SSL 3.0: 3DES-CBC (server)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+3DES-CBC:+VERS-SSL3.0" + }, + { + .name = "client SSL 3.0: 3DES-CBC (client)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:+VERS-SSL3.0:+3DES-CBC", + .client_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0" + }, + { + .name = "both SSL 3.0: 3DES-CBC (client)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:+3DES-CBC:+VERS-SSL3.0", + .client_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0" + }, + { + .name = "server SSL 3.0: ARCFOUR-128 (server)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+VERS-SSL3.0:+ARCFOUR-128" + }, + { + .name = "both SSL 3.0: ARCFOUR-128 (server)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+ARCFOUR-128:+VERS-SSL3.0" + }, + { + .name = "client SSL 3.0: ARCFOUR-128 (client)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:+VERS-SSL3.0:+ARCFOUR-128", + .client_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0" + }, + { + .name = "both SSL 3.0: ARCFOUR-128 (client)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:+ARCFOUR-128:+VERS-SSL3.0", + .client_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-SSL3.0" + } +}; + +void doit(void) +{ +#ifdef ENABLE_SSL3 + unsigned i; + global_init(); + + for (i=0;i<sizeof(tests)/sizeof(tests[0]);i++) { + try(&tests[i]); + } + + gnutls_global_deinit(); +#else + exit(77); +#endif +} diff --git a/tests/tls10-cipher-neg.c b/tests/tls10-cipher-neg.c new file mode 100644 index 0000000000..5ae89a1001 --- /dev/null +++ b/tests/tls10-cipher-neg.c @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2017 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 Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/> + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +/* This program tests the ciphersuite negotiation for various key exchange + * methods and options. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <gnutls/gnutls.h> +#include "utils.h" +#include "cert-common.h" +#include "eagain-common.h" + +#include "cipher-neg-common.c" + +test_case_st tests[] = { + { + .name = "server TLS 1.0: AES-128-CBC (server)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-CBC" + }, + { + .name = "both TLS 1.0: AES-128-CBC (server)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-CBC:+VERS-TLS1.0" + }, + { + .name = "client TLS 1.0: AES-128-CBC (client)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:+AES-128-CBC", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0" + }, + { + .name = "both TLS 1.0: AES-128-CBC (client)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:+AES-128-CBC:+VERS-TLS1.0", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0" + }, + { + .name = "server TLS 1.0: 3DES-CBC (server)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+3DES-CBC" + }, + { + .name = "both TLS 1.0: 3DES-CBC (server)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+3DES-CBC:+VERS-TLS1.0" + }, + { + .name = "client TLS 1.0: 3DES-CBC (client)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:+3DES-CBC", + .client_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0" + }, + { + .name = "both TLS 1.0: 3DES-CBC (client)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:+3DES-CBC:+VERS-TLS1.0", + .client_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0" + }, + { + .name = "server TLS 1.0: ARCFOUR-128 (server)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+ARCFOUR-128" + }, + { + .name = "both TLS 1.0: ARCFOUR-128 (server)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+ARCFOUR-128:+VERS-TLS1.0" + }, + { + .name = "client TLS 1.0: ARCFOUR-128 (client)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:+ARCFOUR-128", + .client_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0" + }, + { + .name = "both TLS 1.0: ARCFOUR-128 (client)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:+ARCFOUR-128:+VERS-TLS1.0", + .client_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.0" + } +}; + +void doit(void) +{ + unsigned i; + global_init(); + + for (i=0;i<sizeof(tests)/sizeof(tests[0]);i++) { + try(&tests[i]); + } + + gnutls_global_deinit(); +} diff --git a/tests/tls11-cipher-neg.c b/tests/tls11-cipher-neg.c new file mode 100644 index 0000000000..5ad65217c7 --- /dev/null +++ b/tests/tls11-cipher-neg.c @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2017 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 Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/> + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +/* This program tests the ciphersuite negotiation for various key exchange + * methods and options. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <gnutls/gnutls.h> +#include "utils.h" +#include "cert-common.h" +#include "eagain-common.h" + +#include "cipher-neg-common.c" + +test_case_st tests[] = { + { + .name = "server TLS 1.1: AES-128-CBC (server)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-CBC" + }, + { + .name = "both TLS 1.1: AES-128-CBC (server)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-CBC:+VERS-TLS1.1" + }, + { + .name = "client TLS 1.1: AES-128-CBC (client)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:+AES-128-CBC", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1" + }, + { + .name = "both TLS 1.1: AES-128-CBC (client)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:+AES-128-CBC:+VERS-TLS1.1", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1" + }, + { + .name = "server TLS 1.1: 3DES-CBC (server)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+3DES-CBC" + }, + { + .name = "both TLS 1.1: 3DES-CBC (server)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+3DES-CBC:+VERS-TLS1.1" + }, + { + .name = "client TLS 1.1: 3DES-CBC (client)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:+3DES-CBC", + .client_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1" + }, + { + .name = "both TLS 1.1: 3DES-CBC (client)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:+3DES-CBC:+VERS-TLS1.1", + .client_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1" + }, + { + .name = "server TLS 1.1: ARCFOUR-128 (server)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+ARCFOUR-128" + }, + { + .name = "both TLS 1.1: ARCFOUR-128 (server)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+ARCFOUR-128:+VERS-TLS1.1" + }, + { + .name = "client TLS 1.1: ARCFOUR-128 (client)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:+ARCFOUR-128", + .client_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1" + }, + { + .name = "both TLS 1.1: ARCFOUR-128 (client)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:+ARCFOUR-128:+VERS-TLS1.1", + .client_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.1" + } +}; + +void doit(void) +{ + unsigned i; + global_init(); + + for (i=0;i<sizeof(tests)/sizeof(tests[0]);i++) { + try(&tests[i]); + } + + gnutls_global_deinit(); +} diff --git a/tests/tls12-cipher-neg.c b/tests/tls12-cipher-neg.c new file mode 100644 index 0000000000..775ccdb9f4 --- /dev/null +++ b/tests/tls12-cipher-neg.c @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2017 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 Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/> + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +/* This program tests the ciphersuite negotiation for various key exchange + * methods and options. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <gnutls/gnutls.h> +#include "utils.h" +#include "cert-common.h" +#include "eagain-common.h" + +#include "cipher-neg-common.c" + +test_case_st tests[] = { + { + .name = "server TLS 1.2: AES-128-GCM (server)", + .cipher = GNUTLS_CIPHER_AES_128_GCM, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-GCM:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-GCM" + }, + { + .name = "both TLS 1.2: AES-128-GCM (server)", + .cipher = GNUTLS_CIPHER_AES_128_GCM, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-GCM:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-GCM:+VERS-TLS1.2" + }, + { + .name = "client TLS 1.2: AES-128-GCM (client)", + .cipher = GNUTLS_CIPHER_AES_128_GCM, + .server_prio = "NORMAL:+AES-128-GCM", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-GCM:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "both TLS 1.2: AES-128-GCM (client)", + .cipher = GNUTLS_CIPHER_AES_128_GCM, + .server_prio = "NORMAL:+AES-128-GCM:+VERS-TLS1.2", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-GCM:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "server TLS 1.2: AES-128-CCM (server)", + .cipher = GNUTLS_CIPHER_AES_128_CCM, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CCM:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-CCM" + }, + { + .name = "both TLS 1.2: AES-128-CCM (server)", + .cipher = GNUTLS_CIPHER_AES_128_CCM, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CCM:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-CCM:+VERS-TLS1.2" + }, + { + .name = "client TLS 1.2: AES-128-CCM (client)", + .cipher = GNUTLS_CIPHER_AES_128_CCM, + .server_prio = "NORMAL:+AES-128-CCM", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CCM:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "both TLS 1.2: AES-128-CCM (client)", + .cipher = GNUTLS_CIPHER_AES_128_CCM, + .server_prio = "NORMAL:+AES-128-CCM:+VERS-TLS1.2", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CCM:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "server TLS 1.2: CHACHA20-POLY (server)", + .cipher = GNUTLS_CIPHER_CHACHA20_POLY1305, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+CHACHA20-POLY1305:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+CHACHA20-POLY1305" + }, + { + .name = "both TLS 1.2: CHACHA20-POLY (server)", + .cipher = GNUTLS_CIPHER_CHACHA20_POLY1305, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+CHACHA20-POLY1305:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+CHACHA20-POLY1305:+VERS-TLS1.2" + }, + { + .name = "client TLS 1.2: CHACHA20-POLY (client)", + .cipher = GNUTLS_CIPHER_CHACHA20_POLY1305, + .not_on_fips = 1, + .server_prio = "NORMAL:+CHACHA20-POLY1305", + .client_prio = "NORMAL:-CIPHER-ALL:+CHACHA20-POLY1305:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "both TLS 1.2: CHACHA20-POLY (client)", + .cipher = GNUTLS_CIPHER_CHACHA20_POLY1305, + .not_on_fips = 1, + .server_prio = "NORMAL:+CHACHA20-POLY1305:+VERS-TLS1.2", + .client_prio = "NORMAL:-CIPHER-ALL:+CHACHA20-POLY1305:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "server TLS 1.2: AES-128-CBC (server)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-CBC" + }, + { + .name = "both TLS 1.2: AES-128-CBC (server)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+AES-128-CBC:+VERS-TLS1.2" + }, + { + .name = "client TLS 1.2: AES-128-CBC (client)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:+AES-128-CBC", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "both TLS 1.2: AES-128-CBC (client)", + .cipher = GNUTLS_CIPHER_AES_128_CBC, + .server_prio = "NORMAL:+AES-128-CBC:+VERS-TLS1.2", + .client_prio = "NORMAL:-CIPHER-ALL:+AES-128-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "server TLS 1.2: 3DES-CBC (server)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+3DES-CBC" + }, + { + .name = "both TLS 1.2: 3DES-CBC (server)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+3DES-CBC:+VERS-TLS1.2" + }, + { + .name = "client TLS 1.2: 3DES-CBC (client)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:+3DES-CBC", + .client_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "both TLS 1.2: 3DES-CBC (client)", + .cipher = GNUTLS_CIPHER_3DES_CBC, + .server_prio = "NORMAL:+3DES-CBC:+VERS-TLS1.2", + .client_prio = "NORMAL:-CIPHER-ALL:+3DES-CBC:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "server TLS 1.2: ARCFOUR-128 (server)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+ARCFOUR-128" + }, + { + .name = "both TLS 1.2: ARCFOUR-128 (server)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2:%SERVER_PRECEDENCE", + .client_prio = "NORMAL:+ARCFOUR-128:+VERS-TLS1.2" + }, + { + .name = "client TLS 1.2: ARCFOUR-128 (client)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:+ARCFOUR-128", + .client_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + }, + { + .name = "both TLS 1.2: ARCFOUR-128 (client)", + .cipher = GNUTLS_CIPHER_ARCFOUR_128, + .not_on_fips = 1, + .server_prio = "NORMAL:+ARCFOUR-128:+VERS-TLS1.2", + .client_prio = "NORMAL:-CIPHER-ALL:+ARCFOUR-128:+CIPHER-ALL:-VERS-ALL:+VERS-TLS1.2" + } +}; + +void doit(void) +{ + unsigned i; + global_init(); + + for (i=0;i<sizeof(tests)/sizeof(tests[0]);i++) { + try(&tests[i]); + } + + gnutls_global_deinit(); +} |