]> git.ipfire.org Git - thirdparty/openssl.git/blame - fuzz/client.c
Auto add a label depending on the type of issue they report.
[thirdparty/openssl.git] / fuzz / client.c
CommitLineData
4410f9d7 1/*
1212818e 2 * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
4410f9d7 3 *
0642931f 4 * Licensed under the Apache License 2.0 (the "License");
4410f9d7
KR
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
14a6570f 11#include <time.h>
4410f9d7
KR
12#include <openssl/rand.h>
13#include <openssl/ssl.h>
14#include <openssl/rsa.h>
76d1ba3a
KR
15#include <openssl/dsa.h>
16#include <openssl/ec.h>
17#include <openssl/dh.h>
4410f9d7
KR
18#include <openssl/err.h>
19#include "fuzzer.h"
20
710769f0
RS
21#include "rand.inc"
22
4410f9d7
KR
23/* unused, to avoid warning. */
24static int idx;
25
14a6570f
KR
26#define FUZZTIME 1485898104
27
28#define TIME_IMPL(t) { if (t != NULL) *t = FUZZTIME; return FUZZTIME; }
29
30/*
b12ae4a9
AP
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.
14a6570f 36 */
b12ae4a9 37#if !defined(_WIN32)
14a6570f
KR
38time_t time(time_t *t) TIME_IMPL(t)
39#endif
40
4410f9d7
KR
41int FuzzerInitialize(int *argc, char ***argv)
42{
43 STACK_OF(SSL_COMP) *comp_methods;
44
45 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL);
46 OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
47 ERR_get_state();
48 CRYPTO_free_ex_index(0, -1);
49 idx = SSL_get_ex_data_X509_STORE_CTX_idx();
9f08a1c6 50 FuzzerSetRand();
4410f9d7 51 comp_methods = SSL_COMP_get_compression_methods();
345bee91
MC
52 if (comp_methods != NULL)
53 sk_SSL_COMP_sort(comp_methods);
4410f9d7 54
4410f9d7
KR
55 return 1;
56}
57
58int FuzzerTestOneInput(const uint8_t *buf, size_t len)
59{
60 SSL *client;
61 BIO *in;
62 BIO *out;
63 SSL_CTX *ctx;
64
65 if (len == 0)
66 return 0;
67
68 /*
69 * TODO: use the ossltest engine (optionally?) to disable crypto checks.
70 */
71
72 /* This only fuzzes the initial flow from the client so far. */
73 ctx = SSL_CTX_new(SSLv23_method());
74
75 client = SSL_new(ctx);
07fc8d52 76 OPENSSL_assert(SSL_set_min_proto_version(client, 0) == 1);
4e995479
KR
77 OPENSSL_assert(SSL_set_cipher_list(client, "ALL:eNULL:@SECLEVEL=0") == 1);
78 SSL_set_tlsext_host_name(client, "localhost");
4410f9d7
KR
79 in = BIO_new(BIO_s_mem());
80 out = BIO_new(BIO_s_mem());
81 SSL_set_bio(client, in, out);
82 SSL_set_connect_state(client);
83 OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
84 if (SSL_do_handshake(client) == 1) {
85 /* Keep reading application data until error or EOF. */
86 uint8_t tmp[1024];
87 for (;;) {
88 if (SSL_read(client, tmp, sizeof(tmp)) <= 0) {
89 break;
90 }
91 }
92 }
93 SSL_free(client);
94 ERR_clear_error();
95 SSL_CTX_free(ctx);
96
97 return 0;
98}
99
100void FuzzerCleanup(void)
101{
102}