blob: db090c59ad8fa7031be1ebf0d46eccedeeb136ca [file] [log] [blame]
Daniel McArdle00e434d2021-02-18 11:47:18 -05001/* Copyright (c) 2021, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15#include <openssl/bytestring.h>
16#include <openssl/ssl.h>
17#include <openssl/span.h>
18
19#include "../ssl/internal.h"
20
21
22extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
23 static bssl::UniquePtr<SSL_CTX> ctx(SSL_CTX_new(TLS_method()));
24 static bssl::UniquePtr<SSL> ssl(SSL_new(ctx.get()));
25
26 CBS reader(bssl::MakeConstSpan(buf, len));
27 CBS encoded_client_hello_inner_cbs;
28
29 if (!CBS_get_u24_length_prefixed(&reader, &encoded_client_hello_inner_cbs)) {
30 return 0;
31 }
32
33 bssl::Array<uint8_t> encoded_client_hello_inner;
34 if (!encoded_client_hello_inner.CopyFrom(encoded_client_hello_inner_cbs)) {
35 return 0;
36 }
37
38 // Use the remaining bytes in |reader| as the ClientHelloOuter.
39 SSL_CLIENT_HELLO client_hello_outer;
40 if (!bssl::ssl_client_hello_init(ssl.get(), &client_hello_outer, reader)) {
41 return 0;
42 }
43
44 // Recover the ClientHelloInner from the EncodedClientHelloInner and
45 // ClientHelloOuter.
46 uint8_t alert_unused;
47 bssl::Array<uint8_t> client_hello_inner;
48 bssl::ssl_decode_client_hello_inner(
49 ssl.get(), &alert_unused, &client_hello_inner, encoded_client_hello_inner,
50 &client_hello_outer);
51 return 0;
52}