15-test_ec.t 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2023 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. SKIP: {
  51. skip "ECX is not supported by this OpenSSL build", 6
  52. if disabled("ecx");
  53. subtest 'Ed25519 conversions -- private key' => sub {
  54. tconversion( -type => "pkey", -prefix => "ed25519-pkey-priv",
  55. -in => srctop_file("test", "tested25519.pem") );
  56. };
  57. subtest 'Ed25519 conversions -- private key PKCS#8' => sub {
  58. tconversion( -type => "pkey", -prefix => "ed25519-pkey-pkcs8",
  59. -in => srctop_file("test", "tested25519.pem"),
  60. -args => ["pkey"] );
  61. };
  62. subtest 'Ed25519 conversions -- public key' => sub {
  63. tconversion( -type => "pkey", -prefix => "ed25519-pkey-pub",
  64. -in => srctop_file("test", "tested25519pub.pem"),
  65. -args => ["pkey", "-pubin", "-pubout"] );
  66. };
  67. subtest 'Ed448 conversions -- private key' => sub {
  68. tconversion( -type => "pkey", -prefix => "ed448-pkey-priv",
  69. -in => srctop_file("test", "tested448.pem") );
  70. };
  71. subtest 'Ed448 conversions -- private key PKCS#8' => sub {
  72. tconversion( -type => "pkey", -prefix => "ed448-pkey-pkcs8",
  73. -in => srctop_file("test", "tested448.pem"),
  74. -args => ["pkey"] );
  75. };
  76. subtest 'Ed448 conversions -- public key' => sub {
  77. tconversion( -type => "pkey", -prefix => "ed448-pkey-pub",
  78. -in => srctop_file("test", "tested448pub.pem"),
  79. -args => ["pkey", "-pubin", "-pubout"] );
  80. };
  81. }
  82. subtest 'Check loading of fips and non-fips keys' => sub {
  83. plan skip_all => "FIPS is disabled"
  84. if $no_fips;
  85. plan tests => 2;
  86. my $fipsconf = srctop_file("test", "fips-and-base.cnf");
  87. $ENV{OPENSSL_CONF} = $fipsconf;
  88. ok(!run(app(['openssl', 'pkey',
  89. '-check', '-in', srctop_file("test", "testec-p112r1.pem")])),
  90. "Checking non-fips curve key fails in FIPS provider");
  91. ok(run(app(['openssl', 'pkey',
  92. '-provider', 'default',
  93. '-propquery', '?fips!=yes',
  94. '-check', '-in', srctop_file("test", "testec-p112r1.pem")])),
  95. "Checking non-fips curve key succeeds with non-fips property query");
  96. delete $ENV{OPENSSL_CONF};
  97. }