2 * Copyright 2017-2018 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 (!create_ssl_ctx_pair(SSLv23_method(), SSLv23_method(),
32 SSL3_VERSION, TLS_MAX_VERSION, &sctx, &cctx,
34 printf("Failed to create SSL_CTX pair\n");
39 * Deliberately set the cipher lists for client and server to be different
40 * to force a handshake failure.
42 if (!SSL_CTX_set_cipher_list(sctx, "AES128-SHA")
43 || !SSL_CTX_set_cipher_list(cctx, "AES256-SHA")) {
44 printf("Failed to set cipher lists\n");
48 if (!create_ssl_objects(sctx, cctx, &sssl, &cssl, NULL, NULL)) {
49 printf("Failed to create SSL objectx\n");
53 wbio = SSL_get_wbio(cssl);
55 printf("Unexpected NULL bio received\n");
59 if (create_ssl_connection(sssl, cssl)) {
60 printf("Unexpected success creating a connection\n");
66 /* Inject a plaintext record from client to server */
67 if (BIO_write(wbio, dummyrec, sizeof(dummyrec)) <= 0) {
68 printf("Unexpected failure injecting dummy record\n");
72 /* SSL_read()/SSL_write should fail because of a previous fatal error */
73 if ((len = SSL_read(sssl, buf, sizeof(buf) - 1)) > 0) {
75 printf("Unexpected success reading data: %s\n", buf);
78 if (SSL_write(sssl, msg, strlen(msg)) > 0) {
79 printf("Unexpected success writing data\n");
93 int main(int argc, char *argv[])
99 printf("Invalid argument count\n");
106 err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
108 CRYPTO_set_mem_debug(1);
109 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
111 ADD_TEST(test_fatalerr);
113 testresult = run_tests(argv[0]);
115 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
116 if (CRYPTO_mem_leaks(err) <= 0)