2 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/ssl.h>
11 #include <openssl/err.h>
12 #include "ssltestlib.h"
16 static char *cert = NULL;
17 static char *privkey = NULL;
19 static int test_fatalerr(void)
21 SSL_CTX *sctx = NULL, *cctx = NULL;
22 SSL *sssl = NULL, *cssl = NULL;
23 const char *msg = "Dummy";
27 unsigned char dummyrec[] = {
28 0x17, 0x03, 0x03, 0x00, 0x05, 'D', 'u', 'm', 'm', 'y'
31 if (!TEST_true(create_ssl_ctx_pair(TLS_method(), TLS_method(), &sctx, &cctx,
36 * Deliberately set the cipher lists for client and server to be different
37 * to force a handshake failure.
39 if (!TEST_true(SSL_CTX_set_cipher_list(sctx, "AES128-SHA"))
40 || !TEST_true(SSL_CTX_set_cipher_list(cctx, "AES256-SHA"))
41 || !TEST_true(create_ssl_objects(sctx, cctx, &sssl, &cssl, NULL,
45 wbio = SSL_get_wbio(cssl);
46 if (!TEST_ptr(wbio)) {
47 printf("Unexpected NULL bio received\n");
51 /* Connection should fail */
52 if (!TEST_false(create_ssl_connection(sssl, cssl, SSL_ERROR_NONE)))
57 /* Inject a plaintext record from client to server */
58 if (!TEST_int_gt(BIO_write(wbio, dummyrec, sizeof(dummyrec)), 0))
61 /* SSL_read()/SSL_write should fail because of a previous fatal error */
62 if (!TEST_int_le(len = SSL_read(sssl, buf, sizeof(buf) - 1), 0)) {
64 TEST_error("Unexpected success reading data: %s\n", buf);
67 if (!TEST_int_le(SSL_write(sssl, msg, strlen(msg)), 0))
82 if (!TEST_ptr(cert = test_get_argument(0))
83 || !TEST_ptr(privkey = test_get_argument(1)))
86 ADD_TEST(test_fatalerr);