1e0c4386eSCy Schubert /* 2*44096ebdSEnji Cooper * Copyright 2016-2024 The OpenSSL Project Authors. All Rights Reserved. 3e0c4386eSCy Schubert * 4e0c4386eSCy Schubert * Licensed under the Apache License 2.0 (the "License"); 5e0c4386eSCy Schubert * you may not use this file except in compliance with the License. 6e0c4386eSCy Schubert * You may obtain a copy of the License at 7e0c4386eSCy Schubert * https://www.openssl.org/source/license.html 8e0c4386eSCy Schubert * or in the file LICENSE in the source distribution. 9e0c4386eSCy Schubert */ 10e0c4386eSCy Schubert 11e0c4386eSCy Schubert /* 12e0c4386eSCy Schubert * Fuzz ASN.1 parsing for various data structures. Specify which on the 13e0c4386eSCy Schubert * command line: 14e0c4386eSCy Schubert * 15e0c4386eSCy Schubert * asn1 <data structure> 16e0c4386eSCy Schubert */ 17e0c4386eSCy Schubert 18e0c4386eSCy Schubert /* We need to use some deprecated APIs */ 19e0c4386eSCy Schubert #define OPENSSL_SUPPRESS_DEPRECATED 20e0c4386eSCy Schubert 21e0c4386eSCy Schubert #include <stdio.h> 22e0c4386eSCy Schubert #include <string.h> 23e0c4386eSCy Schubert #include <openssl/asn1.h> 24e0c4386eSCy Schubert #include <openssl/asn1t.h> 25e0c4386eSCy Schubert #include <openssl/dh.h> 26e0c4386eSCy Schubert #include <openssl/dsa.h> 27e0c4386eSCy Schubert #include <openssl/ec.h> 28e0c4386eSCy Schubert #include <openssl/ocsp.h> 29e0c4386eSCy Schubert #include <openssl/pkcs12.h> 30e0c4386eSCy Schubert #include <openssl/rsa.h> 31e0c4386eSCy Schubert #include <openssl/ts.h> 32e0c4386eSCy Schubert #include <openssl/x509v3.h> 33e0c4386eSCy Schubert #include <openssl/cms.h> 34e0c4386eSCy Schubert #include <openssl/ess.h> 35e0c4386eSCy Schubert #include <openssl/err.h> 36e0c4386eSCy Schubert #include <openssl/rand.h> 37e0c4386eSCy Schubert #include <openssl/bio.h> 38e0c4386eSCy Schubert #include <openssl/evp.h> 39e0c4386eSCy Schubert #include <openssl/ssl.h> 40e0c4386eSCy Schubert #include "internal/nelem.h" 41e0c4386eSCy Schubert #include "fuzzer.h" 42e0c4386eSCy Schubert 43e0c4386eSCy Schubert static ASN1_ITEM_EXP *item_type[] = { 44e0c4386eSCy Schubert ASN1_ITEM_ref(ACCESS_DESCRIPTION), 45e0c4386eSCy Schubert #ifndef OPENSSL_NO_RFC3779 46e0c4386eSCy Schubert ASN1_ITEM_ref(ASIdentifierChoice), 47e0c4386eSCy Schubert ASN1_ITEM_ref(ASIdentifiers), 48e0c4386eSCy Schubert ASN1_ITEM_ref(ASIdOrRange), 49e0c4386eSCy Schubert #endif 50e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_ANY), 51e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_BIT_STRING), 52e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_BMPSTRING), 53e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_BOOLEAN), 54e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_ENUMERATED), 55e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_FBOOLEAN), 56e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_GENERALIZEDTIME), 57e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_GENERALSTRING), 58e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_IA5STRING), 59e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_INTEGER), 60e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_NULL), 61e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_OBJECT), 62e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_OCTET_STRING), 63e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_OCTET_STRING_NDEF), 64e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_PRINTABLE), 65e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_PRINTABLESTRING), 66e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_SEQUENCE), 67e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_SEQUENCE_ANY), 68e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_SET_ANY), 69e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_T61STRING), 70e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_TBOOLEAN), 71e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_TIME), 72e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_UNIVERSALSTRING), 73e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_UTCTIME), 74e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_UTF8STRING), 75e0c4386eSCy Schubert ASN1_ITEM_ref(ASN1_VISIBLESTRING), 76e0c4386eSCy Schubert #ifndef OPENSSL_NO_RFC3779 77e0c4386eSCy Schubert ASN1_ITEM_ref(ASRange), 78e0c4386eSCy Schubert #endif 79e0c4386eSCy Schubert ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS), 80e0c4386eSCy Schubert ASN1_ITEM_ref(AUTHORITY_KEYID), 81e0c4386eSCy Schubert ASN1_ITEM_ref(BASIC_CONSTRAINTS), 82e0c4386eSCy Schubert ASN1_ITEM_ref(BIGNUM), 83e0c4386eSCy Schubert ASN1_ITEM_ref(CBIGNUM), 84e0c4386eSCy Schubert ASN1_ITEM_ref(CERTIFICATEPOLICIES), 85e0c4386eSCy Schubert #ifndef OPENSSL_NO_CMS 86e0c4386eSCy Schubert ASN1_ITEM_ref(CMS_ContentInfo), 87e0c4386eSCy Schubert ASN1_ITEM_ref(CMS_ReceiptRequest), 88e0c4386eSCy Schubert ASN1_ITEM_ref(CRL_DIST_POINTS), 89e0c4386eSCy Schubert #endif 90e0c4386eSCy Schubert #ifndef OPENSSL_NO_DH 91e0c4386eSCy Schubert ASN1_ITEM_ref(DHparams), 92e0c4386eSCy Schubert #endif 93e0c4386eSCy Schubert ASN1_ITEM_ref(DIRECTORYSTRING), 94e0c4386eSCy Schubert ASN1_ITEM_ref(DISPLAYTEXT), 95e0c4386eSCy Schubert ASN1_ITEM_ref(DIST_POINT), 96e0c4386eSCy Schubert ASN1_ITEM_ref(DIST_POINT_NAME), 97e0c4386eSCy Schubert #if !defined(OPENSSL_NO_EC) && !defined(OPENSSL_NO_DEPRECATED_3_0) 98e0c4386eSCy Schubert ASN1_ITEM_ref(ECPARAMETERS), 99e0c4386eSCy Schubert ASN1_ITEM_ref(ECPKPARAMETERS), 100e0c4386eSCy Schubert #endif 101e0c4386eSCy Schubert ASN1_ITEM_ref(EDIPARTYNAME), 102e0c4386eSCy Schubert ASN1_ITEM_ref(EXTENDED_KEY_USAGE), 103e0c4386eSCy Schubert ASN1_ITEM_ref(GENERAL_NAME), 104e0c4386eSCy Schubert ASN1_ITEM_ref(GENERAL_NAMES), 105e0c4386eSCy Schubert ASN1_ITEM_ref(GENERAL_SUBTREE), 106e0c4386eSCy Schubert #ifndef OPENSSL_NO_RFC3779 107e0c4386eSCy Schubert ASN1_ITEM_ref(IPAddressChoice), 108e0c4386eSCy Schubert ASN1_ITEM_ref(IPAddressFamily), 109e0c4386eSCy Schubert ASN1_ITEM_ref(IPAddressOrRange), 110e0c4386eSCy Schubert ASN1_ITEM_ref(IPAddressRange), 111e0c4386eSCy Schubert #endif 112e0c4386eSCy Schubert ASN1_ITEM_ref(ISSUING_DIST_POINT), 113e0c4386eSCy Schubert #ifndef OPENSSL_NO_DEPRECATED_3_0 114e0c4386eSCy Schubert ASN1_ITEM_ref(LONG), 115e0c4386eSCy Schubert #endif 116e0c4386eSCy Schubert ASN1_ITEM_ref(NAME_CONSTRAINTS), 117e0c4386eSCy Schubert ASN1_ITEM_ref(NETSCAPE_CERT_SEQUENCE), 118e0c4386eSCy Schubert ASN1_ITEM_ref(NETSCAPE_SPKAC), 119e0c4386eSCy Schubert ASN1_ITEM_ref(NETSCAPE_SPKI), 120e0c4386eSCy Schubert ASN1_ITEM_ref(NOTICEREF), 121e0c4386eSCy Schubert #ifndef OPENSSL_NO_OCSP 122e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_BASICRESP), 123e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_CERTID), 124e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_CERTSTATUS), 125e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_CRLID), 126e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_ONEREQ), 127e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_REQINFO), 128e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_REQUEST), 129e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_RESPBYTES), 130e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_RESPDATA), 131e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_RESPID), 132e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_RESPONSE), 133e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_REVOKEDINFO), 134e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_SERVICELOC), 135e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_SIGNATURE), 136e0c4386eSCy Schubert ASN1_ITEM_ref(OCSP_SINGLERESP), 137e0c4386eSCy Schubert #endif 138e0c4386eSCy Schubert ASN1_ITEM_ref(OTHERNAME), 139e0c4386eSCy Schubert ASN1_ITEM_ref(PBE2PARAM), 140e0c4386eSCy Schubert ASN1_ITEM_ref(PBEPARAM), 141e0c4386eSCy Schubert ASN1_ITEM_ref(PBKDF2PARAM), 142e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS12), 143e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS12_AUTHSAFES), 144e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS12_BAGS), 145e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS12_MAC_DATA), 146e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS12_SAFEBAG), 147e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS12_SAFEBAGS), 148e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7), 149e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_ATTR_SIGN), 150e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_ATTR_VERIFY), 151e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_DIGEST), 152e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_ENC_CONTENT), 153e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_ENCRYPT), 154e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_ENVELOPE), 155e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_ISSUER_AND_SERIAL), 156e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_RECIP_INFO), 157e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_SIGNED), 158e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_SIGN_ENVELOPE), 159e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS7_SIGNER_INFO), 160e0c4386eSCy Schubert ASN1_ITEM_ref(PKCS8_PRIV_KEY_INFO), 161e0c4386eSCy Schubert ASN1_ITEM_ref(PKEY_USAGE_PERIOD), 162e0c4386eSCy Schubert ASN1_ITEM_ref(POLICY_CONSTRAINTS), 163e0c4386eSCy Schubert ASN1_ITEM_ref(POLICYINFO), 164e0c4386eSCy Schubert ASN1_ITEM_ref(POLICY_MAPPING), 165e0c4386eSCy Schubert ASN1_ITEM_ref(POLICY_MAPPINGS), 166e0c4386eSCy Schubert ASN1_ITEM_ref(POLICYQUALINFO), 167e0c4386eSCy Schubert ASN1_ITEM_ref(PROXY_CERT_INFO_EXTENSION), 168e0c4386eSCy Schubert ASN1_ITEM_ref(PROXY_POLICY), 169e0c4386eSCy Schubert ASN1_ITEM_ref(RSA_OAEP_PARAMS), 170e0c4386eSCy Schubert ASN1_ITEM_ref(RSA_PSS_PARAMS), 171e0c4386eSCy Schubert #ifndef OPENSSL_NO_DEPRECATED_3_0 172e0c4386eSCy Schubert ASN1_ITEM_ref(RSAPrivateKey), 173e0c4386eSCy Schubert ASN1_ITEM_ref(RSAPublicKey), 174e0c4386eSCy Schubert #endif 175e0c4386eSCy Schubert ASN1_ITEM_ref(SXNET), 176e0c4386eSCy Schubert ASN1_ITEM_ref(SXNETID), 177e0c4386eSCy Schubert ASN1_ITEM_ref(USERNOTICE), 178e0c4386eSCy Schubert ASN1_ITEM_ref(X509), 179e0c4386eSCy Schubert ASN1_ITEM_ref(X509_ALGOR), 180e0c4386eSCy Schubert ASN1_ITEM_ref(X509_ALGORS), 181e0c4386eSCy Schubert ASN1_ITEM_ref(X509_ATTRIBUTE), 182e0c4386eSCy Schubert ASN1_ITEM_ref(X509_CERT_AUX), 183e0c4386eSCy Schubert ASN1_ITEM_ref(X509_CINF), 184e0c4386eSCy Schubert ASN1_ITEM_ref(X509_CRL), 185e0c4386eSCy Schubert ASN1_ITEM_ref(X509_CRL_INFO), 186e0c4386eSCy Schubert ASN1_ITEM_ref(X509_EXTENSION), 187e0c4386eSCy Schubert ASN1_ITEM_ref(X509_EXTENSIONS), 188e0c4386eSCy Schubert ASN1_ITEM_ref(X509_NAME), 189e0c4386eSCy Schubert ASN1_ITEM_ref(X509_NAME_ENTRY), 190e0c4386eSCy Schubert ASN1_ITEM_ref(X509_PUBKEY), 191e0c4386eSCy Schubert ASN1_ITEM_ref(X509_REQ), 192e0c4386eSCy Schubert ASN1_ITEM_ref(X509_REQ_INFO), 193e0c4386eSCy Schubert ASN1_ITEM_ref(X509_REVOKED), 194e0c4386eSCy Schubert ASN1_ITEM_ref(X509_SIG), 195e0c4386eSCy Schubert ASN1_ITEM_ref(X509_VAL), 196e0c4386eSCy Schubert #ifndef OPENSSL_NO_DEPRECATED_3_0 197e0c4386eSCy Schubert ASN1_ITEM_ref(ZLONG), 198e0c4386eSCy Schubert #endif 199e0c4386eSCy Schubert ASN1_ITEM_ref(INT32), 200e0c4386eSCy Schubert ASN1_ITEM_ref(ZINT32), 201e0c4386eSCy Schubert ASN1_ITEM_ref(UINT32), 202e0c4386eSCy Schubert ASN1_ITEM_ref(ZUINT32), 203e0c4386eSCy Schubert ASN1_ITEM_ref(INT64), 204e0c4386eSCy Schubert ASN1_ITEM_ref(ZINT64), 205e0c4386eSCy Schubert ASN1_ITEM_ref(UINT64), 206e0c4386eSCy Schubert ASN1_ITEM_ref(ZUINT64), 207e0c4386eSCy Schubert NULL 208e0c4386eSCy Schubert }; 209e0c4386eSCy Schubert 210e0c4386eSCy Schubert static ASN1_PCTX *pctx; 211e0c4386eSCy Schubert 212e0c4386eSCy Schubert #define DO_TEST(TYPE, D2I, I2D, PRINT) { \ 213e0c4386eSCy Schubert const unsigned char *p = buf; \ 214e0c4386eSCy Schubert unsigned char *der = NULL; \ 215e0c4386eSCy Schubert TYPE *type = D2I(NULL, &p, len); \ 216e0c4386eSCy Schubert \ 217e0c4386eSCy Schubert if (type != NULL) { \ 218e0c4386eSCy Schubert int len2; \ 219e0c4386eSCy Schubert BIO *bio = BIO_new(BIO_s_null()); \ 220e0c4386eSCy Schubert \ 221e0c4386eSCy Schubert if (bio != NULL) { \ 222e0c4386eSCy Schubert PRINT(bio, type); \ 223e0c4386eSCy Schubert BIO_free(bio); \ 224e0c4386eSCy Schubert } \ 225e0c4386eSCy Schubert len2 = I2D(type, &der); \ 226e0c4386eSCy Schubert if (len2 != 0) {} \ 227e0c4386eSCy Schubert OPENSSL_free(der); \ 228e0c4386eSCy Schubert TYPE ## _free(type); \ 229e0c4386eSCy Schubert } \ 230e0c4386eSCy Schubert } 231e0c4386eSCy Schubert 232e0c4386eSCy Schubert #define DO_TEST_PRINT_OFFSET(TYPE, D2I, I2D, PRINT) { \ 233e0c4386eSCy Schubert const unsigned char *p = buf; \ 234e0c4386eSCy Schubert unsigned char *der = NULL; \ 235e0c4386eSCy Schubert TYPE *type = D2I(NULL, &p, len); \ 236e0c4386eSCy Schubert \ 237e0c4386eSCy Schubert if (type != NULL) { \ 238e0c4386eSCy Schubert BIO *bio = BIO_new(BIO_s_null()); \ 239e0c4386eSCy Schubert \ 240e0c4386eSCy Schubert if (bio != NULL) { \ 241e0c4386eSCy Schubert PRINT(bio, type, 0); \ 242e0c4386eSCy Schubert BIO_free(bio); \ 243e0c4386eSCy Schubert } \ 244e0c4386eSCy Schubert I2D(type, &der); \ 245e0c4386eSCy Schubert OPENSSL_free(der); \ 246e0c4386eSCy Schubert TYPE ## _free(type); \ 247e0c4386eSCy Schubert } \ 248e0c4386eSCy Schubert } 249e0c4386eSCy Schubert 250e0c4386eSCy Schubert #define DO_TEST_PRINT_PCTX(TYPE, D2I, I2D, PRINT) { \ 251e0c4386eSCy Schubert const unsigned char *p = buf; \ 252e0c4386eSCy Schubert unsigned char *der = NULL; \ 253e0c4386eSCy Schubert TYPE *type = D2I(NULL, &p, len); \ 254e0c4386eSCy Schubert \ 255e0c4386eSCy Schubert if (type != NULL) { \ 256e0c4386eSCy Schubert BIO *bio = BIO_new(BIO_s_null()); \ 257e0c4386eSCy Schubert \ 258e0c4386eSCy Schubert if (bio != NULL) { \ 259e0c4386eSCy Schubert PRINT(bio, type, 0, pctx); \ 260e0c4386eSCy Schubert BIO_free(bio); \ 261e0c4386eSCy Schubert } \ 262e0c4386eSCy Schubert I2D(type, &der); \ 263e0c4386eSCy Schubert OPENSSL_free(der); \ 264e0c4386eSCy Schubert TYPE ## _free(type); \ 265e0c4386eSCy Schubert } \ 266e0c4386eSCy Schubert } 267e0c4386eSCy Schubert 268e0c4386eSCy Schubert 269e0c4386eSCy Schubert #define DO_TEST_NO_PRINT(TYPE, D2I, I2D) { \ 270e0c4386eSCy Schubert const unsigned char *p = buf; \ 271e0c4386eSCy Schubert unsigned char *der = NULL; \ 272e0c4386eSCy Schubert TYPE *type = D2I(NULL, &p, len); \ 273e0c4386eSCy Schubert \ 274e0c4386eSCy Schubert if (type != NULL) { \ 275e0c4386eSCy Schubert BIO *bio = BIO_new(BIO_s_null()); \ 276e0c4386eSCy Schubert \ 277e0c4386eSCy Schubert BIO_free(bio); \ 278e0c4386eSCy Schubert I2D(type, &der); \ 279e0c4386eSCy Schubert OPENSSL_free(der); \ 280e0c4386eSCy Schubert TYPE ## _free(type); \ 281e0c4386eSCy Schubert } \ 282e0c4386eSCy Schubert } 283e0c4386eSCy Schubert 284e0c4386eSCy Schubert 285e0c4386eSCy Schubert int FuzzerInitialize(int *argc, char ***argv) 286e0c4386eSCy Schubert { 287e0c4386eSCy Schubert FuzzerSetRand(); 288e0c4386eSCy Schubert pctx = ASN1_PCTX_new(); 289e0c4386eSCy Schubert ASN1_PCTX_set_flags(pctx, ASN1_PCTX_FLAGS_SHOW_ABSENT | 290e0c4386eSCy Schubert ASN1_PCTX_FLAGS_SHOW_SEQUENCE | ASN1_PCTX_FLAGS_SHOW_SSOF | 291e0c4386eSCy Schubert ASN1_PCTX_FLAGS_SHOW_TYPE | ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME); 292e0c4386eSCy Schubert ASN1_PCTX_set_str_flags(pctx, ASN1_STRFLGS_UTF8_CONVERT | 293e0c4386eSCy Schubert ASN1_STRFLGS_SHOW_TYPE | ASN1_STRFLGS_DUMP_ALL); 294e0c4386eSCy Schubert 295e0c4386eSCy Schubert OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); 296e0c4386eSCy Schubert OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL); 297e0c4386eSCy Schubert ERR_clear_error(); 298e0c4386eSCy Schubert CRYPTO_free_ex_index(0, -1); 299e0c4386eSCy Schubert 300e0c4386eSCy Schubert return 1; 301e0c4386eSCy Schubert } 302e0c4386eSCy Schubert 303e0c4386eSCy Schubert int FuzzerTestOneInput(const uint8_t *buf, size_t len) 304e0c4386eSCy Schubert { 305e0c4386eSCy Schubert int n; 306e0c4386eSCy Schubert 307e0c4386eSCy Schubert 308e0c4386eSCy Schubert for (n = 0; item_type[n] != NULL; ++n) { 309e0c4386eSCy Schubert const uint8_t *b = buf; 310e0c4386eSCy Schubert unsigned char *der = NULL; 311e0c4386eSCy Schubert const ASN1_ITEM *i = ASN1_ITEM_ptr(item_type[n]); 312e0c4386eSCy Schubert ASN1_VALUE *o = ASN1_item_d2i(NULL, &b, len, i); 313e0c4386eSCy Schubert 314e0c4386eSCy Schubert if (o != NULL) { 315*44096ebdSEnji Cooper /* 316*44096ebdSEnji Cooper * Don't print excessively long output to prevent spurious fuzzer 317*44096ebdSEnji Cooper * timeouts. 318*44096ebdSEnji Cooper */ 319*44096ebdSEnji Cooper if (b - buf < 10000) { 320e0c4386eSCy Schubert BIO *bio = BIO_new(BIO_s_null()); 321e0c4386eSCy Schubert if (bio != NULL) { 322e0c4386eSCy Schubert ASN1_item_print(bio, o, 4, i, pctx); 323e0c4386eSCy Schubert BIO_free(bio); 324e0c4386eSCy Schubert } 325*44096ebdSEnji Cooper } 326e0c4386eSCy Schubert if (ASN1_item_i2d(o, &der, i) > 0) { 327e0c4386eSCy Schubert OPENSSL_free(der); 328e0c4386eSCy Schubert } 329e0c4386eSCy Schubert ASN1_item_free(o, i); 330e0c4386eSCy Schubert } 331e0c4386eSCy Schubert } 332e0c4386eSCy Schubert 333e0c4386eSCy Schubert #ifndef OPENSSL_NO_TS 334e0c4386eSCy Schubert DO_TEST(TS_REQ, d2i_TS_REQ, i2d_TS_REQ, TS_REQ_print_bio); 335e0c4386eSCy Schubert DO_TEST(TS_MSG_IMPRINT, d2i_TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, TS_MSG_IMPRINT_print_bio); 336e0c4386eSCy Schubert DO_TEST(TS_RESP, d2i_TS_RESP, i2d_TS_RESP, TS_RESP_print_bio); 337e0c4386eSCy Schubert DO_TEST(TS_STATUS_INFO, d2i_TS_STATUS_INFO, i2d_TS_STATUS_INFO, TS_STATUS_INFO_print_bio); 338e0c4386eSCy Schubert DO_TEST(TS_TST_INFO, d2i_TS_TST_INFO, i2d_TS_TST_INFO, TS_TST_INFO_print_bio); 339e0c4386eSCy Schubert DO_TEST_NO_PRINT(TS_ACCURACY, d2i_TS_ACCURACY, i2d_TS_ACCURACY); 340e0c4386eSCy Schubert #endif 341e0c4386eSCy Schubert DO_TEST_NO_PRINT(ESS_ISSUER_SERIAL, d2i_ESS_ISSUER_SERIAL, i2d_ESS_ISSUER_SERIAL); 342e0c4386eSCy Schubert DO_TEST_NO_PRINT(ESS_CERT_ID, d2i_ESS_CERT_ID, i2d_ESS_CERT_ID); 343e0c4386eSCy Schubert DO_TEST_NO_PRINT(ESS_SIGNING_CERT, d2i_ESS_SIGNING_CERT, i2d_ESS_SIGNING_CERT); 344e0c4386eSCy Schubert DO_TEST_NO_PRINT(ESS_CERT_ID_V2, d2i_ESS_CERT_ID_V2, i2d_ESS_CERT_ID_V2); 345e0c4386eSCy Schubert DO_TEST_NO_PRINT(ESS_SIGNING_CERT_V2, d2i_ESS_SIGNING_CERT_V2, i2d_ESS_SIGNING_CERT_V2); 346e0c4386eSCy Schubert #if !defined(OPENSSL_NO_DH) && !defined(OPENSSL_NO_DEPRECATED_3_0) 347e0c4386eSCy Schubert DO_TEST_NO_PRINT(DH, d2i_DHparams, i2d_DHparams); 348e0c4386eSCy Schubert DO_TEST_NO_PRINT(DH, d2i_DHxparams, i2d_DHxparams); 349e0c4386eSCy Schubert #endif 350e0c4386eSCy Schubert #ifndef OPENSSL_NO_DSA 351e0c4386eSCy Schubert DO_TEST_NO_PRINT(DSA_SIG, d2i_DSA_SIG, i2d_DSA_SIG); 352e0c4386eSCy Schubert # ifndef OPENSSL_NO_DEPRECATED_3_0 353e0c4386eSCy Schubert DO_TEST_NO_PRINT(DSA, d2i_DSAPrivateKey, i2d_DSAPrivateKey); 354e0c4386eSCy Schubert DO_TEST_NO_PRINT(DSA, d2i_DSAPublicKey, i2d_DSAPublicKey); 355e0c4386eSCy Schubert DO_TEST_NO_PRINT(DSA, d2i_DSAparams, i2d_DSAparams); 356e0c4386eSCy Schubert # endif 357e0c4386eSCy Schubert #endif 358e0c4386eSCy Schubert #ifndef OPENSSL_NO_DEPRECATED_3_0 359e0c4386eSCy Schubert DO_TEST_NO_PRINT(RSA, d2i_RSAPublicKey, i2d_RSAPublicKey); 360e0c4386eSCy Schubert #endif 361e0c4386eSCy Schubert #ifndef OPENSSL_NO_EC 362e0c4386eSCy Schubert # ifndef OPENSSL_NO_DEPRECATED_3_0 363e0c4386eSCy Schubert DO_TEST_PRINT_OFFSET(EC_GROUP, d2i_ECPKParameters, i2d_ECPKParameters, ECPKParameters_print); 364e0c4386eSCy Schubert DO_TEST_PRINT_OFFSET(EC_KEY, d2i_ECPrivateKey, i2d_ECPrivateKey, EC_KEY_print); 365e0c4386eSCy Schubert DO_TEST(EC_KEY, d2i_ECParameters, i2d_ECParameters, ECParameters_print); 366e0c4386eSCy Schubert DO_TEST_NO_PRINT(ECDSA_SIG, d2i_ECDSA_SIG, i2d_ECDSA_SIG); 367e0c4386eSCy Schubert # endif 368e0c4386eSCy Schubert #endif 369e0c4386eSCy Schubert DO_TEST_PRINT_PCTX(EVP_PKEY, d2i_AutoPrivateKey, i2d_PrivateKey, EVP_PKEY_print_private); 370e0c4386eSCy Schubert DO_TEST(SSL_SESSION, d2i_SSL_SESSION, i2d_SSL_SESSION, SSL_SESSION_print); 371e0c4386eSCy Schubert 372e0c4386eSCy Schubert ERR_clear_error(); 373e0c4386eSCy Schubert 374e0c4386eSCy Schubert return 0; 375e0c4386eSCy Schubert } 376e0c4386eSCy Schubert 377e0c4386eSCy Schubert void FuzzerCleanup(void) 378e0c4386eSCy Schubert { 379e0c4386eSCy Schubert ASN1_PCTX_free(pctx); 380e0c4386eSCy Schubert FuzzerClearRand(); 381e0c4386eSCy Schubert } 382