2016-04-22 11:21:51 +00:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
|
|
#
|
2018-12-06 12:05:25 +00:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-04-22 11:21:51 +00:00
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
|
|
|
|
2015-04-17 18:15:22 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use File::Spec;
|
2019-03-26 16:07:02 +00:00
|
|
|
use OpenSSL::Test::Utils;
|
2016-01-30 00:05:33 +00:00
|
|
|
use OpenSSL::Test qw/:DEFAULT srctop_file/;
|
2015-04-17 18:15:22 +00:00
|
|
|
|
|
|
|
setup("test_x509");
|
|
|
|
|
2019-03-18 23:35:03 +00:00
|
|
|
plan tests => 10;
|
2015-04-17 18:15:22 +00:00
|
|
|
|
2016-01-30 00:05:33 +00:00
|
|
|
require_ok(srctop_file('test','recipes','tconversion.pl'));
|
2015-04-17 18:15:22 +00:00
|
|
|
|
2017-03-14 18:53:35 +00:00
|
|
|
my $pem = srctop_file("test/certs", "cyrillic.pem");
|
|
|
|
my $out = "cyrillic.out";
|
|
|
|
my $msb = srctop_file("test/certs", "cyrillic.msb");
|
|
|
|
my $utf = srctop_file("test/certs", "cyrillic.utf8");
|
|
|
|
|
|
|
|
ok(run(app(["openssl", "x509", "-text", "-in", $pem, "-out", $out,
|
|
|
|
"-nameopt", "esc_msb"])));
|
|
|
|
is(cmp_text($out, srctop_file("test/certs", "cyrillic.msb")),
|
|
|
|
0, 'Comparing esc_msb output');
|
|
|
|
ok(run(app(["openssl", "x509", "-text", "-in", $pem, "-out", $out,
|
|
|
|
"-nameopt", "utf8"])));
|
|
|
|
is(cmp_text($out, srctop_file("test/certs", "cyrillic.utf8")),
|
|
|
|
0, 'Comparing utf8 output');
|
|
|
|
unlink $out;
|
|
|
|
|
2019-03-26 16:07:02 +00:00
|
|
|
SKIP: {
|
|
|
|
skip "EC disabled", 1 if disabled("ec");
|
|
|
|
|
|
|
|
# producing and checking self-issued (but not self-signed) cert
|
|
|
|
my @path = qw(test certs);
|
|
|
|
my $subj = "/CN=CA"; # using same DN as in issuer of ee-cert.pem
|
|
|
|
my $pkey = srctop_file(@path, "ca-key.pem"); # issuer private key
|
|
|
|
my $pubkey = "ca-pubkey.pem"; # the corresponding issuer public key
|
|
|
|
# use any (different) key for signing our self-issued cert:
|
|
|
|
my $signkey = srctop_file(@path, "ee-ecdsa-key.pem");
|
|
|
|
my $selfout = "self-issued.out";
|
|
|
|
my $testcert = srctop_file(@path, "ee-cert.pem");
|
|
|
|
ok(run(app(["openssl", "pkey", "-in", $pkey, "-pubout", "-out", $pubkey]))
|
|
|
|
&&
|
|
|
|
run(app(["openssl", "x509", "-new", "-force_pubkey", $pubkey,
|
|
|
|
"-subj", $subj, "-signkey", $signkey, "-out", $selfout]))
|
|
|
|
&&
|
|
|
|
run(app(["openssl", "verify", "-no_check_time",
|
|
|
|
"-trusted", $selfout, $testcert])));
|
|
|
|
unlink $pubkey;
|
|
|
|
unlink $selfout;
|
|
|
|
}
|
2019-03-18 23:35:03 +00:00
|
|
|
|
2015-04-17 18:15:22 +00:00
|
|
|
subtest 'x509 -- x.509 v1 certificate' => sub {
|
2016-01-30 00:05:33 +00:00
|
|
|
tconversion("x509", srctop_file("test","testx509.pem"));
|
2015-04-17 18:15:22 +00:00
|
|
|
};
|
|
|
|
subtest 'x509 -- first x.509 v3 certificate' => sub {
|
2016-01-30 00:05:33 +00:00
|
|
|
tconversion("x509", srctop_file("test","v3-cert1.pem"));
|
2015-04-17 18:15:22 +00:00
|
|
|
};
|
|
|
|
subtest 'x509 -- second x.509 v3 certificate' => sub {
|
2016-01-30 00:05:33 +00:00
|
|
|
tconversion("x509", srctop_file("test","v3-cert2.pem"));
|
2015-04-17 18:15:22 +00:00
|
|
|
};
|
2016-06-08 15:37:06 +00:00
|
|
|
|
|
|
|
subtest 'x509 -- pathlen' => sub {
|
|
|
|
ok(run(test(["v3ext", srctop_file("test/certs", "pathlen.pem")])));
|
|
|
|
}
|