]>
Commit | Line | Data |
---|---|---|
4410f9d7 KR |
1 | /* |
2 | * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
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. | |
9 | */ | |
10 | ||
11 | #include <openssl/rand.h> | |
12 | #include <openssl/ssl.h> | |
13 | #include <openssl/rsa.h> | |
14 | #include <openssl/err.h> | |
15 | #include "fuzzer.h" | |
16 | ||
17 | #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION | |
18 | extern int rand_predictable; | |
19 | #endif | |
20 | #define ENTROPY_NEEDED 32 | |
21 | ||
22 | /* unused, to avoid warning. */ | |
23 | static int idx; | |
24 | ||
25 | int FuzzerInitialize(int *argc, char ***argv) | |
26 | { | |
27 | STACK_OF(SSL_COMP) *comp_methods; | |
28 | ||
29 | OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL); | |
30 | OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL); | |
31 | ERR_get_state(); | |
32 | CRYPTO_free_ex_index(0, -1); | |
33 | idx = SSL_get_ex_data_X509_STORE_CTX_idx(); | |
34 | RAND_add("", 1, ENTROPY_NEEDED); | |
35 | RAND_status(); | |
36 | RSA_get_default_method(); | |
37 | comp_methods = SSL_COMP_get_compression_methods(); | |
38 | OPENSSL_sk_sort((OPENSSL_STACK *)comp_methods); | |
39 | ||
40 | ||
41 | #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION | |
42 | rand_predictable = 1; | |
43 | #endif | |
44 | ||
45 | return 1; | |
46 | } | |
47 | ||
48 | int FuzzerTestOneInput(const uint8_t *buf, size_t len) | |
49 | { | |
50 | SSL *client; | |
51 | BIO *in; | |
52 | BIO *out; | |
53 | SSL_CTX *ctx; | |
54 | ||
55 | if (len == 0) | |
56 | return 0; | |
57 | ||
58 | /* | |
59 | * TODO: use the ossltest engine (optionally?) to disable crypto checks. | |
60 | */ | |
61 | ||
62 | /* This only fuzzes the initial flow from the client so far. */ | |
63 | ctx = SSL_CTX_new(SSLv23_method()); | |
64 | ||
65 | client = SSL_new(ctx); | |
4e995479 KR |
66 | OPENSSL_assert(SSL_set_cipher_list(client, "ALL:eNULL:@SECLEVEL=0") == 1); |
67 | SSL_set_tlsext_host_name(client, "localhost"); | |
4410f9d7 KR |
68 | in = BIO_new(BIO_s_mem()); |
69 | out = BIO_new(BIO_s_mem()); | |
70 | SSL_set_bio(client, in, out); | |
71 | SSL_set_connect_state(client); | |
72 | OPENSSL_assert((size_t)BIO_write(in, buf, len) == len); | |
73 | if (SSL_do_handshake(client) == 1) { | |
74 | /* Keep reading application data until error or EOF. */ | |
75 | uint8_t tmp[1024]; | |
76 | for (;;) { | |
77 | if (SSL_read(client, tmp, sizeof(tmp)) <= 0) { | |
78 | break; | |
79 | } | |
80 | } | |
81 | } | |
82 | SSL_free(client); | |
83 | ERR_clear_error(); | |
84 | SSL_CTX_free(ctx); | |
85 | ||
86 | return 0; | |
87 | } | |
88 | ||
89 | void FuzzerCleanup(void) | |
90 | { | |
91 | } |