xref: /freebsd/crypto/openssl/test/recipes/60-test_x509_store.t (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert#! /usr/bin/env perl
2*e0c4386eSCy Schubert# Copyright 2015-2016 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::Copy;
14*e0c4386eSCy Schubertuse File::Spec::Functions qw/:DEFAULT canonpath/;
15*e0c4386eSCy Schubertuse OpenSSL::Test qw/:DEFAULT srctop_file/;
16*e0c4386eSCy Schubert
17*e0c4386eSCy Schubertsetup("test_x509_store");
18*e0c4386eSCy Schubert
19*e0c4386eSCy Schubert#If "openssl rehash -help" fails it's most likely because we're on a platform
20*e0c4386eSCy Schubert#that doesn't support the rehash command (e.g. Windows)
21*e0c4386eSCy Schubertplan skip_all => "test_rehash is not available on this platform"
22*e0c4386eSCy Schubert    unless run(app(["openssl", "rehash", "-help"]));
23*e0c4386eSCy Schubert
24*e0c4386eSCy Schubert# We use 'openssl verify' for these tests, as it contains everything
25*e0c4386eSCy Schubert# we need to conduct these tests.  The tests here are a subset of the
26*e0c4386eSCy Schubert# ones found in 25-test_verify.t
27*e0c4386eSCy Schubert
28*e0c4386eSCy Schubertsub verify {
29*e0c4386eSCy Schubert    my ($cert, $purpose, $trustedpath, $untrusted, @opts) = @_;
30*e0c4386eSCy Schubert    my @args = qw(openssl verify -auth_level 1 -purpose);
31*e0c4386eSCy Schubert    my @path = qw(test certs);
32*e0c4386eSCy Schubert    push(@args, "$purpose", @opts);
33*e0c4386eSCy Schubert    push(@args, "-CApath", $trustedpath);
34*e0c4386eSCy Schubert    for (@$untrusted) { push(@args, "-untrusted", srctop_file(@path, "$_.pem")) }
35*e0c4386eSCy Schubert    push(@args, srctop_file(@path, "$cert.pem"));
36*e0c4386eSCy Schubert    run(app([@args]));
37*e0c4386eSCy Schubert}
38*e0c4386eSCy Schubert
39*e0c4386eSCy Schubertplan tests => 3;
40*e0c4386eSCy Schubert
41*e0c4386eSCy Schubertindir "60-test_x509_store" => sub {
42*e0c4386eSCy Schubert    for (("root-cert")) {
43*e0c4386eSCy Schubert        copy(srctop_file("test", "certs", "$_.pem"), curdir());
44*e0c4386eSCy Schubert    }
45*e0c4386eSCy Schubert    ok(run(app([qw(openssl rehash), curdir()])), "Rehashing");
46*e0c4386eSCy Schubert
47*e0c4386eSCy Schubert    # Canonical success
48*e0c4386eSCy Schubert    ok(verify("ee-cert", "sslserver", curdir(), ["ca-cert"], "-show_chain"),
49*e0c4386eSCy Schubert       "verify ee-cert");
50*e0c4386eSCy Schubert
51*e0c4386eSCy Schubert    # Failure because root cert not present in CApath
52*e0c4386eSCy Schubert    ok(!verify("ca-root2", "any", curdir(), [], "-show_chain"));
53*e0c4386eSCy Schubert}, create => 1, cleanup => 1;
54