25-test_d2i.t 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. use strict;
  9. use warnings;
  10. use File::Spec;
  11. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  12. use OpenSSL::Test::Utils;
  13. setup("test_d2i");
  14. plan tests => 14;
  15. ok(run(test(["d2i_test", "X509", "decode",
  16. srctop_file('test','d2i-tests','bad_cert.der')])),
  17. "Running d2i_test bad_cert.der");
  18. ok(run(test(["d2i_test", "GENERAL_NAME", "decode",
  19. srctop_file('test','d2i-tests','bad_generalname.der')])),
  20. "Running d2i_test bad_generalname.der");
  21. ok(run(test(["d2i_test", "ASN1_ANY", "BIO",
  22. srctop_file('test','d2i-tests','bad_bio.der')])),
  23. "Running d2i_test bad_bio.der");
  24. # This test checks CVE-2016-2108. The data consists of an tag 258 and
  25. # two zero content octets. This is parsed as an ASN1_ANY type. If the
  26. # type is incorrectly interpreted as an ASN.1 INTEGER the two zero content
  27. # octets will be reject as invalid padding and this test will fail.
  28. # If the type is correctly interpreted it will by treated as an ASN1_STRING
  29. # type and the content octets copied verbatim.
  30. ok(run(test(["d2i_test", "ASN1_ANY", "OK",
  31. srctop_file('test','d2i-tests','high_tag.der')])),
  32. "Running d2i_test high_tag.der");
  33. # Above test data but interpreted as ASN.1 INTEGER: this will be rejected
  34. # because the tag is invalid.
  35. ok(run(test(["d2i_test", "ASN1_INTEGER", "decode",
  36. srctop_file('test','d2i-tests','high_tag.der')])),
  37. "Running d2i_test high_tag.der INTEGER");
  38. # Parse valid 0, 1 and -1 ASN.1 INTEGER as INTEGER or ANY.
  39. ok(run(test(["d2i_test", "ASN1_INTEGER", "OK",
  40. srctop_file('test','d2i-tests','int0.der')])),
  41. "Running d2i_test int0.der INTEGER");
  42. ok(run(test(["d2i_test", "ASN1_INTEGER", "OK",
  43. srctop_file('test','d2i-tests','int1.der')])),
  44. "Running d2i_test int1.der INTEGER");
  45. ok(run(test(["d2i_test", "ASN1_INTEGER", "OK",
  46. srctop_file('test','d2i-tests','intminus1.der')])),
  47. "Running d2i_test intminus1.der INTEGER");
  48. ok(run(test(["d2i_test", "ASN1_ANY", "OK",
  49. srctop_file('test','d2i-tests','int0.der')])),
  50. "Running d2i_test int0.der ANY");
  51. ok(run(test(["d2i_test", "ASN1_ANY", "OK",
  52. srctop_file('test','d2i-tests','int1.der')])),
  53. "Running d2i_test int1.der ANY");
  54. ok(run(test(["d2i_test", "ASN1_ANY", "OK",
  55. srctop_file('test','d2i-tests','intminus1.der')])),
  56. "Running d2i_test intminus1.der ANY");
  57. # Integers with illegal additional padding.
  58. ok(run(test(["d2i_test", "ASN1_INTEGER", "decode",
  59. srctop_file('test','d2i-tests','bad-int-pad0.der')])),
  60. "Running d2i_test bad-int-pad0.der INTEGER");
  61. ok(run(test(["d2i_test", "ASN1_INTEGER", "decode",
  62. srctop_file('test','d2i-tests','bad-int-padminus1.der')])),
  63. "Running d2i_test bad-int-padminus1.der INTEGER");
  64. SKIP: {
  65. skip "No CMS support in this configuration", 1 if disabled("cms");
  66. # Invalid CMS structure with decode error in CHOICE value.
  67. # Test for CVE-2016-7053
  68. ok(run(test(["d2i_test", "CMS_ContentInfo", "decode",
  69. srctop_file('test','d2i-tests','bad-cms.der')])),
  70. "Running d2i_test bad-cms.der CMS ContentInfo");
  71. }