2 * Copyright (C) 2016 Red Hat, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * GnuTLS is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * GnuTLS is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GnuTLS; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
30 /* In this test we check whether the server will bail out after receiving
31 * a bunch of warning alerts without a client hello.
36 /* socketpair isn't supported on Win32. */
37 int main(int argc, char **argv)
45 #include <sys/types.h>
46 #include <sys/socket.h>
51 #include <gnutls/gnutls.h>
54 #include "cert-common.h"
58 static void tls_log_func(int level, const char *str)
60 fprintf(stderr, "%s |<%d>| %s", child ? "server" : "client", level,
64 static unsigned char tls_alert[] =
65 "\x15\x03\x03\x00\x02\x00\x0A";
67 static void client(int sd)
72 /* send a list of warning alerts */
75 ret = send(sd, tls_alert, sizeof(tls_alert)-1, 0);
77 fail("error sending hello\n");
83 static void server(int sd)
85 gnutls_certificate_credentials_t x509_cred;
86 gnutls_session_t session;
90 /* this must be called once in the program
94 gnutls_global_set_log_function(tls_log_func);
96 gnutls_global_set_log_level(6);
98 gnutls_certificate_allocate_credentials(&x509_cred);
99 gnutls_certificate_set_x509_trust_mem(x509_cred, &ca3_cert,
100 GNUTLS_X509_FMT_PEM);
102 gnutls_certificate_set_x509_key_mem(x509_cred, &server_ca3_localhost_cert,
104 GNUTLS_X509_FMT_PEM);
107 success("Launched, generating DH parameters...\n");
109 gnutls_init(&session, GNUTLS_SERVER);
111 /* avoid calling all the priority functions, since the defaults
114 gnutls_priority_set_direct(session, "NORMAL", NULL);
116 gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
118 gnutls_transport_set_int(session, sd);
121 ret = gnutls_handshake(session);
124 fail("Too many loops in the handshake!\n");
125 } while (ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_WARNING_ALERT_RECEIVED);
127 if (ret != GNUTLS_E_UNEXPECTED_PACKET) {
128 fail("server: Handshake didn't fail with expected code (failed with %d)\n", ret);
132 gnutls_deinit(session);
134 gnutls_certificate_free_credentials(x509_cred);
136 gnutls_global_deinit();
139 success("server: finished\n");
148 err = socketpair(AF_UNIX, SOCK_STREAM, 0, sockets);
150 perror("socketpair");
151 fail("socketpair failed\n");