]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/fatalerrtest.c
2 * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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 "helpers/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(NULL
, TLS_method(), TLS_method(),
33 &sctx
, &cctx
, cert
, privkey
)))
37 * Deliberately set the cipher lists for client and server to be different
38 * to force a handshake failure.
40 if (!TEST_true(SSL_CTX_set_cipher_list(sctx
, "AES128-SHA"))
41 || !TEST_true(SSL_CTX_set_cipher_list(cctx
, "AES256-SHA"))
42 || !TEST_true(SSL_CTX_set_ciphersuites(sctx
,
43 "TLS_AES_128_GCM_SHA256"))
44 || !TEST_true(SSL_CTX_set_ciphersuites(cctx
,
45 "TLS_AES_256_GCM_SHA384"))
46 || !TEST_true(create_ssl_objects(sctx
, cctx
, &sssl
, &cssl
, NULL
,
50 wbio
= SSL_get_wbio(cssl
);
51 if (!TEST_ptr(wbio
)) {
52 printf("Unexpected NULL bio received\n");
56 /* Connection should fail */
57 if (!TEST_false(create_ssl_connection(sssl
, cssl
, SSL_ERROR_NONE
)))
62 /* Inject a plaintext record from client to server */
63 if (!TEST_int_gt(BIO_write(wbio
, dummyrec
, sizeof(dummyrec
)), 0))
66 /* SSL_read()/SSL_write should fail because of a previous fatal error */
67 if (!TEST_int_le(len
= SSL_read(sssl
, buf
, sizeof(buf
) - 1), 0)) {
69 TEST_error("Unexpected success reading data: %s\n", buf
);
72 if (!TEST_int_le(SSL_write(sssl
, msg
, strlen(msg
)), 0))
85 OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")
89 if (!test_skip_common_options()) {
90 TEST_error("Error parsing test options\n");
94 if (!TEST_ptr(cert
= test_get_argument(0))
95 || !TEST_ptr(privkey
= test_get_argument(1)))
98 ADD_TEST(test_fatalerr
);