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