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"
14 int main(int argc, char *argv[])
18 const char *msg = "Dummy";
19 BIO *err = NULL, *wbio = NULL;
22 unsigned char dummyrec[] = {
23 0x17, 0x03, 0x03, 0x00, 0x05, 'D', 'u', 'm', 'm', 'y'
27 printf("Incorrect number of parameters\n");
32 SSL_load_error_strings();
33 err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
34 CRYPTO_malloc_debug_init();
35 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
36 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
38 if (!create_ssl_ctx_pair(SSLv23_method(), SSLv23_method(), &sctx, &cctx,
40 printf("Failed to create SSL_CTX pair\n");
45 * Deliberately set the cipher lists for client and server to be different
46 * to force a handshake failure.
48 if (!SSL_CTX_set_cipher_list(sctx, "AES128-SHA")
49 || !SSL_CTX_set_cipher_list(cctx, "AES256-SHA")) {
50 printf("Failed to set cipher lists\n");
54 if (!create_ssl_objects(sctx, cctx, &sssl, &cssl, NULL, NULL)) {
55 printf("Failed to create SSL objectx\n");
59 wbio = SSL_get_wbio(cssl);
61 printf("Unexpected NULL bio received\n");
65 if (create_ssl_connection(sssl, cssl)) {
66 printf("Unexpected success creating a connection\n");
72 /* Inject a plaintext record from client to server */
73 if (BIO_write(wbio, dummyrec, sizeof(dummyrec)) <= 0) {
74 printf("Unexpected failure injecting dummy record\n");
78 /* SSL_read()/SSL_write should fail because of a previous fatal error */
79 if ((len = SSL_read(sssl, buf, sizeof(buf - 1))) > 0) {
81 printf("Unexpected success reading data: %s\n", buf);
84 if (SSL_write(sssl, msg, strlen(msg)) > 0) {
85 printf("Unexpected success writing data\n");
95 ERR_print_errors_fp(stderr);
98 printf("Fatal err test: FAILED\n");
102 ERR_remove_thread_state(NULL);
104 CRYPTO_cleanup_all_ex_data();
105 CRYPTO_mem_leaks(err);