xref: /freebsd/crypto/openssl/test/recipes/25-test_crl.t (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert#! /usr/bin/env perl
2*e0c4386eSCy Schubert# Copyright 2015-2021 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 Schubert
16*e0c4386eSCy Schubertsetup("test_crl");
17*e0c4386eSCy Schubert
18*e0c4386eSCy Schubertplan tests => 10;
19*e0c4386eSCy Schubert
20*e0c4386eSCy Schubertrequire_ok(srctop_file('test','recipes','tconversion.pl'));
21*e0c4386eSCy Schubert
22*e0c4386eSCy Schubertmy $pem = srctop_file("test/certs", "cyrillic_crl.pem");
23*e0c4386eSCy Schubertmy $out = "cyrillic_crl.out";
24*e0c4386eSCy Schubertmy $utf = srctop_file("test/certs", "cyrillic_crl.utf8");
25*e0c4386eSCy Schubert
26*e0c4386eSCy Schubertsubtest 'crl conversions' => sub {
27*e0c4386eSCy Schubert    tconversion( -type => "crl", -in => srctop_file("test","testcrl.pem") );
28*e0c4386eSCy Schubert};
29*e0c4386eSCy Schubert
30*e0c4386eSCy Schubertok(run(test(['crltest'])));
31*e0c4386eSCy Schubert
32*e0c4386eSCy Schubertok(compare1stline([qw{openssl crl -noout -fingerprint -in},
33*e0c4386eSCy Schubert                   srctop_file('test', 'testcrl.pem')],
34*e0c4386eSCy Schubert                  'SHA1 Fingerprint=BA:F4:1B:AD:7A:9B:2F:09:16:BC:60:A7:0E:CE:79:2E:36:00:E7:B2'));
35*e0c4386eSCy Schubertok(compare1stline([qw{openssl crl -noout -fingerprint -sha256 -in},
36*e0c4386eSCy Schubert                   srctop_file('test', 'testcrl.pem')],
37*e0c4386eSCy Schubert                  'SHA2-256 Fingerprint=B3:A9:FD:A7:2E:8C:3D:DF:D0:F1:C3:1A:96:60:B5:FD:B0:99:7C:7F:0E:E4:34:F5:DB:87:62:36:BC:F1:BC:1B'));
38*e0c4386eSCy Schubertok(compare1stline([qw{openssl crl -noout -hash -in},
39*e0c4386eSCy Schubert                   srctop_file('test', 'testcrl.pem')],
40*e0c4386eSCy Schubert                  '106cd822'));
41*e0c4386eSCy Schubert
42*e0c4386eSCy Schubertok(compare1stline_stdin([qw{openssl crl -hash -noout}],
43*e0c4386eSCy Schubert                        srctop_file("test","testcrl.pem"),
44*e0c4386eSCy Schubert                        '106cd822'),
45*e0c4386eSCy Schubert   "crl piped input test");
46*e0c4386eSCy Schubert
47*e0c4386eSCy Schubertok(!run(app(["openssl", "crl", "-text", "-in", $pem, "-inform", "DER",
48*e0c4386eSCy Schubert             "-out", $out, "-nameopt", "utf8"])));
49*e0c4386eSCy Schubertok(run(app(["openssl", "crl", "-text", "-in", $pem, "-inform", "PEM",
50*e0c4386eSCy Schubert            "-out", $out, "-nameopt", "utf8"])));
51*e0c4386eSCy Schubertis(cmp_text($out, srctop_file("test/certs", "cyrillic_crl.utf8")),
52*e0c4386eSCy Schubert   0, 'Comparing utf8 output');
53*e0c4386eSCy Schubert
54*e0c4386eSCy Schubertsub compare1stline {
55*e0c4386eSCy Schubert    my ($cmdarray, $str) = @_;
56*e0c4386eSCy Schubert    my @lines = run(app($cmdarray), capture => 1);
57*e0c4386eSCy Schubert
58*e0c4386eSCy Schubert    return 1 if $lines[0] =~ m|^\Q${str}\E\R$|;
59*e0c4386eSCy Schubert    note "Got      ", $lines[0];
60*e0c4386eSCy Schubert    note "Expected ", $str;
61*e0c4386eSCy Schubert    return 0;
62*e0c4386eSCy Schubert}
63*e0c4386eSCy Schubert
64*e0c4386eSCy Schubertsub compare1stline_stdin {
65*e0c4386eSCy Schubert    my ($cmdarray, $infile, $str) = @_;
66*e0c4386eSCy Schubert    my @lines = run(app($cmdarray, stdin => $infile), capture => 1);
67*e0c4386eSCy Schubert
68*e0c4386eSCy Schubert    return 1 if $lines[0] =~ m|^\Q${str}\E\R$|;
69*e0c4386eSCy Schubert    note "Got      ", $lines[0];
70*e0c4386eSCy Schubert    note "Expected ", $str;
71*e0c4386eSCy Schubert    return 0;
72*e0c4386eSCy Schubert}
73