Added app for EVP_KDF
[openssl.git] / test / recipes / 25-test_x509.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
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
8
9
10 use strict;
11 use warnings;
12
13 use File::Spec;
14 use OpenSSL::Test::Utils;
15 use OpenSSL::Test qw/:DEFAULT srctop_file/;
16
17 setup("test_x509");
18
19 plan tests => 10;
20
21 require_ok(srctop_file('test','recipes','tconversion.pl'));
22
23 my $pem = srctop_file("test/certs", "cyrillic.pem");
24 my $out = "cyrillic.out";
25 my $msb = srctop_file("test/certs", "cyrillic.msb");
26 my $utf = srctop_file("test/certs", "cyrillic.utf8");
27
28 ok(run(app(["openssl", "x509", "-text", "-in", $pem, "-out", $out,
29             "-nameopt", "esc_msb"])));
30 is(cmp_text($out, srctop_file("test/certs", "cyrillic.msb")),
31    0, 'Comparing esc_msb output');
32 ok(run(app(["openssl", "x509", "-text", "-in", $pem, "-out", $out,
33             "-nameopt", "utf8"])));
34 is(cmp_text($out, srctop_file("test/certs", "cyrillic.utf8")),
35    0, 'Comparing utf8 output');
36 unlink $out;
37
38 SKIP: {
39     skip "EC disabled", 1 if disabled("ec");
40
41     # producing and checking self-issued (but not self-signed) cert
42     my @path = qw(test certs);
43     my $subj = "/CN=CA"; # using same DN as in issuer of ee-cert.pem
44     my $pkey = srctop_file(@path, "ca-key.pem"); #  issuer private key
45     my $pubkey = "ca-pubkey.pem"; # the corresponding issuer public key
46     # use any (different) key for signing our self-issued cert:
47     my $signkey = srctop_file(@path, "ee-ecdsa-key.pem");
48     my $selfout = "self-issued.out";
49     my $testcert = srctop_file(@path, "ee-cert.pem");
50     ok(run(app(["openssl", "pkey", "-in", $pkey, "-pubout", "-out", $pubkey]))
51        &&
52        run(app(["openssl", "x509", "-new", "-force_pubkey", $pubkey,
53                 "-subj", $subj, "-signkey", $signkey, "-out", $selfout]))
54        &&
55        run(app(["openssl", "verify", "-no_check_time",
56                 "-trusted", $selfout, $testcert])));
57     unlink $pubkey;
58     unlink $selfout;
59 }
60
61 subtest 'x509 -- x.509 v1 certificate' => sub {
62     tconversion("x509", srctop_file("test","testx509.pem"));
63 };
64 subtest 'x509 -- first x.509 v3 certificate' => sub {
65     tconversion("x509", srctop_file("test","v3-cert1.pem"));
66 };
67 subtest 'x509 -- second x.509 v3 certificate' => sub {
68     tconversion("x509", srctop_file("test","v3-cert2.pem"));
69 };
70
71 subtest 'x509 -- pathlen' => sub {
72     ok(run(test(["v3ext", srctop_file("test/certs", "pathlen.pem")])));
73 }