]> git.ipfire.org Git - thirdparty/openssl.git/blame - fuzz/x509.c
RAND_METHOD deprecation: fuzzer
[thirdparty/openssl.git] / fuzz / x509.c
CommitLineData
e1859d8d 1/*
a28d06f3 2 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
e1859d8d 3 *
0642931f 4 * Licensed under the Apache License 2.0 (the "License");
e1859d8d
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
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
f3e911d5
KR
17int FuzzerInitialize(int *argc, char ***argv)
18{
de2ea978 19 FuzzerSetRand();
d69d8f90 20 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
e5d4233f 21 ERR_clear_error();
d69d8f90 22 CRYPTO_free_ex_index(0, -1);
a05b0bcf
KR
23 return 1;
24}
25
f3e911d5
KR
26int FuzzerTestOneInput(const uint8_t *buf, size_t len)
27{
e1859d8d
KR
28 const unsigned char *p = buf;
29 unsigned char *der = NULL;
30
31 X509 *x509 = d2i_X509(NULL, &p, len);
32 if (x509 != NULL) {
33 BIO *bio = BIO_new(BIO_s_null());
03cb37ac 34 /* This will load and print the public key as well as extensions */
e1859d8d
KR
35 X509_print(bio, x509);
36 BIO_free(bio);
37
55869f59
MC
38 X509_issuer_and_serial_hash(x509);
39
e1859d8d
KR
40 i2d_X509(x509, &der);
41 OPENSSL_free(der);
42
43 X509_free(x509);
44 }
d69d8f90 45 ERR_clear_error();
e1859d8d
KR
46 return 0;
47}
ad4da7fb
KR
48
49void FuzzerCleanup(void)
50{
de2ea978 51 FuzzerClearRand();
ad4da7fb 52}