|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* Copyright (C) 2016 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 General Public License
|
|
Packit |
aea12f |
* along with GnuTLS; if not, write to the Free Software Foundation,
|
|
Packit |
aea12f |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
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 <gnutls/gnutls.h>
|
|
Packit |
aea12f |
#include "utils.h"
|
|
Packit |
aea12f |
#include "eagain-common.h"
|
|
Packit |
aea12f |
#include "cert-common.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* This program tests whether rehandshake without ext master secret works
|
|
Packit |
aea12f |
* even if ext master secret was used initially.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Note that we do not fail gracefully and we simply continue as if
|
|
Packit |
aea12f |
* the extension is still valid. This violates the letter of RFC7627.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
const char *side = "";
|
|
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 void try(unsigned onclient)
|
|
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 |
/* 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(7);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Init server */
|
|
Packit |
aea12f |
gnutls_certificate_allocate_credentials(&serverx509cred);
|
|
Packit |
aea12f |
gnutls_certificate_set_x509_key_mem(serverx509cred,
|
|
Packit |
aea12f |
&server_cert, &server_key,
|
|
Packit |
aea12f |
GNUTLS_X509_FMT_PEM);
|
|
Packit |
aea12f |
gnutls_init(&server, GNUTLS_SERVER);
|
|
Packit |
aea12f |
gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
|
|
Packit |
aea12f |
serverx509cred);
|
|
Packit |
aea12f |
gnutls_priority_set_direct(server, "NORMAL:-VERS-ALL:+VERS-TLS1.2", NULL);
|
|
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 |
|
|
Packit |
aea12f |
/* Init client */
|
|
Packit |
aea12f |
gnutls_certificate_allocate_credentials(&clientx509cred);
|
|
Packit |
aea12f |
gnutls_init(&client, GNUTLS_CLIENT);
|
|
Packit |
aea12f |
gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE,
|
|
Packit |
aea12f |
clientx509cred);
|
|
Packit |
aea12f |
gnutls_priority_set_direct(client, "NORMAL:-VERS-ALL:+VERS-TLS1.2", NULL);
|
|
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 |
if (gnutls_session_ext_master_secret_status(server) == 0) {
|
|
Packit |
aea12f |
fail("%d: ext master secret was not detected by server\n", onclient);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (gnutls_session_ext_master_secret_status(client) == 0) {
|
|
Packit |
aea12f |
fail("%d: ext master secret was not detected by client\n", onclient);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if ((gnutls_session_get_flags(server) & GNUTLS_SFLAGS_EXT_MASTER_SECRET) == 0) {
|
|
Packit |
aea12f |
fail("%d: ext master secret was not detected by server\n", onclient);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if ((gnutls_session_get_flags(client) & GNUTLS_SFLAGS_EXT_MASTER_SECRET) == 0) {
|
|
Packit |
aea12f |
fail("%d: ext master secret was not detected by client\n", onclient);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (onclient)
|
|
Packit |
aea12f |
gnutls_priority_set_direct(client, "NORMAL:-VERS-ALL:+VERS-TLS1.2:%NO_SESSION_HASH", NULL);
|
|
Packit |
aea12f |
else
|
|
Packit |
aea12f |
gnutls_priority_set_direct(server, "NORMAL:-VERS-ALL:+VERS-TLS1.2:%NO_SESSION_HASH", NULL);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
sret = gnutls_rehandshake(server);
|
|
Packit |
aea12f |
if (debug) {
|
|
Packit |
aea12f |
tls_log_func(0, "gnutls_rehandshake (server)...\n");
|
|
Packit |
aea12f |
tls_log_func(0, gnutls_strerror(sret));
|
|
Packit |
aea12f |
tls_log_func(0, "\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
ssize_t n;
|
|
Packit |
aea12f |
char b[1];
|
|
Packit |
aea12f |
n = gnutls_record_recv(client, b, 1);
|
|
Packit |
aea12f |
if (n != GNUTLS_E_REHANDSHAKE)
|
|
Packit |
aea12f |
abort();
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (onclient) {
|
|
Packit |
aea12f |
HANDSHAKE_EXPECT(client, server, GNUTLS_E_AGAIN, GNUTLS_E_DECRYPTION_FAILED);
|
|
Packit |
aea12f |
} else {
|
|
Packit |
aea12f |
HANDSHAKE_EXPECT(client, server, GNUTLS_E_AGAIN, GNUTLS_E_DECRYPTION_FAILED);
|
|
Packit |
aea12f |
}
|
|
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 |
|
|
Packit |
aea12f |
void doit(void)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
try(0);
|
|
Packit |
aea12f |
reset_buffers();
|
|
Packit |
aea12f |
try(1);
|
|
Packit |
aea12f |
}
|