Blame tests/tls13-server-kx-neg.c

Packit aea12f
/*
Packit aea12f
 * Copyright (C) 2017-2018 Red Hat, Inc.
Packit aea12f
 *
Packit aea12f
 * Author: Nikos Mavrogiannopoulos
Packit aea12f
 *
Packit aea12f
 * This file is part of GnuTLS.
Packit aea12f
 *
Packit aea12f
 * GnuTLS is free software; you can redistribute it and/or modify it
Packit aea12f
 * under the terms of the GNU General Public License as published by
Packit aea12f
 * the Free Software Foundation; either version 3 of the License, or
Packit aea12f
 * (at your option) any later version.
Packit aea12f
 *
Packit aea12f
 * GnuTLS is distributed in the hope that it will be useful, but
Packit aea12f
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit aea12f
 * General Public License for more details.
Packit aea12f
 *
Packit aea12f
 * You should have received a copy of the GNU Lesser General Public License
Packit aea12f
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
Packit aea12f
 */
Packit aea12f
Packit aea12f
#ifdef HAVE_CONFIG_H
Packit aea12f
#include <config.h>
Packit aea12f
#endif
Packit aea12f
Packit aea12f
/* This program tests the negotiation for various key exchange
Packit aea12f
 * methods and options which are considered legacy in TLS1.3. */
Packit aea12f
Packit aea12f
#include <stdio.h>
Packit aea12f
#include <stdlib.h>
Packit aea12f
#include <string.h>
Packit aea12f
#include <errno.h>
Packit aea12f
#include <gnutls/gnutls.h>
Packit aea12f
#include "utils.h"
Packit aea12f
#include "cert-common.h"
Packit aea12f
#include "eagain-common.h"
Packit aea12f
Packit aea12f
#include "server-kx-neg-common.c"
Packit aea12f
Packit aea12f
#define PVERSION "-VERS-ALL:+VERS-TLS1.3:+VERS-TLS1.2"
Packit aea12f
Packit aea12f
test_case_st tests[] = {
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 DHE-PSK without cred",
Packit aea12f
		.client_ret = GNUTLS_E_AGAIN,
Packit aea12f
		.server_ret = GNUTLS_E_INSUFFICIENT_CREDENTIALS,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+DHE-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+DHE-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_3,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 DHE-PSK with cred but no DH params",
Packit aea12f
		.client_ret = 0,
Packit aea12f
		.server_ret = 0,
Packit aea12f
		.have_psk_cred = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+DHE-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+DHE-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_3,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 DHE-PSK with cred and DH params (level)",
Packit aea12f
		.client_ret = 0,
Packit aea12f
		.server_ret = 0,
Packit aea12f
		.have_psk_cred = 1,
Packit aea12f
		.have_psk_dh_params = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+DHE-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+DHE-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_3,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 DHE-PSK with cred and DH params (explicit)",
Packit aea12f
		.client_ret = 0,
Packit aea12f
		.server_ret = 0,
Packit aea12f
		.have_psk_cred = 1,
Packit aea12f
		.have_psk_exp_dh_params = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+DHE-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+DHE-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_3,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 ECDHE-PSK with cred but no common curve",
Packit aea12f
		.client_ret = GNUTLS_E_AGAIN,
Packit aea12f
		.server_ret = GNUTLS_E_NO_COMMON_KEY_SHARE,
Packit aea12f
		.have_psk_cred = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+ECDHE-PSK:-CURVE-ALL:+CURVE-SECP256R1:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+ECDHE-PSK:-CURVE-ALL:+CURVE-SECP384R1:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_3,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 ECDHE-PSK with cred and common curve",
Packit aea12f
		.client_ret = 0,
Packit aea12f
		.server_ret = 0,
Packit aea12f
		.have_psk_cred = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+ECDHE-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+ECDHE-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_3,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 RSA-PSK without cert cred",
Packit aea12f
		.client_ret = GNUTLS_E_AGAIN,
Packit aea12f
		.server_ret = GNUTLS_E_INSUFFICIENT_CREDENTIALS,
Packit aea12f
		.have_psk_cred = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 RSA-PSK without psk cred",
Packit aea12f
		.client_ret = GNUTLS_E_AGAIN,
Packit aea12f
		.server_ret = GNUTLS_E_NO_CIPHER_SUITES,
Packit aea12f
		.have_psk_cred = 0,
Packit aea12f
		.have_cert_cred = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 RSA-PSK with cred but invalid cert",
Packit aea12f
		.client_ret = GNUTLS_E_AGAIN,
Packit aea12f
		.server_ret = GNUTLS_E_NO_CIPHER_SUITES,
Packit aea12f
		.have_psk_cred = 1,
Packit aea12f
		.have_cert_cred = 1,
Packit aea12f
		.have_rsa_sign_cert = 1,
Packit aea12f
		.have_ecc_sign_cert = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 RSA-PSK with cred",
Packit aea12f
		.server_ret = 0,
Packit aea12f
		.client_ret = 0,
Packit aea12f
		.have_psk_cred = 1,
Packit aea12f
		.have_cert_cred = 1,
Packit aea12f
		.have_rsa_decrypt_cert = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 RSA-PSK with cred and multiple certs",
Packit aea12f
		.server_ret = 0,
Packit aea12f
		.client_ret = 0,
Packit aea12f
		.have_psk_cred = 1,
Packit aea12f
		.have_cert_cred = 1,
Packit aea12f
		.have_rsa_sign_cert = 1,
Packit aea12f
		.have_ecc_sign_cert = 1,
Packit aea12f
		.have_rsa_decrypt_cert = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+RSA-PSK:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 SRP-RSA without cert cred",
Packit aea12f
		.client_ret = GNUTLS_E_AGAIN,
Packit aea12f
		.server_ret = GNUTLS_E_INSUFFICIENT_CREDENTIALS,
Packit aea12f
		.have_srp_cred = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 SRP-RSA without srp cred",
Packit aea12f
		.client_ret = GNUTLS_E_AGAIN,
Packit aea12f
		.server_ret = GNUTLS_E_NO_CIPHER_SUITES,
Packit aea12f
		.have_srp_cred = 0,
Packit aea12f
		.have_cert_cred = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 SRP-RSA with cred but invalid cert",
Packit aea12f
		.client_ret = GNUTLS_E_AGAIN,
Packit aea12f
		.server_ret = GNUTLS_E_NO_CIPHER_SUITES,
Packit aea12f
		.have_srp_cred = 1,
Packit aea12f
		.have_cert_cred = 1,
Packit aea12f
		.have_rsa_decrypt_cert = 1,
Packit aea12f
		.have_ecc_sign_cert = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 SRP-RSA with cred",
Packit aea12f
		.server_ret = 0,
Packit aea12f
		.client_ret = 0,
Packit aea12f
		.have_srp_cred = 1,
Packit aea12f
		.have_cert_cred = 1,
Packit aea12f
		.have_rsa_sign_cert = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 SRP-RSA with cred and multiple certs",
Packit aea12f
		.server_ret = 0,
Packit aea12f
		.client_ret = 0,
Packit aea12f
		.have_srp_cred = 1,
Packit aea12f
		.have_cert_cred = 1,
Packit aea12f
		.have_rsa_sign_cert = 1,
Packit aea12f
		.have_ecc_sign_cert = 1,
Packit aea12f
		.have_rsa_decrypt_cert = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+SRP-RSA:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 SRP without srp cred",
Packit aea12f
		.client_ret = GNUTLS_E_AGAIN,
Packit aea12f
		.server_ret = GNUTLS_E_INSUFFICIENT_CREDENTIALS,
Packit aea12f
		.have_srp_cred = 0,
Packit aea12f
		.have_cert_cred = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+SRP:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+SRP:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit aea12f
	},
