2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
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.
12 * Fuzz ASN.1 parsing for various data structures. Specify which on the
15 * asn1 <data structure>
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>
29 static ASN1_ITEM_EXP *item_type[] = {
30 ASN1_ITEM_ref(ASN1_SEQUENCE),
31 ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
32 ASN1_ITEM_ref(BIGNUM),
34 ASN1_ITEM_ref(ECPARAMETERS),
35 ASN1_ITEM_ref(ECPKPARAMETERS),
37 ASN1_ITEM_ref(GENERAL_NAME),
38 ASN1_ITEM_ref(GENERAL_SUBTREE),
39 ASN1_ITEM_ref(NAME_CONSTRAINTS),
40 ASN1_ITEM_ref(OCSP_BASICRESP),
41 ASN1_ITEM_ref(OCSP_RESPONSE),
42 ASN1_ITEM_ref(PKCS12),
43 ASN1_ITEM_ref(PKCS12_AUTHSAFES),
44 ASN1_ITEM_ref(PKCS12_SAFEBAGS),
46 ASN1_ITEM_ref(PKCS7_ATTR_SIGN),
47 ASN1_ITEM_ref(PKCS7_ATTR_VERIFY),
48 ASN1_ITEM_ref(PKCS7_DIGEST),
49 ASN1_ITEM_ref(PKCS7_ENC_CONTENT),
50 ASN1_ITEM_ref(PKCS7_ENCRYPT),
51 ASN1_ITEM_ref(PKCS7_ENVELOPE),
52 ASN1_ITEM_ref(PKCS7_RECIP_INFO),
53 ASN1_ITEM_ref(PKCS7_SIGN_ENVELOPE),
54 ASN1_ITEM_ref(PKCS7_SIGNED),
55 ASN1_ITEM_ref(PKCS7_SIGNER_INFO),
56 ASN1_ITEM_ref(POLICY_CONSTRAINTS),
57 ASN1_ITEM_ref(POLICY_MAPPINGS),
59 /*ASN1_ITEM_ref(TS_RESP), want to do this, but type is hidden, however d2i exists... */
61 ASN1_ITEM_ref(X509_CRL),
65 int FuzzerInitialize(int *argc, char ***argv) {
69 int FuzzerTestOneInput(const uint8_t *buf, size_t len) {
72 ASN1_PCTX *pctx = ASN1_PCTX_new();
74 ASN1_PCTX_set_flags(pctx, ASN1_PCTX_FLAGS_SHOW_ABSENT |
75 ASN1_PCTX_FLAGS_SHOW_SEQUENCE | ASN1_PCTX_FLAGS_SHOW_SSOF |
76 ASN1_PCTX_FLAGS_SHOW_TYPE | ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME);
77 ASN1_PCTX_set_str_flags(pctx, ASN1_STRFLGS_UTF8_CONVERT |
78 ASN1_STRFLGS_SHOW_TYPE | ASN1_STRFLGS_DUMP_ALL);
80 for (n = 0; item_type[n] != NULL; ++n) {
81 const uint8_t *b = buf;
82 unsigned char *der = NULL;
83 const ASN1_ITEM *i = ASN1_ITEM_ptr(item_type[n]);
84 ASN1_VALUE *o = ASN1_item_d2i(NULL, &b, len, i);
87 BIO *bio = BIO_new(BIO_s_null());
88 ASN1_item_print(bio, o, 4, i, pctx);
91 ASN1_item_i2d(o, &der, i);