80-test_pkcs12.t 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #! /usr/bin/env perl
  2. # Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. use strict;
  9. use warnings;
  10. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  11. use OpenSSL::Test::Utils;
  12. use Encode;
  13. setup("test_pkcs12");
  14. plan skip_all => "The PKCS12 command line utility is not supported by this OpenSSL build"
  15. if disabled("des");
  16. my $pass = "σύνθημα γνώρισμα";
  17. my $savedcp;
  18. if (eval { require Win32::API; 1; }) {
  19. # Trouble is that Win32 perl uses CreateProcessA, which
  20. # makes it problematic to pass non-ASCII arguments, from perl[!]
  21. # that is. This is because CreateProcessA is just a wrapper for
  22. # CreateProcessW and will call MultiByteToWideChar and use
  23. # system default locale. Since we attempt Greek pass-phrase
  24. # conversion can be done only with Greek locale.
  25. Win32::API->Import("kernel32","UINT GetSystemDefaultLCID()");
  26. if (GetSystemDefaultLCID() != 0x408) {
  27. plan skip_all => "Non-Greek system locale";
  28. } else {
  29. # Ensure correct code page so that VERBOSE output is right.
  30. Win32::API->Import("kernel32","UINT GetConsoleOutputCP()");
  31. Win32::API->Import("kernel32","BOOL SetConsoleOutputCP(UINT cp)");
  32. $savedcp = GetConsoleOutputCP();
  33. SetConsoleOutputCP(1253);
  34. $pass = Encode::encode("cp1253",Encode::decode("utf-8",$pass));
  35. }
  36. } elsif ($^O eq "MSWin32") {
  37. plan skip_all => "Win32::API unavailable";
  38. } else {
  39. # Running MinGW tests transparently under Wine apparently requires
  40. # UTF-8 locale...
  41. foreach(`locale -a`) {
  42. s/\R$//;
  43. if ($_ =~ m/^C\.UTF\-?8/i) {
  44. $ENV{LC_ALL} = $_;
  45. last;
  46. }
  47. }
  48. }
  49. $ENV{OPENSSL_WIN32_UTF8}=1;
  50. plan tests => 1;
  51. # just see that we can read shibboleth.pfx protected with $pass
  52. ok(run(app(["openssl", "pkcs12", "-noout",
  53. "-password", "pass:$pass",
  54. "-in", srctop_file("test", "shibboleth.pfx")])),
  55. "test_pkcs12");
  56. SetConsoleOutputCP($savedcp) if (defined($savedcp));