2017-02-03 07:31:09 +08:00
|
|
|
#! /usr/bin/env perl
|
2021-01-28 20:54:57 +08:00
|
|
|
# Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2017-02-03 07:31:09 +08:00
|
|
|
#
|
2018-12-06 20:05:25 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2017-02-03 07:31:09 +08: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
|
|
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use File::Spec;
|
2021-01-22 22:52:07 +08:00
|
|
|
use File::Compare qw/compare_text/;
|
2017-08-02 04:43:56 +08:00
|
|
|
use OpenSSL::Glob;
|
2017-02-03 07:31:09 +08:00
|
|
|
use OpenSSL::Test qw/:DEFAULT data_file/;
|
|
|
|
use OpenSSL::Test::Utils;
|
|
|
|
|
|
|
|
setup("test_ecparam");
|
|
|
|
|
2021-01-22 22:52:07 +08:00
|
|
|
plan skip_all => "EC or EC2M isn't supported in this build"
|
2017-04-02 17:18:59 +08:00
|
|
|
if disabled("ec") || disabled("ec2m");
|
2017-02-03 07:31:09 +08:00
|
|
|
|
|
|
|
my @valid = glob(data_file("valid", "*.pem"));
|
2021-01-22 22:52:07 +08:00
|
|
|
my @noncanon = glob(data_file("noncanon", "*.pem"));
|
2017-02-03 07:31:09 +08:00
|
|
|
my @invalid = glob(data_file("invalid", "*.pem"));
|
|
|
|
|
2021-01-22 22:52:07 +08:00
|
|
|
plan tests => 11;
|
2017-02-03 07:31:09 +08:00
|
|
|
|
2021-01-22 22:52:07 +08:00
|
|
|
sub checkload {
|
|
|
|
my $files = shift; # List of files
|
|
|
|
my $valid = shift; # Check should pass or fail?
|
|
|
|
my $app = shift; # Which application
|
|
|
|
my $opt = shift; # Additional option
|
2017-02-03 07:31:09 +08:00
|
|
|
|
2021-01-22 22:52:07 +08:00
|
|
|
foreach (@$files) {
|
|
|
|
if ($valid) {
|
|
|
|
ok(run(app(['openssl', $app, '-noout', $opt, '-in', $_])));
|
|
|
|
} else {
|
|
|
|
ok(!run(app(['openssl', $app, '-noout', $opt, '-in', $_])));
|
|
|
|
}
|
2020-02-12 08:10:44 +08:00
|
|
|
}
|
2021-01-22 22:52:07 +08:00
|
|
|
}
|
2020-02-12 08:10:44 +08:00
|
|
|
|
2021-01-22 22:52:07 +08:00
|
|
|
sub checkcompare {
|
|
|
|
my $files = shift; # List of files
|
|
|
|
my $app = shift; # Which application
|
2020-02-12 08:10:44 +08:00
|
|
|
|
2021-01-22 22:52:07 +08:00
|
|
|
foreach (@$files) {
|
|
|
|
my $testout = "$app.tst";
|
2020-02-12 08:10:44 +08:00
|
|
|
|
2021-01-22 22:52:07 +08:00
|
|
|
ok(run(app(['openssl', $app, '-out', $testout, '-in', $_])));
|
|
|
|
ok(!compare_text($_, $testout), "Original file $_ is the same as new one");
|
2020-02-12 08:10:44 +08:00
|
|
|
}
|
2019-03-21 18:09:02 +08:00
|
|
|
}
|
|
|
|
|
2021-01-22 22:52:07 +08:00
|
|
|
subtest "Check loading valid parameters by ecparam with -check" => sub {
|
|
|
|
plan tests => scalar(@valid);
|
|
|
|
checkload(\@valid, 1, "ecparam", "-check");
|
|
|
|
};
|
2019-03-21 18:09:02 +08:00
|
|
|
|
2021-01-22 22:52:07 +08:00
|
|
|
subtest "Check loading valid parameters by ecparam with -check_named" => sub {
|
|
|
|
plan tests => scalar(@valid);
|
|
|
|
checkload(\@valid, 1, "ecparam", "-check_named");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Check loading valid parameters by pkeyparam with -check" => sub {
|
|
|
|
plan tests => scalar(@valid);
|
|
|
|
checkload(\@valid, 1, "pkeyparam", "-check");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Check loading non-canonically encoded parameters by ecparam with -check" => sub {
|
|
|
|
plan tests => scalar(@noncanon);
|
|
|
|
checkload(\@noncanon, 1, "ecparam", "-check");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Check loading non-canonically encoded parameters by ecparam with -check_named" => sub {
|
|
|
|
plan tests => scalar(@noncanon);
|
|
|
|
checkload(\@noncanon, 1, "ecparam", "-check_named");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Check loading non-canonically encoded parameters by pkeyparam with -check" => sub {
|
|
|
|
plan tests => scalar(@noncanon);
|
|
|
|
checkload(\@noncanon, 1, "pkeyparam", "-check");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Check loading invalid parameters by ecparam with -check" => sub {
|
|
|
|
plan tests => scalar(@invalid);
|
|
|
|
checkload(\@invalid, 0, "ecparam", "-check");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Check loading invalid parameters by ecparam with -check_named" => sub {
|
|
|
|
plan tests => scalar(@invalid);
|
|
|
|
checkload(\@invalid, 0, "ecparam", "-check_named");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Check loading invalid parameters by pkeyparam with -check" => sub {
|
|
|
|
plan tests => scalar(@invalid);
|
|
|
|
checkload(\@invalid, 0, "pkeyparam", "-check");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Check ecparam does not change the parameter file on output" => sub {
|
|
|
|
plan tests => 2 * scalar(@valid);
|
|
|
|
checkcompare(\@valid, "ecparam");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Check pkeyparam does not change the parameter file on output" => sub {
|
|
|
|
plan tests => 2 * scalar(@valid);
|
|
|
|
checkcompare(\@valid, "pkeyparam");
|
|
|
|
};
|