]> git.ipfire.org Git - thirdparty/openssl.git/blame - fuzz/asn1.c
Add X509 and CRL fuzzer
[thirdparty/openssl.git] / fuzz / asn1.c
CommitLineData
c38bb727
BL
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/*
12 * Fuzz ASN.1 parsing for various data structures. Specify which on the
13 * command line:
14 *
15 * asn1 <data structure>
16 */
17
18#include <stdio.h>
19#include <string.h>
20#include <openssl/asn1.h>
21#include <openssl/asn1t.h>
22#include <openssl/ec.h>
23#include <openssl/ocsp.h>
24#include <openssl/pkcs12.h>
25#include <openssl/ts.h>
26#include <openssl/x509v3.h>
27#include "fuzzer.h"
28
e298cb10
BL
29static const ASN1_ITEM *item_type[] = {
30 ASN1_ITEM_rptr(ASN1_SEQUENCE),
31 ASN1_ITEM_rptr(AUTHORITY_INFO_ACCESS),
32 ASN1_ITEM_rptr(BIGNUM),
33 ASN1_ITEM_rptr(ECPARAMETERS),
34 ASN1_ITEM_rptr(ECPKPARAMETERS),
35 ASN1_ITEM_rptr(GENERAL_NAME),
36 ASN1_ITEM_rptr(GENERAL_SUBTREE),
37 ASN1_ITEM_rptr(NAME_CONSTRAINTS),
38 ASN1_ITEM_rptr(OCSP_BASICRESP),
39 ASN1_ITEM_rptr(OCSP_RESPONSE),
40 ASN1_ITEM_rptr(PKCS12),
41 ASN1_ITEM_rptr(PKCS12_AUTHSAFES),
42 ASN1_ITEM_rptr(PKCS12_SAFEBAGS),
43 ASN1_ITEM_rptr(PKCS7),
44 ASN1_ITEM_rptr(PKCS7_ATTR_SIGN),
45 ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY),
46 ASN1_ITEM_rptr(PKCS7_DIGEST),
47 ASN1_ITEM_rptr(PKCS7_ENC_CONTENT),
48 ASN1_ITEM_rptr(PKCS7_ENCRYPT),
49 ASN1_ITEM_rptr(PKCS7_ENVELOPE),
50 ASN1_ITEM_rptr(PKCS7_RECIP_INFO),
51 ASN1_ITEM_rptr(PKCS7_SIGN_ENVELOPE),
52 ASN1_ITEM_rptr(PKCS7_SIGNED),
53 ASN1_ITEM_rptr(PKCS7_SIGNER_INFO),
54 ASN1_ITEM_rptr(POLICY_CONSTRAINTS),
55 ASN1_ITEM_rptr(POLICY_MAPPINGS),
56 ASN1_ITEM_rptr(SXNET),
57 //ASN1_ITEM_rptr(TS_RESP), want to do this, but type is hidden, however d2i exists...
58 ASN1_ITEM_rptr(X509),
59 ASN1_ITEM_rptr(X509_CRL),
60 NULL
61};
c38bb727 62
f59d0131 63int FuzzerTestOneInput(const uint8_t *buf, size_t len) {
e298cb10
BL
64 for (int n = 0; item_type[n] != NULL; ++n) {
65 const uint8_t *b = buf;
66 ASN1_VALUE *o = ASN1_item_d2i(NULL, &b, len, item_type[n]);
67 ASN1_item_free(o, item_type[n]);
68 }
c38bb727
BL
69 return 0;
70}