|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* Copyright (C) 2018 Nikos Mavrogiannopoulos
|
|
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 |
#include <stdio.h>
|
|
Packit |
aea12f |
#include <stdlib.h>
|
|
Packit |
aea12f |
#include <string.h>
|
|
Packit |
aea12f |
#include <errno.h>
|
|
Packit |
aea12f |
#include <assert.h>
|
|
Packit |
aea12f |
#include <gnutls/gnutls.h>
|
|
Packit |
aea12f |
#include "utils.h"
|
|
Packit |
aea12f |
#include "eagain-common.h"
|
|
Packit |
aea12f |
#include "cert-common.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Tests whether the post_client_hello callback can modify
|
|
Packit |
aea12f |
* the avalable priorities. This is used by apache's mod_gnutls.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
const char *side;
|
|
Packit |
aea12f |
static int pch_ok = 0;
|
|
Packit |
aea12f |
const char *override_prio = NULL;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static int post_client_hello_callback(gnutls_session_t session)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
assert(gnutls_priority_set_direct(session, override_prio, NULL) >= 0);
|
|
Packit |
aea12f |
pch_ok = 1;
|
|
Packit |
aea12f |
return 0;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static void tls_log_func(int level, const char *str)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
fprintf(stderr, "%s|<%d>| %s", side, level, str);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static
|
|
Packit |
aea12f |
void start(const char *name, const char *prio, gnutls_protocol_t exp_version)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
/* Server stuff. */
|
|
Packit |
aea12f |
gnutls_certificate_credentials_t serverx509cred;
|
|
Packit |
aea12f |
gnutls_session_t server;
|
|
Packit |
aea12f |
int sret = GNUTLS_E_AGAIN;
|
|
Packit |
aea12f |
/* Client stuff. */
|
|
Packit |
aea12f |
gnutls_certificate_credentials_t clientx509cred;
|
|
Packit |
aea12f |
gnutls_session_t client;
|
|
Packit |
aea12f |
int cret = GNUTLS_E_AGAIN;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
success("trying %s\n", name);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
pch_ok = 0;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* General init. */
|
|
Packit |
aea12f |
global_init();
|
|
Packit |
aea12f |
gnutls_global_set_log_function(tls_log_func);
|
|
Packit |
aea12f |
if (debug)
|
|
Packit |
aea12f |
gnutls_global_set_log_level(4);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Init server */
|
|
Packit |
aea12f |
assert(gnutls_certificate_allocate_credentials(&serverx509cred)>=0);
|
|
Packit |
aea12f |
assert(gnutls_certificate_set_x509_key_mem(serverx509cred,
|
|
Packit |
aea12f |
&server_cert, &server_key,
|
|
Packit |
aea12f |
GNUTLS_X509_FMT_PEM)>=0);
|
|
Packit |
aea12f |
assert(gnutls_init(&server, GNUTLS_SERVER)>=0);
|
|
Packit |
aea12f |
gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
|
|
Packit |
aea12f |
serverx509cred);
|
|
Packit |
aea12f |
assert(gnutls_priority_set_direct(server, prio, NULL)>=0);
|
|
Packit |
aea12f |
gnutls_transport_set_push_function(server, server_push);
|
|
Packit |
aea12f |
gnutls_transport_set_pull_function(server, server_pull);
|
|
Packit |
aea12f |
gnutls_transport_set_ptr(server, server);
|
|
Packit |
aea12f |
gnutls_handshake_set_post_client_hello_function(server,
|
|
Packit |
aea12f |
post_client_hello_callback);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
assert(gnutls_certificate_allocate_credentials(&clientx509cred)>=0);
|
|
Packit |
aea12f |
assert(gnutls_init(&client, GNUTLS_CLIENT)>=0);
|
|
Packit |
aea12f |
gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE,
|
|
Packit |
aea12f |
clientx509cred);
|
|
Packit |
aea12f |
assert(gnutls_priority_set_direct(client, prio, NULL)>=0);
|
|
Packit |
aea12f |
gnutls_transport_set_push_function(client, client_push);
|
|
Packit |
aea12f |
gnutls_transport_set_pull_function(client, client_pull);
|
|
Packit |
aea12f |
gnutls_transport_set_ptr(client, client);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
HANDSHAKE(client, server);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
assert(exp_version == gnutls_protocol_get_version(client));
|
|
Packit |
aea12f |
assert(exp_version == gnutls_protocol_get_version(server));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_bye(client, GNUTLS_SHUT_RDWR);
|
|
Packit |
aea12f |
gnutls_bye(server, GNUTLS_SHUT_RDWR);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_deinit(client);
|
|
Packit |
aea12f |
gnutls_deinit(server);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_certificate_free_credentials(serverx509cred);
|
|
Packit |
aea12f |
gnutls_certificate_free_credentials(clientx509cred);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_global_deinit();
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (pch_ok == 0)
|
|
Packit |
aea12f |
fail("Post client hello callback wasn't called\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
reset_buffers();
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
void doit(void)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
override_prio = "NORMAL";
|
|
Packit |
aea12f |
start("tls1.2-only", "NORMAL:-VERS-ALL:+VERS-TLS1.2", GNUTLS_TLS1_2);
|
|
Packit |
aea12f |
start("tls1.3-only", "NORMAL:-VERS-ALL:+VERS-TLS1.3", GNUTLS_TLS1_3);
|
|
Packit |
aea12f |
start("default", "NORMAL", GNUTLS_TLS1_3);
|
|
Packit |
aea12f |
override_prio = "NORMAL:-VERS-ALL:+VERS-TLS1.2";
|
|
Packit |
aea12f |
start("default overriden to TLS1.2-only", "NORMAL", GNUTLS_TLS1_2);
|
|
Packit |
aea12f |
}
|