Blame test/recipes/80-test_pkcs12.t

Packit c4476c
#! /usr/bin/env perl
Packit c4476c
# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
#
Packit c4476c
# Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
# this file except in compliance with the License.  You can obtain a copy
Packit c4476c
# in the file LICENSE in the source distribution or at
Packit c4476c
# https://www.openssl.org/source/license.html
Packit c4476c
Packit c4476c
use strict;
Packit c4476c
use warnings;
Packit c4476c
Packit c4476c
use OpenSSL::Test qw/:DEFAULT srctop_file/;
Packit c4476c
use OpenSSL::Test::Utils;
Packit c4476c
Packit c4476c
use Encode;
Packit c4476c
Packit c4476c
setup("test_pkcs12");
Packit c4476c
Packit c4476c
plan skip_all => "The PKCS12 command line utility is not supported by this OpenSSL build"
Packit c4476c
    if disabled("des");
Packit c4476c
Packit c4476c
my $pass = "σύνθημα γνώρισμα";
Packit c4476c
Packit c4476c
my $savedcp;
Packit c4476c
if (eval { require Win32::API; 1; }) {
Packit c4476c
    # Trouble is that Win32 perl uses CreateProcessA, which
Packit c4476c
    # makes it problematic to pass non-ASCII arguments, from perl[!]
Packit c4476c
    # that is. This is because CreateProcessA is just a wrapper for
Packit c4476c
    # CreateProcessW and will call MultiByteToWideChar and use
Packit c4476c
    # system default locale. Since we attempt Greek pass-phrase
Packit c4476c
    # conversion can be done only with Greek locale.
Packit c4476c
Packit c4476c
    Win32::API->Import("kernel32","UINT GetSystemDefaultLCID()");
Packit c4476c
    if (GetSystemDefaultLCID() != 0x408) {
Packit c4476c
        plan skip_all => "Non-Greek system locale";
Packit c4476c
    } else {
Packit c4476c
        # Ensure correct code page so that VERBOSE output is right.
Packit c4476c
        Win32::API->Import("kernel32","UINT GetConsoleOutputCP()");
Packit c4476c
        Win32::API->Import("kernel32","BOOL SetConsoleOutputCP(UINT cp)");
Packit c4476c
        $savedcp = GetConsoleOutputCP();
Packit c4476c
        SetConsoleOutputCP(1253);
Packit c4476c
        $pass = Encode::encode("cp1253",Encode::decode("utf-8",$pass));
Packit c4476c
    }
Packit c4476c
} elsif ($^O eq "MSWin32") {
Packit c4476c
    plan skip_all => "Win32::API unavailable";
Packit c4476c
} else {
Packit c4476c
    # Running MinGW tests transparently under Wine apparently requires
Packit c4476c
    # UTF-8 locale...
Packit c4476c
Packit c4476c
    foreach(`locale -a`) {
Packit c4476c
        s/\R$//;
Packit c4476c
        if ($_ =~ m/^C\.UTF\-?8/i) {
Packit c4476c
            $ENV{LC_ALL} = $_;
Packit c4476c
            last;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
}
Packit c4476c
$ENV{OPENSSL_WIN32_UTF8}=1;
Packit c4476c
Packit c4476c
plan tests => 1;
Packit c4476c
Packit c4476c
# just see that we can read shibboleth.pfx protected with $pass
Packit c4476c
ok(run(app(["openssl", "pkcs12", "-noout",
Packit c4476c
            "-password", "pass:$pass",
Packit c4476c
            "-in", srctop_file("test", "shibboleth.pfx")])),
Packit c4476c
   "test_pkcs12");
Packit c4476c
Packit c4476c
SetConsoleOutputCP($savedcp) if (defined($savedcp));