2016-04-22 19:21:51 +08:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
# 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-20 04:24:17 +08:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use POSIX;
|
|
|
|
use File::Spec::Functions qw/devnull catfile/;
|
|
|
|
use File::Copy;
|
2017-10-20 03:44:10 +08:00
|
|
|
use OpenSSL::Test qw/:DEFAULT with pipe srctop_dir data_file/;
|
2016-03-22 00:54:53 +08:00
|
|
|
use OpenSSL::Test::Utils;
|
2015-04-20 04:24:17 +08:00
|
|
|
|
|
|
|
setup("test_ocsp");
|
|
|
|
|
2016-03-22 00:54:53 +08:00
|
|
|
plan skip_all => "OCSP is not supported by this OpenSSL build"
|
|
|
|
if disabled("ocsp");
|
|
|
|
|
2016-01-30 08:05:33 +08:00
|
|
|
my $ocspdir=srctop_dir("test", "ocsp-tests");
|
2015-04-20 04:24:17 +08:00
|
|
|
# 17 December 2012 so we don't get certificate expiry errors.
|
|
|
|
my @check_time=("-attime", "1355875200");
|
|
|
|
|
|
|
|
sub test_ocsp {
|
|
|
|
my $title = shift;
|
|
|
|
my $inputfile = shift;
|
|
|
|
my $CAfile = shift;
|
2017-08-17 02:00:05 +08:00
|
|
|
my $untrusted = shift;
|
|
|
|
if ($untrusted eq "") {
|
|
|
|
$untrusted = $CAfile;
|
|
|
|
}
|
2015-04-20 04:24:17 +08:00
|
|
|
my $expected_exit = shift;
|
|
|
|
|
2016-01-14 00:27:06 +08:00
|
|
|
run(app(["openssl", "base64", "-d",
|
|
|
|
"-in", catfile($ocspdir,$inputfile),
|
|
|
|
"-out", "ocsp-resp-fff.dat"]));
|
2015-04-20 04:24:17 +08:00
|
|
|
with({ exit_checker => sub { return shift == $expected_exit; } },
|
2016-01-14 00:27:06 +08:00
|
|
|
sub { ok(run(app(["openssl", "ocsp", "-respin", "ocsp-resp-fff.dat",
|
|
|
|
"-partial_chain", @check_time,
|
|
|
|
"-CAfile", catfile($ocspdir, $CAfile),
|
2017-08-17 02:00:05 +08:00
|
|
|
"-verify_other", catfile($ocspdir, $untrusted),
|
2016-01-14 00:27:06 +08:00
|
|
|
"-no-CApath"])),
|
|
|
|
$title); });
|
|
|
|
unlink "ocsp-resp-fff.dat";
|
2015-04-20 04:24:17 +08:00
|
|
|
}
|
|
|
|
|
2017-10-20 03:44:10 +08:00
|
|
|
plan tests => 11;
|
2015-04-20 04:24:17 +08:00
|
|
|
|
|
|
|
subtest "=== VALID OCSP RESPONSES ===" => sub {
|
2017-08-17 02:00:05 +08:00
|
|
|
plan tests => 7;
|
2015-04-20 04:24:17 +08:00
|
|
|
|
|
|
|
test_ocsp("NON-DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND1.ors", "ND1_Issuer_ICA.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND2.ors", "ND2_Issuer_Root.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND3.ors", "ND3_Issuer_Root.pem", "", 0);
|
|
|
|
test_ocsp("NON-DELEGATED; 3-level CA hierarchy",
|
|
|
|
"ND1.ors", "ND1_Cross_Root.pem", "ND1_Issuer_ICA-Cross.pem", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D1.ors", "D1_Issuer_ICA.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D2.ors", "D2_Issuer_Root.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D3.ors", "D3_Issuer_Root.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest "=== INVALID SIGNATURE on the OCSP RESPONSE ===" => sub {
|
|
|
|
plan tests => 6;
|
|
|
|
|
|
|
|
test_ocsp("NON-DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ISOP_ND1.ors", "ND1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ISOP_ND2.ors", "ND2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ISOP_ND3.ors", "ND3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ISOP_D1.ors", "D1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ISOP_D2.ors", "D2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ISOP_D3.ors", "D3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest "=== WRONG RESPONDERID in the OCSP RESPONSE ===" => sub {
|
|
|
|
plan tests => 6;
|
|
|
|
|
|
|
|
test_ocsp("NON-DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WRID_ND1.ors", "ND1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WRID_ND2.ors", "ND2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WRID_ND3.ors", "ND3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WRID_D1.ors", "D1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WRID_D2.ors", "D2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WRID_D3.ors", "D3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest "=== WRONG ISSUERNAMEHASH in the OCSP RESPONSE ===" => sub {
|
|
|
|
plan tests => 6;
|
|
|
|
|
|
|
|
test_ocsp("NON-DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WINH_ND1.ors", "ND1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WINH_ND2.ors", "ND2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WINH_ND3.ors", "ND3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WINH_D1.ors", "D1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WINH_D2.ors", "D2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WINH_D3.ors", "D3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest "=== WRONG ISSUERKEYHASH in the OCSP RESPONSE ===" => sub {
|
|
|
|
plan tests => 6;
|
|
|
|
|
|
|
|
test_ocsp("NON-DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WIKH_ND1.ors", "ND1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WIKH_ND2.ors", "ND2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WIKH_ND3.ors", "ND3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WIKH_D1.ors", "D1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WIKH_D2.ors", "D2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WIKH_D3.ors", "D3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest "=== WRONG KEY in the DELEGATED OCSP SIGNING CERTIFICATE ===" => sub {
|
|
|
|
plan tests => 3;
|
|
|
|
|
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WKDOSC_D1.ors", "D1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WKDOSC_D2.ors", "D2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"WKDOSC_D3.ors", "D3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest "=== INVALID SIGNATURE on the DELEGATED OCSP SIGNING CERTIFICATE ===" => sub {
|
|
|
|
plan tests => 3;
|
|
|
|
|
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ISDOSC_D1.ors", "D1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ISDOSC_D2.ors", "D2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ISDOSC_D3.ors", "D3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest "=== WRONG SUBJECT NAME in the ISSUER CERTIFICATE ===" => sub {
|
|
|
|
plan tests => 6;
|
|
|
|
|
|
|
|
test_ocsp("NON-DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND1.ors", "WSNIC_ND1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND2.ors", "WSNIC_ND2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND3.ors", "WSNIC_ND3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D1.ors", "WSNIC_D1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D2.ors", "WSNIC_D2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D3.ors", "WSNIC_D3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest "=== WRONG KEY in the ISSUER CERTIFICATE ===" => sub {
|
|
|
|
plan tests => 6;
|
|
|
|
|
|
|
|
test_ocsp("NON-DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND1.ors", "WKIC_ND1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND2.ors", "WKIC_ND2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND3.ors", "WKIC_ND3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D1.ors", "WKIC_D1_Issuer_ICA.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D2.ors", "WKIC_D2_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D3.ors", "WKIC_D3_Issuer_Root.pem", "", 1);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest "=== INVALID SIGNATURE on the ISSUER CERTIFICATE ===" => sub {
|
|
|
|
plan tests => 6;
|
|
|
|
|
|
|
|
# Expect success, because we're explicitly trusting the issuer certificate.
|
|
|
|
test_ocsp("NON-DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND1.ors", "ISIC_ND1_Issuer_ICA.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND2.ors", "ISIC_ND2_Issuer_Root.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("NON-DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"ND3.ors", "ISIC_ND3_Issuer_Root.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Intermediate CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D1.ors", "ISIC_D1_Issuer_ICA.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> Intermediate CA",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D2.ors", "ISIC_D2_Issuer_Root.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
test_ocsp("DELEGATED; Root CA -> EE",
|
2017-08-17 02:00:05 +08:00
|
|
|
"D3.ors", "ISIC_D3_Issuer_Root.pem", "", 0);
|
2015-04-20 04:24:17 +08:00
|
|
|
};
|
2017-10-20 03:44:10 +08:00
|
|
|
|
|
|
|
subtest "=== OCSP API TESTS===" => sub {
|
|
|
|
plan tests => 1;
|
|
|
|
|
|
|
|
ok(run(test(["ocspapitest", data_file("cert.pem"), data_file("key.pem")])),
|
|
|
|
"running ocspapitest");
|
|
|
|
}
|