/src/libressl.fuzzers/client.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (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 <time.h> |
12 | | #include <openssl/rand.h> |
13 | | #include <openssl/ssl.h> |
14 | | #include <openssl/rsa.h> |
15 | | #include <openssl/dsa.h> |
16 | | #include <openssl/ec.h> |
17 | | #include <openssl/dh.h> |
18 | | #include <openssl/err.h> |
19 | | #include "fuzzer.h" |
20 | | |
21 | | #include "rand.inc" |
22 | | |
23 | | /* unused, to avoid warning. */ |
24 | | static int idx; |
25 | | |
26 | 12.4k | #define FUZZTIME 1485898104 |
27 | | |
28 | 12.4k | #define TIME_IMPL(t) { if (t != NULL) *t = FUZZTIME; return FUZZTIME; } |
29 | | |
30 | | /* |
31 | | * This might not work in all cases (and definitely not on Windows |
32 | | * because of the way linkers are) and callees can still get the |
33 | | * current time instead of the fixed time. This will just result |
34 | | * in things not being fully reproducible and have a slightly |
35 | | * different coverage. |
36 | | */ |
37 | | #if !defined(_WIN32) |
38 | | time_t time(time_t *t) TIME_IMPL(t) |
39 | | #endif |
40 | | |
41 | | int FuzzerInitialize(int *argc, char ***argv) |
42 | 4 | { |
43 | 4 | STACK_OF(SSL_COMP) *comp_methods; |
44 | | |
45 | 4 | OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL); |
46 | 4 | OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL); |
47 | 4 | idx = SSL_get_ex_data_X509_STORE_CTX_idx(); |
48 | 4 | FuzzerSetRand(); |
49 | 4 | comp_methods = SSL_COMP_get_compression_methods(); |
50 | 4 | if (comp_methods != NULL) |
51 | 4 | sk_SSL_COMP_sort(comp_methods); |
52 | | |
53 | 4 | return 1; |
54 | 4 | } |
55 | | |
56 | | int FuzzerTestOneInput(const uint8_t *buf, size_t len) |
57 | 5.65k | { |
58 | 5.65k | SSL *client; |
59 | 5.65k | BIO *in; |
60 | 5.65k | BIO *out; |
61 | 5.65k | SSL_CTX *ctx; |
62 | | |
63 | 5.65k | if (len == 0) |
64 | 0 | return 0; |
65 | | |
66 | | /* |
67 | | * TODO: use the ossltest engine (optionally?) to disable crypto checks. |
68 | | */ |
69 | | |
70 | | /* This only fuzzes the initial flow from the client so far. */ |
71 | 5.65k | ctx = SSL_CTX_new(SSLv23_method()); |
72 | | |
73 | 5.65k | client = SSL_new(ctx); |
74 | 5.65k | OPENSSL_assert(SSL_set_min_proto_version(client, 0) == 1); |
75 | 5.65k | OPENSSL_assert(SSL_set_cipher_list(client, "ALL:eNULL") == 1); |
76 | 5.65k | SSL_set_tlsext_host_name(client, "localhost"); |
77 | 5.65k | in = BIO_new(BIO_s_mem()); |
78 | 5.65k | out = BIO_new(BIO_s_mem()); |
79 | 5.65k | SSL_set_bio(client, in, out); |
80 | 5.65k | SSL_set_connect_state(client); |
81 | 5.65k | OPENSSL_assert((size_t)BIO_write(in, buf, len) == len); |
82 | 5.65k | if (SSL_do_handshake(client) == 1) { |
83 | | /* Keep reading application data until error or EOF. */ |
84 | 0 | uint8_t tmp[1024]; |
85 | 0 | for (;;) { |
86 | 0 | if (SSL_read(client, tmp, sizeof(tmp)) <= 0) { |
87 | 0 | break; |
88 | 0 | } |
89 | 0 | } |
90 | 0 | } |
91 | 5.65k | SSL_free(client); |
92 | 5.65k | ERR_clear_error(); |
93 | 5.65k | SSL_CTX_free(ctx); |
94 | | |
95 | 5.65k | return 0; |
96 | 5.65k | } |
97 | | |
98 | | void FuzzerCleanup(void) |
99 | 0 | { |
100 | 0 | } |