Packit aea12f
	{
Packit aea12f
		.name = "TLS 1.3 SRP with cred",
Packit aea12f
		.server_ret = 0,
Packit aea12f
		.client_ret = 0,
Packit aea12f
		.have_srp_cred = 1,
Packit aea12f
		.server_prio = "NORMAL:-KX-ALL:+SRP:"PVERSION,
Packit aea12f
		.client_prio = "NORMAL:-KX-ALL:+SRP:"PVERSION,
Packit aea12f
		.exp_version = GNUTLS_TLS1_2,
Packit Service 991b93
	},
Packit Service 991b93
#ifdef ENABLE_GOST
Packit Service 991b93
	{
Packit Service 991b93
		.name = "TLS 1.3 server, TLS 1.2 client VKO-GOST-12 with cred and GOST-256 cert",
Packit Service 991b93
		.server_ret = 0,
Packit Service 991b93
		.client_ret = 0,
Packit Service 991b93
		.have_cert_cred = 1,
Packit Service 991b93
		.have_gost12_256_cert = 1,
Packit Service 991b93
		.not_on_fips = 1,
Packit Service 991b93
		.server_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:"PVERSION,
Packit Service 991b93
		.client_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:" "-VERS-ALL:+VERS-TLS1.2",
Packit Service 991b93
		.exp_version = GNUTLS_TLS1_2,
Packit Service 991b93
	},
