15-test_ec.t 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2021 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 File::Spec;
  11. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  12. use OpenSSL::Test::Utils;
  13. setup("test_ec");
  14. plan skip_all => 'EC is not supported in this build' if disabled('ec');
  15. plan tests => 15;
  16. my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
  17. require_ok(srctop_file('test','recipes','tconversion.pl'));
  18. ok(run(test(["ectest"])), "running ectest");
  19. # TODO: remove these when the 'ec' app is removed.
  20. # Also consider moving this to the 20-25 test section because it is testing
  21. # the command line tool in addition to the algorithm.
  22. subtest 'EC conversions -- private key' => sub {
  23. tconversion( -type => 'ec', -prefix => 'ec-priv',
  24. -in => srctop_file("test","testec-p256.pem") );
  25. };
  26. subtest 'EC conversions -- private key PKCS#8' => sub {
  27. tconversion( -type => 'ec', -prefix => 'ec-pkcs8',
  28. -in => srctop_file("test","testec-p256.pem"),
  29. -args => "pkey" );
  30. };
  31. subtest 'EC conversions -- public key' => sub {
  32. tconversion( -type => 'ec', -prefix => 'ec-pub',
  33. -in => srctop_file("test","testecpub-p256.pem"),
  34. -args => [ "ec", "-pubin", "-pubout" ] );
  35. };
  36. subtest 'PKEY conversions -- private key' => sub {
  37. tconversion( -type => 'pkey', -prefix => 'ec-pkey-priv',
  38. -in => srctop_file("test","testec-p256.pem") );
  39. };
  40. subtest 'PKEY conversions -- private key PKCS#8' => sub {
  41. tconversion( -type => 'pkey', -prefix => 'ec-pkey-pkcs8',
  42. -in => srctop_file("test","testec-p256.pem"),
  43. -args => "pkey" );
  44. };
  45. subtest 'PKEY conversions -- public key' => sub {
  46. tconversion( -type => 'pkey', -prefix => 'ec-pkey-pub',
  47. -in => srctop_file("test","testecpub-p256.pem"),
  48. -args => [ "pkey", "-pubin", "-pubout" ] );
  49. };
  50. subtest 'Ed25519 conversions -- private key' => sub {
  51. tconversion( -type => "pkey", -prefix => "ed25519-pkey-priv",
  52. -in => srctop_file("test", "tested25519.pem") );
  53. };
  54. subtest 'Ed25519 conversions -- private key PKCS#8' => sub {
  55. tconversion( -type => "pkey", -prefix => "ed25519-pkey-pkcs8",
  56. -in => srctop_file("test", "tested25519.pem"),
  57. -args => ["pkey"] );
  58. };
  59. subtest 'Ed25519 conversions -- public key' => sub {
  60. tconversion( -type => "pkey", -prefix => "ed25519-pkey-pub",
  61. -in => srctop_file("test", "tested25519pub.pem"),
  62. -args => ["pkey", "-pubin", "-pubout"] );
  63. };
  64. subtest 'Ed448 conversions -- private key' => sub {
  65. tconversion( -type => "pkey", -prefix => "ed448-pkey-priv",
  66. -in => srctop_file("test", "tested448.pem") );
  67. };
  68. subtest 'Ed448 conversions -- private key PKCS#8' => sub {
  69. tconversion( -type => "pkey", -prefix => "ed448-pkey-pkcs8",
  70. -in => srctop_file("test", "tested448.pem"),
  71. -args => ["pkey"] );
  72. };
  73. subtest 'Ed448 conversions -- public key' => sub {
  74. tconversion( -type => "pkey", -prefix => "ed448-pkey-pub",
  75. -in => srctop_file("test", "tested448pub.pem"),
  76. -args => ["pkey", "-pubin", "-pubout"] );
  77. };
  78. subtest 'Check loading of fips and non-fips keys' => sub {
  79. plan skip_all => "FIPS is disabled"
  80. if $no_fips;
  81. plan tests => 2;
  82. my $fipsconf = srctop_file("test", "fips-and-base.cnf");
  83. $ENV{OPENSSL_CONF} = $fipsconf;
  84. ok(!run(app(['openssl', 'pkey',
  85. '-check', '-in', srctop_file("test", "testec-p112r1.pem")])),
  86. "Checking non-fips curve key fails in FIPS provider");
  87. ok(run(app(['openssl', 'pkey',
  88. '-provider', 'default',
  89. '-propquery', '?fips!=yes',
  90. '-check', '-in', srctop_file("test", "testec-p112r1.pem")])),
  91. "Checking non-fips curve key succeeds with non-fips property query");
  92. delete $ENV{OPENSSL_CONF};
  93. }