2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL licenses, (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.openssl.org/source/license.html
8 * or in the file LICENSE in the source distribution.
11 #include <openssl/rand.h>
12 #include <openssl/ssl.h>
13 #include <openssl/rsa.h>
14 #include <openssl/dsa.h>
15 #include <openssl/ec.h>
16 #include <openssl/dh.h>
17 #include <openssl/err.h>
20 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
21 extern int rand_predictable;
23 #define ENTROPY_NEEDED 32
25 /* unused, to avoid warning. */
28 int FuzzerInitialize(int *argc, char ***argv)
30 STACK_OF(SSL_COMP) *comp_methods;
32 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL);
33 OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
35 CRYPTO_free_ex_index(0, -1);
36 idx = SSL_get_ex_data_X509_STORE_CTX_idx();
37 RAND_add("", 1, ENTROPY_NEEDED);
39 RSA_get_default_method();
40 #ifndef OPENSSL_NO_DSA
41 DSA_get_default_method();
44 EC_KEY_get_default_method();
47 DH_get_default_method();
49 comp_methods = SSL_COMP_get_compression_methods();
50 OPENSSL_sk_sort((OPENSSL_STACK *)comp_methods);
53 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
60 int FuzzerTestOneInput(const uint8_t *buf, size_t len)
71 * TODO: use the ossltest engine (optionally?) to disable crypto checks.
74 /* This only fuzzes the initial flow from the client so far. */
75 ctx = SSL_CTX_new(SSLv23_method());
77 client = SSL_new(ctx);
78 OPENSSL_assert(SSL_set_cipher_list(client, "ALL:eNULL:@SECLEVEL=0") == 1);
79 SSL_set_tlsext_host_name(client, "localhost");
80 in = BIO_new(BIO_s_mem());
81 out = BIO_new(BIO_s_mem());
82 SSL_set_bio(client, in, out);
83 SSL_set_connect_state(client);
84 OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
85 if (SSL_do_handshake(client) == 1) {
86 /* Keep reading application data until error or EOF. */
89 if (SSL_read(client, tmp, sizeof(tmp)) <= 0) {
101 void FuzzerCleanup(void)