2017-02-24 04:28:32 +08:00
|
|
|
#! /usr/bin/env perl
|
2021-04-08 20:04:41 +08:00
|
|
|
# Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2017-02-24 04:28:32 +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-24 04:28:32 +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::Compare qw/compare_text/;
|
|
|
|
use File::Basename;
|
|
|
|
use OpenSSL::Test qw/:DEFAULT srctop_file data_file/;
|
|
|
|
use OpenSSL::Test::Utils;
|
|
|
|
|
|
|
|
setup("test_pem_reading");
|
|
|
|
|
|
|
|
my $testsrc = srctop_file("test", "recipes", basename($0));
|
|
|
|
|
|
|
|
my $cmd = "openssl";
|
|
|
|
|
|
|
|
# map input PEM file to 1 if it should be accepted; 0 when should be rejected
|
|
|
|
my %cert_expected = (
|
|
|
|
"cert-1023line.pem" => 1,
|
|
|
|
"cert-1024line.pem" => 1,
|
|
|
|
"cert-1025line.pem" => 1,
|
2020-04-08 01:33:39 +08:00
|
|
|
"cert-254-chars-at-the-end.pem" => 1,
|
|
|
|
"cert-254-chars-in-the-middle.pem" => 1,
|
2017-02-24 04:28:32 +08:00
|
|
|
"cert-255line.pem" => 1,
|
|
|
|
"cert-256line.pem" => 1,
|
|
|
|
"cert-257line.pem" => 1,
|
|
|
|
"cert-blankline.pem" => 0,
|
2019-10-07 03:25:10 +08:00
|
|
|
"cert-bom.pem" => 1,
|
2017-02-24 04:28:32 +08:00
|
|
|
"cert-comment.pem" => 0,
|
|
|
|
"cert-earlypad.pem" => 0,
|
|
|
|
"cert-extrapad.pem" => 0,
|
|
|
|
"cert-infixwhitespace.pem" => 1,
|
|
|
|
"cert-junk.pem" => 0,
|
|
|
|
"cert-leadingwhitespace.pem" => 1,
|
|
|
|
"cert-longline.pem" => 1,
|
|
|
|
"cert-misalignedpad.pem" => 0,
|
|
|
|
"cert-onecolumn.pem" => 1,
|
|
|
|
"cert-oneline.pem" => 1,
|
2020-04-08 01:33:39 +08:00
|
|
|
"cert-oneline-multiple-of-254.pem" => 1,
|
2017-02-24 04:28:32 +08:00
|
|
|
"cert-shortandlongline.pem" => 1,
|
|
|
|
"cert-shortline.pem" => 1,
|
|
|
|
"cert-threecolumn.pem" => 1,
|
|
|
|
"cert-trailingwhitespace.pem" => 1,
|
|
|
|
"cert.pem" => 1
|
|
|
|
);
|
|
|
|
my %dsa_expected = (
|
|
|
|
"dsa-1023line.pem" => 0,
|
|
|
|
"dsa-1024line.pem" => 0,
|
|
|
|
"dsa-1025line.pem" => 0,
|
|
|
|
"dsa-255line.pem" => 0,
|
|
|
|
"dsa-256line.pem" => 0,
|
|
|
|
"dsa-257line.pem" => 0,
|
|
|
|
"dsa-blankline.pem" => 0,
|
|
|
|
"dsa-comment.pem" => 0,
|
|
|
|
"dsa-corruptedheader.pem" => 0,
|
|
|
|
"dsa-corruptiv.pem" => 0,
|
|
|
|
"dsa-earlypad.pem" => 0,
|
|
|
|
"dsa-extrapad.pem" => 0,
|
|
|
|
"dsa-infixwhitespace.pem" => 0,
|
|
|
|
"dsa-junk.pem" => 0,
|
|
|
|
"dsa-leadingwhitespace.pem" => 0,
|
|
|
|
"dsa-longline.pem" => 0,
|
|
|
|
"dsa-misalignedpad.pem" => 0,
|
|
|
|
"dsa-onecolumn.pem" => 0,
|
|
|
|
"dsa-oneline.pem" => 0,
|
|
|
|
"dsa-onelineheader.pem" => 0,
|
|
|
|
"dsa-shortandlongline.pem" => 0,
|
|
|
|
"dsa-shortline.pem" => 0,
|
|
|
|
"dsa-threecolumn.pem" => 0,
|
|
|
|
"dsa-trailingwhitespace.pem" => 1,
|
|
|
|
"dsa.pem" => 1
|
|
|
|
);
|
|
|
|
|
2017-04-13 05:24:43 +08:00
|
|
|
plan tests => scalar keys(%cert_expected) + scalar keys(%dsa_expected) + 2;
|
2017-02-24 04:28:32 +08:00
|
|
|
|
|
|
|
foreach my $input (keys %cert_expected) {
|
|
|
|
my @common = ($cmd, "x509", "-text", "-noout", "-inform", "PEM", "-in");
|
|
|
|
my @data = run(app([@common, data_file($input)], stderr => undef), capture => 1);
|
|
|
|
my @match = grep /The Great State of Long-Winded Certificate Field Names Whereby to Increase the Output Size/, @data;
|
|
|
|
is((scalar @match > 0 ? 1 : 0), $cert_expected{$input});
|
|
|
|
}
|
|
|
|
SKIP: {
|
|
|
|
skip "DSA support disabled, skipping...", (scalar keys %dsa_expected) unless !disabled("dsa");
|
|
|
|
foreach my $input (keys %dsa_expected) {
|
|
|
|
my @common = ($cmd, "pkey", "-inform", "PEM", "-passin", "file:" . data_file("wellknown"), "-noout", "-text", "-in");
|
Avoid unnecessary MSYS2 conversion of some arguments
Fixes #4740
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 it happens that some arguments to the openssl
application get converted when they shouldn't. In one case, it's
arguments like '-passin file:something', and in another, it's a file:
URI (what typically happens is that URIs without an authority
component get converted, 'cause the conversion mechanism doesn't
recognise them as URIs).
To avoid conversion where we don't want it, we simply assign
MSYS2_ARG_CONV_EXCL a pattern to avoid specific conversions. As a
precaution, we only do this where we obviously need it.
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/4765)
2017-11-21 22:09:59 +08:00
|
|
|
my @data;
|
|
|
|
{
|
|
|
|
local $ENV{MSYS2_ARG_CONV_EXCL} = "file:";
|
|
|
|
@data = run(app([@common, data_file($input)], stderr => undef), capture => 1);
|
|
|
|
}
|
2017-02-24 04:28:32 +08:00
|
|
|
my @match = grep /68:42:02:16:63:54:16:eb:06:5c:ab:06:72:3b:78:/, @data;
|
|
|
|
is((scalar @match > 0 ? 1 : 0), $dsa_expected{$input});
|
|
|
|
}
|
|
|
|
}
|
2017-02-24 06:22:10 +08:00
|
|
|
SKIP: {
|
|
|
|
skip "RSA support disabled, skipping...", 1 unless !disabled("rsa");
|
|
|
|
my @common = ($cmd, "pkey", "-inform", "PEM", "-noout", "-text", "-in");
|
|
|
|
my @data = run(app([@common, data_file("beermug.pem")], stderr => undef), capture => 1);
|
|
|
|
my @match = grep /00:a0:3a:21:14:5d:cd:b6:d5:a0:3e:49:23:c1:3a:/, @data;
|
|
|
|
ok(scalar @match > 0 ? 1 : 0);
|
|
|
|
}
|
2017-04-13 05:24:43 +08:00
|
|
|
|
|
|
|
ok(run(test(["pemtest"])), "running pemtest");
|