]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/04-test_pem.t
2 # Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (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
9 # ======================================================================
15 use File
::Compare qw
/compare_text/;
17 use OpenSSL
::Test qw
/:DEFAULT srctop_file data_file/;
18 use OpenSSL
::Test
::Utils
;
20 setup
("test_pem_reading");
22 my $testsrc = srctop_file
("test", "recipes", basename
($0));
26 # map input PEM file to 1 if it should be accepted; 0 when should be rejected
28 "cert-1023line.pem" => 1,
29 "cert-1024line.pem" => 1,
30 "cert-1025line.pem" => 1,
31 "cert-255line.pem" => 1,
32 "cert-256line.pem" => 1,
33 "cert-257line.pem" => 1,
34 "cert-blankline.pem" => 0,
36 "cert-comment.pem" => 0,
37 "cert-earlypad.pem" => 0,
38 "cert-extrapad.pem" => 0,
39 "cert-infixwhitespace.pem" => 1,
41 "cert-leadingwhitespace.pem" => 1,
42 "cert-longline.pem" => 1,
43 "cert-misalignedpad.pem" => 0,
44 "cert-onecolumn.pem" => 1,
45 "cert-oneline.pem" => 1,
46 "cert-shortandlongline.pem" => 1,
47 "cert-shortline.pem" => 1,
48 "cert-threecolumn.pem" => 1,
49 "cert-trailingwhitespace.pem" => 1,
53 "dsa-1023line.pem" => 0,
54 "dsa-1024line.pem" => 0,
55 "dsa-1025line.pem" => 0,
56 "dsa-255line.pem" => 0,
57 "dsa-256line.pem" => 0,
58 "dsa-257line.pem" => 0,
59 "dsa-blankline.pem" => 0,
60 "dsa-comment.pem" => 0,
61 "dsa-corruptedheader.pem" => 0,
62 "dsa-corruptiv.pem" => 0,
63 "dsa-earlypad.pem" => 0,
64 "dsa-extrapad.pem" => 0,
65 "dsa-infixwhitespace.pem" => 0,
67 "dsa-leadingwhitespace.pem" => 0,
68 "dsa-longline.pem" => 0,
69 "dsa-misalignedpad.pem" => 0,
70 "dsa-onecolumn.pem" => 0,
71 "dsa-oneline.pem" => 0,
72 "dsa-onelineheader.pem" => 0,
73 "dsa-shortandlongline.pem" => 0,
74 "dsa-shortline.pem" => 0,
75 "dsa-threecolumn.pem" => 0,
76 "dsa-trailingwhitespace.pem" => 1,
80 plan tests
=> scalar keys(%cert_expected) + scalar keys(%dsa_expected) + 2;
82 foreach my $input (keys %cert_expected) {
83 my @common = ($cmd, "x509", "-text", "-noout", "-inform", "PEM", "-in");
84 my @data = run
(app
([@common, data_file
($input)], stderr
=> undef), capture
=> 1);
85 my @match = grep /The Great State of Long-Winded Certificate Field Names Whereby to Increase the Output Size/, @data;
86 is
((scalar @match > 0 ?
1 : 0), $cert_expected{$input});
89 skip
"DSA support disabled, skipping...", (scalar keys %dsa_expected) unless !disabled
("dsa");
90 foreach my $input (keys %dsa_expected) {
91 my @common = ($cmd, "pkey", "-inform", "PEM", "-passin", "file:" . data_file
("wellknown"), "-noout", "-text", "-in");
94 local $ENV{MSYS2_ARG_CONV_EXCL
} = "file:";
95 @data = run
(app
([@common, data_file
($input)], stderr
=> undef), capture
=> 1);
97 my @match = grep /68:42:02:16:63:54:16:eb:06:5c:ab:06:72:3b:78:/, @data;
98 is
((scalar @match > 0 ?
1 : 0), $dsa_expected{$input});
102 skip
"RSA support disabled, skipping...", 1 unless !disabled
("rsa");
103 my @common = ($cmd, "pkey", "-inform", "PEM", "-noout", "-text", "-in");
104 my @data = run
(app
([@common, data_file
("beermug.pem")], stderr
=> undef), capture
=> 1);
105 my @match = grep /00:a0:3a:21:14:5d:cd:b6:d5:a0:3e:49:23:c1:3a:/, @data;
106 ok
(scalar @match > 0 ?
1 : 0);
109 ok
(run
(test
(["pemtest"])), "running pemtest");