asn1.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * Fuzz ASN.1 parsing for various data structures. Specify which on the
  12. * command line:
  13. *
  14. * asn1 <data structure>
  15. */
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <openssl/asn1.h>
  19. #include <openssl/asn1t.h>
  20. #include <openssl/ec.h>
  21. #include <openssl/ocsp.h>
  22. #include <openssl/pkcs12.h>
  23. #include <openssl/ts.h>
  24. #include <openssl/x509v3.h>
  25. #include "fuzzer.h"
  26. static const ASN1_ITEM *item_type;
  27. int LLVMFuzzerInitialize(int *argc, char ***argv) {
  28. const char *cmd;
  29. OPENSSL_assert(*argc > 1);
  30. cmd = (*argv)[1];
  31. (*argv)[1] = (*argv)[0];
  32. ++*argv;
  33. --*argc;
  34. // TODO: make this work like d2i_test.c does, once its decided what the
  35. // common scheme is!
  36. #define Y(t) if (!strcmp(cmd, #t)) item_type = ASN1_ITEM_rptr(t)
  37. #define X(t) else Y(t)
  38. Y(ASN1_SEQUENCE);
  39. X(AUTHORITY_INFO_ACCESS);
  40. X(BIGNUM);
  41. X(ECPARAMETERS);
  42. X(ECPKPARAMETERS);
  43. X(GENERAL_NAME);
  44. X(GENERAL_SUBTREE);
  45. X(NAME_CONSTRAINTS);
  46. X(OCSP_BASICRESP);
  47. X(OCSP_RESPONSE);
  48. X(PKCS12);
  49. X(PKCS12_AUTHSAFES);
  50. X(PKCS12_SAFEBAGS);
  51. X(PKCS7);
  52. X(PKCS7_ATTR_SIGN);
  53. X(PKCS7_ATTR_VERIFY);
  54. X(PKCS7_DIGEST);
  55. X(PKCS7_ENC_CONTENT);
  56. X(PKCS7_ENCRYPT);
  57. X(PKCS7_ENVELOPE);
  58. X(PKCS7_RECIP_INFO);
  59. X(PKCS7_SIGN_ENVELOPE);
  60. X(PKCS7_SIGNED);
  61. X(PKCS7_SIGNER_INFO);
  62. X(POLICY_CONSTRAINTS);
  63. X(POLICY_MAPPINGS);
  64. X(SXNET);
  65. //X(TS_RESP); want to do this, but type is hidden, however d2i exists...
  66. X(X509);
  67. X(X509_CRL);
  68. else
  69. OPENSSL_assert(!"Bad type");
  70. return 0;
  71. }
  72. int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
  73. const uint8_t *b = buf;
  74. ASN1_VALUE *o = ASN1_item_d2i(NULL, &b, len, item_type);
  75. ASN1_item_free(o, item_type);
  76. return 0;
  77. }