1 /* Based on BoringSSL's cert.c fuzzer */
2
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 #include <openssl/asn1.h>
8 #include <openssl/crypto.h>
9 #include <openssl/x509.h>
10 #include <openssl/x509v3.h>
11 #include <stdint.h>
12 #include <stdio.h>
13
14 #include <hf_ssl_lib.h>
15 #include <libhfuzz/libhfuzz.h>
16
LLVMFuzzerInitialize(int * argc,char *** argv)17 int LLVMFuzzerInitialize(int* argc, char*** argv) {
18 HFInit();
19 HFResetRand();
20 return 1;
21 }
22
LLVMFuzzerTestOneInput(const uint8_t * buf,size_t len)23 int LLVMFuzzerTestOneInput(const uint8_t* buf, size_t len) {
24 const uint8_t* b = buf;
25 X509* x = d2i_X509(NULL, &b, len);
26 if (x) {
27 BIO* o = BIO_new_fp(stdout, BIO_NOCLOSE);
28 X509_print_ex(o, x, XN_FLAG_RFC2253, X509_FLAG_COMPAT);
29
30 unsigned char* der = NULL;
31 i2d_X509(x, &der);
32 OPENSSL_free(der);
33
34 X509_free(x);
35 BIO_free(o);
36 }
37
38 return 0;
39 }
40
41 #ifdef __cplusplus
42 }
43 #endif
44