1e1051a39Sopenharmony_ci#! /usr/bin/env perl 2e1051a39Sopenharmony_ci# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci# 4e1051a39Sopenharmony_ci# Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci# this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci# in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci# https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ciuse strict; 11e1051a39Sopenharmony_ciuse warnings; 12e1051a39Sopenharmony_ci 13e1051a39Sopenharmony_ciuse File::Copy; 14e1051a39Sopenharmony_ciuse File::Spec::Functions qw/:DEFAULT canonpath/; 15e1051a39Sopenharmony_ciuse OpenSSL::Test qw/:DEFAULT srctop_file/; 16e1051a39Sopenharmony_ci 17e1051a39Sopenharmony_cisetup("test_x509_store"); 18e1051a39Sopenharmony_ci 19e1051a39Sopenharmony_ci#If "openssl rehash -help" fails it's most likely because we're on a platform 20e1051a39Sopenharmony_ci#that doesn't support the rehash command (e.g. Windows) 21e1051a39Sopenharmony_ciplan skip_all => "test_rehash is not available on this platform" 22e1051a39Sopenharmony_ci unless run(app(["openssl", "rehash", "-help"])); 23e1051a39Sopenharmony_ci 24e1051a39Sopenharmony_ci# We use 'openssl verify' for these tests, as it contains everything 25e1051a39Sopenharmony_ci# we need to conduct these tests. The tests here are a subset of the 26e1051a39Sopenharmony_ci# ones found in 25-test_verify.t 27e1051a39Sopenharmony_ci 28e1051a39Sopenharmony_cisub verify { 29e1051a39Sopenharmony_ci my ($cert, $purpose, $trustedpath, $untrusted, @opts) = @_; 30e1051a39Sopenharmony_ci my @args = qw(openssl verify -auth_level 1 -purpose); 31e1051a39Sopenharmony_ci my @path = qw(test certs); 32e1051a39Sopenharmony_ci push(@args, "$purpose", @opts); 33e1051a39Sopenharmony_ci push(@args, "-CApath", $trustedpath); 34e1051a39Sopenharmony_ci for (@$untrusted) { push(@args, "-untrusted", srctop_file(@path, "$_.pem")) } 35e1051a39Sopenharmony_ci push(@args, srctop_file(@path, "$cert.pem")); 36e1051a39Sopenharmony_ci run(app([@args])); 37e1051a39Sopenharmony_ci} 38e1051a39Sopenharmony_ci 39e1051a39Sopenharmony_ciplan tests => 3; 40e1051a39Sopenharmony_ci 41e1051a39Sopenharmony_ciindir "60-test_x509_store" => sub { 42e1051a39Sopenharmony_ci for (("root-cert")) { 43e1051a39Sopenharmony_ci copy(srctop_file("test", "certs", "$_.pem"), curdir()); 44e1051a39Sopenharmony_ci } 45e1051a39Sopenharmony_ci ok(run(app([qw(openssl rehash), curdir()])), "Rehashing"); 46e1051a39Sopenharmony_ci 47e1051a39Sopenharmony_ci # Canonical success 48e1051a39Sopenharmony_ci ok(verify("ee-cert", "sslserver", curdir(), ["ca-cert"], "-show_chain"), 49e1051a39Sopenharmony_ci "verify ee-cert"); 50e1051a39Sopenharmony_ci 51e1051a39Sopenharmony_ci # Failure because root cert not present in CApath 52e1051a39Sopenharmony_ci ok(!verify("ca-root2", "any", curdir(), [], "-show_chain")); 53e1051a39Sopenharmony_ci}, create => 1, cleanup => 1; 54