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