]> git.ipfire.org Git - thirdparty/openssl.git/blame - fuzz/x509.c
Make x509 and asn1 fuzzer reproducible
[thirdparty/openssl.git] / fuzz / x509.c
CommitLineData
e1859d8d
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/x509.h>
12#include <openssl/bio.h>
d69d8f90 13#include <openssl/err.h>
b534df96 14#include <openssl/rand.h>
e1859d8d
KR
15#include "fuzzer.h"
16
b534df96
KR
17#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
18extern int rand_predictable;
19#endif
20#define ENTROPY_NEEDED 32
21
f3e911d5
KR
22int FuzzerInitialize(int *argc, char ***argv)
23{
d69d8f90
KR
24 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
25 ERR_get_state();
26 CRYPTO_free_ex_index(0, -1);
b534df96
KR
27 RAND_add("", 1, ENTROPY_NEEDED);
28 RAND_status();
29
30#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
31 rand_predictable = 1;
32#endif
a05b0bcf
KR
33 return 1;
34}
35
f3e911d5
KR
36int FuzzerTestOneInput(const uint8_t *buf, size_t len)
37{
e1859d8d
KR
38 const unsigned char *p = buf;
39 unsigned char *der = NULL;
40
41 X509 *x509 = d2i_X509(NULL, &p, len);
42 if (x509 != NULL) {
43 BIO *bio = BIO_new(BIO_s_null());
03cb37ac 44 /* This will load and print the public key as well as extensions */
e1859d8d
KR
45 X509_print(bio, x509);
46 BIO_free(bio);
47
48 i2d_X509(x509, &der);
49 OPENSSL_free(der);
50
51 X509_free(x509);
52 }
d69d8f90 53 ERR_clear_error();
e1859d8d
KR
54 return 0;
55}
ad4da7fb
KR
56
57void FuzzerCleanup(void)
58{
59}