#! /usr/bin/env perl
-# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2016-2018 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
-use File::Spec;
+use File::Spec::Functions;
use File::Copy;
use MIME::Base64;
use OpenSSL::Test qw(:DEFAULT srctop_file srctop_dir bldtop_file data_file);
+use OpenSSL::Test::Utils;
my $test_name = "test_store";
setup($test_name);
-# The MSYS2 run-time convert arguments that look like paths when executing
-# a program unless that application is linked with the MSYS run-time. The
-# exact conversion rules are listed here:
-#
-# http://www.mingw.org/wiki/Posix_path_conversion
-#
-# With the built-in configurations (all having names starting with "mingw"),
-# the openssl application is not linked with the MSYS2 run-time, and therefore,
-# it will receive possibly converted arguments from the process that executes
-# it. This conversion is fine for normal path arguments, but when those
-# arguments are URIs, they sometimes aren't converted right (typically for
-# URIs without an authority component, 'cause the conversion mechanism doesn't
-# recognise them as URIs) or aren't converted at all (which gives perfectly
-# normal absolute paths from the MSYS viewpoint, but don't work for the
-# Windows run-time we're linked with).
-#
-# It's also possible to avoid conversion by defining MSYS2_ARG_CONV_EXCL with
-# some suitable pattern ("*" to avoid conversions entirely), but that will
-# again give us unconverted paths that don't work with the Windows run-time
-# we're linked with.
-#
-# Checking for both msys perl operating environment and that the target name
-# starts with "mingw", we're doing what we can to assure that other configs
-# that might link openssl.exe with the MSYS run-time are not disturbed.
-my $msys_mingw = ($^O eq 'msys') && (config('target') =~ m|^mingw|);
+my $mingw = config('target') =~ m|^mingw|;
my @noexist_files =
( "test/blahdiblah.pem",
( "file:blahdiblah.pem",
"file:test/blahdibleh.der" );
-
my $n = (3 * scalar @noexist_files)
+ (6 * scalar @src_files)
+ (4 * scalar @generated_files)
+ (scalar keys %generated_file_files)
+ (scalar @noexist_file_files)
- + 4;
+ + 3
+ + 11;
plan tests => $n;
{
skip "failed initialisation", $n unless init();
- # test PEM_read_bio_PrivateKey
- ok(run(app(["openssl", "rsa", "-in", "rsa-key-pkcs8-pbes2-sha256.pem",
- "-passin", "pass:password"])));
+ my $rehash = init_rehash();
foreach (@noexist_files) {
my $file = srctop_file($_);
- SKIP: {
- ok(!run(app(["openssl", "storeutl", $file])));
- ok(!run(app(["openssl", "storeutl", to_abs_file($file)])));
- skip "No test of URI form of $file for mingw", 1 if $msys_mingw;
+ ok(!run(app(["openssl", "storeutl", "-noout", $file])));
+ ok(!run(app(["openssl", "storeutl", "-noout",
+ to_abs_file($file)])));
+ {
+ local $ENV{MSYS2_ARG_CONV_EXCL} = "file:";
- ok(!run(app(["openssl", "storeutl", to_abs_file_uri($file)])));
+ ok(!run(app(["openssl", "storeutl", "-noout",
+ to_abs_file_uri($file)])));
}
}
foreach (@src_files) {
my $file = srctop_file($_);
- SKIP: {
- ok(run(app(["openssl", "storeutl", $file])));
- ok(run(app(["openssl", "storeutl", to_abs_file($file)])));
- skip "No test of URI form of $file for mingw", 4 if $msys_mingw;
+ ok(run(app(["openssl", "storeutl", "-noout", $file])));
+ ok(run(app(["openssl", "storeutl", "-noout", to_abs_file($file)])));
+ SKIP:
+ {
+ skip "file: tests disabled on MingW", 4 if $mingw;
- ok(run(app(["openssl", "storeutl", to_abs_file_uri($file)])));
- ok(run(app(["openssl", "storeutl",
+ ok(run(app(["openssl", "storeutl", "-noout",
+ to_abs_file_uri($file)])));
+ ok(run(app(["openssl", "storeutl", "-noout",
to_abs_file_uri($file, 0, "")])));
- ok(run(app(["openssl", "storeutl",
+ ok(run(app(["openssl", "storeutl", "-noout",
to_abs_file_uri($file, 0, "localhost")])));
- ok(!run(app(["openssl", "storeutl",
+ ok(!run(app(["openssl", "storeutl", "-noout",
to_abs_file_uri($file, 0, "dummy")])));
}
}
foreach (@generated_files) {
- SKIP: {
- ok(run(app(["openssl", "storeutl", "-passin", "pass:password",
- $_])));
- ok(run(app(["openssl", "storeutl", "-passin", "pass:password",
- to_abs_file($_)])));
-
- skip "No test of URI form of $_ for mingw", 2 if $msys_mingw;
-
- ok(run(app(["openssl", "storeutl", "-passin", "pass:password",
- to_abs_file_uri($_)])));
- ok(!run(app(["openssl", "storeutl", "-passin", "pass:password",
- to_file_uri($_)])));
+ ok(run(app(["openssl", "storeutl", "-noout", "-passin",
+ "pass:password", $_])));
+ ok(run(app(["openssl", "storeutl", "-noout", "-passin",
+ "pass:password", to_abs_file($_)])));
+
+ SKIP:
+ {
+ skip "file: tests disabled on MingW", 2 if $mingw;
+
+ ok(run(app(["openssl", "storeutl", "-noout", "-passin",
+ "pass:password", to_abs_file_uri($_)])));
+ ok(!run(app(["openssl", "storeutl", "-noout", "-passin",
+ "pass:password", to_file_uri($_)])));
}
}
foreach (values %generated_file_files) {
- SKIP: {
- skip "No test of $_ for mingw", 1 if $msys_mingw;
+ SKIP:
+ {
+ skip "file: tests disabled on MingW", 1 if $mingw;
- ok(run(app(["openssl", "storeutl", $_])));
+ ok(run(app(["openssl", "storeutl", "-noout", $_])));
}
}
foreach (@noexist_file_files) {
- SKIP: {
- skip "No test of $_ for mingw", 1 if $msys_mingw;
+ SKIP:
+ {
+ skip "file: tests disabled on MingW", 1 if $mingw;
- ok(!run(app(["openssl", "storeutl", $_])));
+ ok(!run(app(["openssl", "storeutl", "-noout", $_])));
}
}
{
my $dir = srctop_dir("test", "certs");
- SKIP: {
- ok(run(app(["openssl", "storeutl", $dir])));
- ok(run(app(["openssl", "storeutl", to_abs_file($dir, 1)])));
- skip "No test of URI form of $dir for mingw", 1 if $msys_mingw;
+ ok(run(app(["openssl", "storeutl", "-noout", $dir])));
+ ok(run(app(["openssl", "storeutl", "-noout",
+ to_abs_file($dir, 1)])));
+ SKIP:
+ {
+ skip "file: tests disabled on MingW", 1 if $mingw;
- ok(run(app(["openssl", "storeutl", to_abs_file_uri($dir, 1)])));
+ ok(run(app(["openssl", "storeutl", "-noout",
+ to_abs_file_uri($dir, 1)])));
}
}
+
+ ok(!run(app(['openssl', 'storeutl', '-noout',
+ '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
+ srctop_file('test', 'testx509.pem')])),
+ "Checking that -subject can't be used with a single file");
+
+ ok(run(app(['openssl', 'storeutl', '-certs', '-noout',
+ srctop_file('test', 'testx509.pem')])),
+ "Checking that -certs returns 1 object on a certificate file");
+ ok(run(app(['openssl', 'storeutl', '-certs', '-noout',
+ srctop_file('test', 'testcrl.pem')])),
+ "Checking that -certs returns 0 objects on a CRL file");
+
+ ok(run(app(['openssl', 'storeutl', '-crls', '-noout',
+ srctop_file('test', 'testx509.pem')])),
+ "Checking that -crls returns 0 objects on a certificate file");
+ ok(run(app(['openssl', 'storeutl', '-crls', '-noout',
+ srctop_file('test', 'testcrl.pem')])),
+ "Checking that -crls returns 1 object on a CRL file");
+
+ SKIP: {
+ skip "failed rehash initialisation", 6 unless $rehash;
+
+ # subject from testx509.pem:
+ # '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert'
+ # issuer from testcrl.pem:
+ # '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority'
+ ok(run(app(['openssl', 'storeutl', '-noout',
+ '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
+ catdir(curdir(), 'rehash')])));
+ ok(run(app(['openssl', 'storeutl', '-noout',
+ '-subject',
+ '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority',
+ catdir(curdir(), 'rehash')])));
+ ok(run(app(['openssl', 'storeutl', '-noout', '-certs',
+ '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
+ catdir(curdir(), 'rehash')])));
+ ok(run(app(['openssl', 'storeutl', '-noout', '-crls',
+ '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
+ catdir(curdir(), 'rehash')])));
+ ok(run(app(['openssl', 'storeutl', '-noout', '-certs',
+ '-subject',
+ '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority',
+ catdir(curdir(), 'rehash')])));
+ ok(run(app(['openssl', 'storeutl', '-noout', '-crls',
+ '-subject',
+ '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority',
+ catdir(curdir(), 'rehash')])));
+ }
}
}, create => 1, cleanup => 1;
);
}
+sub init_rehash {
+ return (
+ mkdir(catdir(curdir(), 'rehash'))
+ && copy(srctop_file('test', 'testx509.pem'),
+ catdir(curdir(), 'rehash'))
+ && copy(srctop_file('test', 'testcrl.pem'),
+ catdir(curdir(), 'rehash'))
+ && run(app(['openssl', 'rehash', catdir(curdir(), 'rehash')]))
+ );
+}
+
sub runall {
my ($function, @items) = @_;