|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2016 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit Service |
4684c1 |
* under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
4684c1 |
* (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
4684c1 |
* along with GnuTLS; if not, write to the Free Software Foundation,
|
|
Packit Service |
4684c1 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <stdio.h>
|
|
Packit Service |
4684c1 |
#include <stdlib.h>
|
|
Packit Service |
4684c1 |
#include <string.h>
|
|
Packit Service |
4684c1 |
#include <errno.h>
|
|
Packit Service |
4684c1 |
#include <gnutls/gnutls.h>
|
|
Packit Service |
4684c1 |
#include "utils.h"
|
|
Packit Service |
4684c1 |
#include "eagain-common.h"
|
|
Packit Service |
4684c1 |
#include "cert-common.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* This program tests whether rehandshake without ext master secret works
|
|
Packit Service |
4684c1 |
* even if ext master secret was used initially.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Note that we do not fail gracefully and we simply continue as if
|
|
Packit Service |
4684c1 |
* the extension is still valid. This violates the letter of RFC7627.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const char *side = "";
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void tls_log_func(int level, const char *str)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
fprintf(stderr, "%s|<%d>| %s", side, level, str);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void try(unsigned onclient)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
/* Server stuff. */
|
|
Packit Service |
4684c1 |
gnutls_certificate_credentials_t serverx509cred;
|
|
Packit Service |
4684c1 |
gnutls_session_t server;
|
|
Packit Service |
4684c1 |
int sret = GNUTLS_E_AGAIN;
|
|
Packit Service |
4684c1 |
/* Client stuff. */
|
|
Packit Service |
4684c1 |
gnutls_certificate_credentials_t clientx509cred;
|
|
Packit Service |
4684c1 |
gnutls_session_t client;
|
|
Packit Service |
4684c1 |
int cret = GNUTLS_E_AGAIN;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* General init. */
|
|
Packit Service |
4684c1 |
global_init();
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_function(tls_log_func);
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_level(7);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Init server */
|
|
Packit Service |
4684c1 |
gnutls_certificate_allocate_credentials(&serverx509cred);
|
|
Packit Service |
4684c1 |
gnutls_certificate_set_x509_key_mem(serverx509cred,
|
|
Packit Service |
4684c1 |
&server_cert, &server_key,
|
|
Packit Service |
4684c1 |
GNUTLS_X509_FMT_PEM);
|
|
Packit Service |
4684c1 |
gnutls_init(&server, GNUTLS_SERVER);
|
|
Packit Service |
4684c1 |
gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
|
|
Packit Service |
4684c1 |
serverx509cred);
|
|
Packit Service |
4684c1 |
gnutls_priority_set_direct(server, "NORMAL:-VERS-ALL:+VERS-TLS1.2", NULL);
|
|
Packit Service |
4684c1 |
gnutls_transport_set_push_function(server, server_push);
|
|
Packit Service |
4684c1 |
gnutls_transport_set_pull_function(server, server_pull);
|
|
Packit Service |
4684c1 |
gnutls_transport_set_ptr(server, server);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Init client */
|
|
Packit Service |
4684c1 |
gnutls_certificate_allocate_credentials(&clientx509cred);
|
|
Packit Service |
4684c1 |
gnutls_init(&client, GNUTLS_CLIENT);
|
|
Packit Service |
4684c1 |
gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE,
|
|
Packit Service |
4684c1 |
clientx509cred);
|
|
Packit Service |
4684c1 |
gnutls_priority_set_direct(client, "NORMAL:-VERS-ALL:+VERS-TLS1.2", NULL);
|
|
Packit Service |
4684c1 |
gnutls_transport_set_push_function(client, client_push);
|
|
Packit Service |
4684c1 |
gnutls_transport_set_pull_function(client, client_pull);
|
|
Packit Service |
4684c1 |
gnutls_transport_set_ptr(client, client);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
HANDSHAKE(client, server);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (gnutls_session_ext_master_secret_status(server) == 0) {
|
|
Packit Service |
4684c1 |
fail("%d: ext master secret was not detected by server\n", onclient);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (gnutls_session_ext_master_secret_status(client) == 0) {
|
|
Packit Service |
4684c1 |
fail("%d: ext master secret was not detected by client\n", onclient);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if ((gnutls_session_get_flags(server) & GNUTLS_SFLAGS_EXT_MASTER_SECRET) == 0) {
|
|
Packit Service |
4684c1 |
fail("%d: ext master secret was not detected by server\n", onclient);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if ((gnutls_session_get_flags(client) & GNUTLS_SFLAGS_EXT_MASTER_SECRET) == 0) {
|
|
Packit Service |
4684c1 |
fail("%d: ext master secret was not detected by client\n", onclient);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (onclient)
|
|
Packit Service |
4684c1 |
gnutls_priority_set_direct(client, "NORMAL:-VERS-ALL:+VERS-TLS1.2:%NO_SESSION_HASH", NULL);
|
|
Packit Service |
4684c1 |
else
|
|
Packit Service |
4684c1 |
gnutls_priority_set_direct(server, "NORMAL:-VERS-ALL:+VERS-TLS1.2:%NO_SESSION_HASH", NULL);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
sret = gnutls_rehandshake(server);
|
|
Packit Service |
4684c1 |
if (debug) {
|
|
Packit Service |
4684c1 |
tls_log_func(0, "gnutls_rehandshake (server)...\n");
|
|
Packit Service |
4684c1 |
tls_log_func(0, gnutls_strerror(sret));
|
|
Packit Service |
4684c1 |
tls_log_func(0, "\n");
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
ssize_t n;
|
|
Packit Service |
4684c1 |
char b[1];
|
|
Packit Service |
4684c1 |
n = gnutls_record_recv(client, b, 1);
|
|
Packit Service |
4684c1 |
if (n != GNUTLS_E_REHANDSHAKE)
|
|
Packit Service |
4684c1 |
abort();
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (onclient) {
|
|
Packit Service |
4684c1 |
HANDSHAKE_EXPECT(client, server, GNUTLS_E_AGAIN, GNUTLS_E_DECRYPTION_FAILED);
|
|
Packit Service |
4684c1 |
} else {
|
|
Packit Service |
4684c1 |
HANDSHAKE_EXPECT(client, server, GNUTLS_E_AGAIN, GNUTLS_E_DECRYPTION_FAILED);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_deinit(client);
|
|
Packit Service |
4684c1 |
gnutls_deinit(server);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_certificate_free_credentials(serverx509cred);
|
|
Packit Service |
4684c1 |
gnutls_certificate_free_credentials(clientx509cred);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_global_deinit();
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void doit(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
try(0);
|
|
Packit Service |
4684c1 |
reset_buffers();
|
|
Packit Service |
4684c1 |
try(1);
|
|
Packit Service |
4684c1 |
}
|