25-test_pkcs8.t 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #! /usr/bin/env perl
  2. # Copyright 2022 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::Utils;
  11. use File::Compare qw(compare_text);
  12. use OpenSSL::Test qw/:DEFAULT srctop_file ok_nofips is_nofips/;
  13. setup("test_pkcs8");
  14. plan tests => 3;
  15. SKIP: {
  16. skip "SM2, SM3 or SM4 is not supported by this OpenSSL build", 3
  17. if disabled("sm2") || disabled("sm3") || disabled("sm4");
  18. ok_nofips(run(app(([ 'openssl', 'pkcs8', '-topk8',
  19. '-in', srctop_file('test', 'certs', 'sm2.key'),
  20. '-out', 'sm2-pbes2-sm4-hmacWithSM3.key',
  21. '-passout', 'pass:password',
  22. '-v2', 'sm4', '-v2prf', 'hmacWithSM3']))),
  23. "Convert a private key to PKCS#5 v2.0 format using SM4 and hmacWithSM3");
  24. ok_nofips(run(app(([ 'openssl', 'pkcs8', '-topk8',
  25. '-in', 'sm2-pbes2-sm4-hmacWithSM3.key',
  26. '-out', 'sm2.key',
  27. '-passin', 'pass:password', '-nocrypt',
  28. '-v2', 'sm4', '-v2prf', 'hmacWithSM3']))),
  29. "Convert from PKCS#5 v2.0 format to PKCS#8 unencrypted format");
  30. is_nofips(compare_text(srctop_file('test', 'certs', 'sm2.key'), 'sm2.key'), 0,
  31. "compare test/certs/sm2.key to sm2.key")
  32. }