Packit Service 991b93
	{
Packit Service 991b93
		.name = "TLS 1.3 server, TLS 1.2 client VKO-GOST-12 with cred and GOST-512 cert",
Packit Service 991b93
		.server_ret = 0,
Packit Service 991b93
		.client_ret = 0,
Packit Service 991b93
		.have_cert_cred = 1,
Packit Service 991b93
		.have_gost12_512_cert = 1,
Packit Service 991b93
		.not_on_fips = 1,
Packit Service 991b93
		.server_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:"PVERSION,
Packit Service 991b93
		.client_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:" "-VERS-ALL:+VERS-TLS1.2",
Packit Service 991b93
		.exp_version = GNUTLS_TLS1_2,
Packit Service 991b93
	},
Packit Service 991b93
	{
Packit Service 991b93
		.name = "TLS 1.2 server TLS 1.3 client VKO-GOST-12 with cred and GOST-256 cert",
Packit Service 991b93
		.server_ret = 0,
Packit Service 991b93
		.client_ret = 0,
Packit Service 991b93
		.have_cert_cred = 1,
Packit Service 991b93
		.have_gost12_256_cert = 1,
Packit Service 991b93
		.not_on_fips = 1,
Packit Service 991b93
		.server_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:" "-VERS-ALL:+VERS-TLS1.2",
Packit Service 991b93
		.client_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:"PVERSION,
Packit Service 991b93
		.exp_version = GNUTLS_TLS1_2,
Packit Service 991b93
	},
Packit Service 991b93
	{
Packit Service 991b93
		.name = "TLS 1.2 server TLS 1.3 client with cred and GOST-512 cert",
Packit Service 991b93
		.server_ret = 0,
Packit Service 991b93
		.client_ret = 0,
Packit Service 991b93
		.have_cert_cred = 1,
Packit Service 991b93
		.have_gost12_512_cert = 1,
Packit Service 991b93
		.not_on_fips = 1,
Packit Service 991b93
		.server_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:" "-VERS-ALL:+VERS-TLS1.2",
Packit Service 991b93
		.client_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:"PVERSION,
Packit Service 991b93
		.exp_version = GNUTLS_TLS1_2,
Packit Service 991b93
	},
Packit Service 991b93
	/* Ideally for the next two test cases we should fallback to TLS 1.2 + GOST
Packit Service 991b93
	 * but this is unsuppored for now */
Packit Service 991b93
	{
Packit Service 991b93
		.name = "TLS 1.3 server and client VKO-GOST-12 with cred and GOST-256 cert",
Packit Service 991b93
		.server_ret = GNUTLS_E_NO_CIPHER_SUITES,
Packit Service 991b93
		.client_ret = GNUTLS_E_AGAIN,
Packit Service 991b93
		.have_cert_cred = 1,
Packit Service 991b93
		.have_gost12_256_cert = 1,
Packit Service 991b93
		.not_on_fips = 1,
Packit Service 991b93
		.server_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:"PVERSION,
Packit Service 991b93
		.client_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:"PVERSION,
Packit Service 991b93
		.exp_version = GNUTLS_TLS1_2,
Packit Service 991b93
	},
Packit Service 991b93
	{
Packit Service 991b93
		.name = "TLS 1.3 server and client VKO-GOST-12 with cred and GOST-512 cert",
Packit Service 991b93
		.server_ret = GNUTLS_E_NO_CIPHER_SUITES,
Packit Service 991b93
		.client_ret = GNUTLS_E_AGAIN,
Packit Service 991b93
		.have_cert_cred = 1,
Packit Service 991b93
		.have_gost12_512_cert = 1,
Packit Service 991b93
		.not_on_fips = 1,
Packit Service 991b93
		.server_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:"PVERSION,
Packit Service 991b93
		.client_prio = "NORMAL:-KX-ALL:+VKO-GOST-12:+GROUP-GOST-ALL:+CIPHER-GOST-ALL:+MAC-GOST-ALL:+SIGN-GOST-ALL:"PVERSION,
Packit Service 991b93
		.exp_version = GNUTLS_TLS1_2,
Packit Service 991b93
	},
Packit Service 991b93
#endif
Packit aea12f
};
Packit aea12f
Packit aea12f
void doit(void)
Packit aea12f
{
Packit aea12f
	unsigned i;
Packit aea12f
	global_init();
Packit aea12f
Packit aea12f
	for (i=0;i
Packit aea12f
		try(&tests[i]);
Packit aea12f
	}
Packit aea12f
Packit aea12f
	gnutls_global_deinit();
Packit aea12f
}