2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
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
14 use OpenSSL::Test qw/:DEFAULT srctop_file/;
20 ok(run(test(["d2i_test", "X509", "decode",
21 srctop_file('test','d2i-tests','bad_cert.der')])),
22 "Running d2i_test bad_cert.der");
24 ok(run(test(["d2i_test", "GENERAL_NAME", "decode",
25 srctop_file('test','d2i-tests','bad_generalname.der')])),
26 "Running d2i_test bad_generalname.der");
28 ok(run(test(["d2i_test", "ASN1_ANY", "BIO",
29 srctop_file('test','d2i-tests','bad_bio.der')])),
30 "Running d2i_test bad_bio.der");
31 # This test checks CVE-2016-2108. The data consists of an tag 258 and
32 # two zero content octets. This is parsed as an ASN1_ANY type. If the
33 # type is incorrectly interpreted as an ASN.1 INTEGER the two zero content
34 # octets will be reject as invalid padding and this test will fail.
35 # If the type is correctly interpreted it will by treated as an ASN1_STRING
36 # type and the content octets copied verbatim.
37 ok(run(test(["d2i_test", "ASN1_ANY", "OK",
38 srctop_file('test','d2i-tests','high_tag.der')])),
39 "Running d2i_test high_tag.der");
41 # Above test data but interpreted as ASN.1 INTEGER: this will be rejected
42 # because the tag is invalid.
43 ok(run(test(["d2i_test", "ASN1_INTEGER", "decode",
44 srctop_file('test','d2i-tests','high_tag.der')])),
45 "Running d2i_test high_tag.der INTEGER");
47 # Parse valid 0, 1 and -1 ASN.1 INTEGER as INTEGER or ANY.
49 ok(run(test(["d2i_test", "ASN1_INTEGER", "OK",
50 srctop_file('test','d2i-tests','int0.der')])),
51 "Running d2i_test int0.der INTEGER");
53 ok(run(test(["d2i_test", "ASN1_INTEGER", "OK",
54 srctop_file('test','d2i-tests','int1.der')])),
55 "Running d2i_test int1.der INTEGER");
57 ok(run(test(["d2i_test", "ASN1_INTEGER", "OK",
58 srctop_file('test','d2i-tests','intminus1.der')])),
59 "Running d2i_test intminus1.der INTEGER");
61 ok(run(test(["d2i_test", "ASN1_ANY", "OK",
62 srctop_file('test','d2i-tests','int0.der')])),
63 "Running d2i_test int0.der ANY");
65 ok(run(test(["d2i_test", "ASN1_ANY", "OK",
66 srctop_file('test','d2i-tests','int1.der')])),
67 "Running d2i_test int1.der ANY");
69 ok(run(test(["d2i_test", "ASN1_ANY", "OK",
70 srctop_file('test','d2i-tests','intminus1.der')])),
71 "Running d2i_test intminus1.der ANY");
73 # Integers with illegal additional padding.
75 ok(run(test(["d2i_test", "ASN1_INTEGER", "decode",
76 srctop_file('test','d2i-tests','bad-int-pad0.der')])),
77 "Running d2i_test bad-int-pad0.der INTEGER");
79 ok(run(test(["d2i_test", "ASN1_INTEGER", "decode",
80 srctop_file('test','d2i-tests','bad-int-padminus1.der')])),
81 "Running d2i_test bad-int-padminus1.der INTEGER");
83 # Invalid CMS structure with decode error in CHOICE value.
84 # Test for CVE-2016-7053
86 ok(run(test(["d2i_test", "CMS_ContentInfo", "decode",
87 srctop_file('test','d2i-tests','bad-cms.der')])),
88 "Running d2i_test bad-cms.der CMS ContentInfo");