]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/25-test_d2i.t
Add ASN.1 INTEGER tests.
[thirdparty/openssl.git] / test / recipes / 25-test_d2i.t
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
9
10 use strict;
11 use warnings;
12
13 use File::Spec;
14 use OpenSSL::Test qw/:DEFAULT srctop_file/;
15
16 setup("test_d2i");
17
18 plan tests => 13;
19
20 ok(run(test(["d2i_test", "X509", "decode",
21 srctop_file('test','d2i-tests','bad_cert.der')])),
22 "Running d2i_test bad_cert.der");
23
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");
27
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");
40
41 # Above test data but interpeted 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");
46
47 # Parse valid 0, 1 and -1 ASN.1 INTEGER as INTEGER or ANY.
48
49 ok(run(test(["d2i_test", "ASN1_INTEGER", "OK",
50 srctop_file('test','d2i-tests','int0.der')])),
51 "Running d2i_test int0.der INTEGER");
52
53 ok(run(test(["d2i_test", "ASN1_INTEGER", "OK",
54 srctop_file('test','d2i-tests','int1.der')])),
55 "Running d2i_test int1.der INTEGER");
56
57 ok(run(test(["d2i_test", "ASN1_INTEGER", "OK",
58 srctop_file('test','d2i-tests','intminus1.der')])),
59 "Running d2i_test intminus1.der INTEGER");
60
61 ok(run(test(["d2i_test", "ASN1_ANY", "OK",
62 srctop_file('test','d2i-tests','int0.der')])),
63 "Running d2i_test int0.der ANY");
64
65 ok(run(test(["d2i_test", "ASN1_ANY", "OK",
66 srctop_file('test','d2i-tests','int1.der')])),
67 "Running d2i_test int1.der ANY");
68
69 ok(run(test(["d2i_test", "ASN1_ANY", "OK",
70 srctop_file('test','d2i-tests','intminus1.der')])),
71 "Running d2i_test intminus1.der ANY");
72
73 # Integers with illegal additional padding.
74
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");
78
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");