15-test_rsapss.t 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/env perl
  2. # Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (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 with srctop_file/;
  12. use OpenSSL::Test::Utils;
  13. setup("test_rsapss");
  14. plan tests => 7;
  15. #using test/testrsa.pem which happens to be a 512 bit RSA
  16. ok(run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha1',
  17. '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:max',
  18. '-sigopt', 'rsa_mgf1_md:sha512', '-out', 'testrsapss.sig',
  19. srctop_file('test', 'testrsa.pem')])),
  20. "openssl dgst -sign");
  21. with({ exit_checker => sub { return shift == 1; } },
  22. sub { ok(run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha512',
  23. '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:max',
  24. '-sigopt', 'rsa_mgf1_md:sha512', srctop_file('test', 'testrsa.pem')])),
  25. "openssl dgst -sign, expect to fail gracefully");
  26. ok(run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha512',
  27. '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:2147483647',
  28. '-sigopt', 'rsa_mgf1_md:sha1', srctop_file('test', 'testrsa.pem')])),
  29. "openssl dgst -sign, expect to fail gracefully");
  30. ok(run(app(['openssl', 'dgst', '-prverify', srctop_file('test', 'testrsa.pem'), '-sha512',
  31. '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:max',
  32. '-sigopt', 'rsa_mgf1_md:sha512', '-signature', 'testrsapss.sig',
  33. srctop_file('test', 'testrsa.pem')])),
  34. "openssl dgst -prverify, expect to fail gracefully");
  35. });
  36. ok(run(app(['openssl', 'dgst', '-prverify', srctop_file('test', 'testrsa.pem'), '-sha1',
  37. '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:max',
  38. '-sigopt', 'rsa_mgf1_md:sha512', '-signature', 'testrsapss.sig',
  39. srctop_file('test', 'testrsa.pem')])),
  40. "openssl dgst -prverify");
  41. unlink 'testrsapss.sig';
  42. ok(run(app(['openssl', 'genpkey', '-algorithm', 'RSA-PSS', '-pkeyopt', 'rsa_keygen_bits:1024',
  43. '-pkeyopt', 'rsa_pss_keygen_md:SHA256', '-pkeyopt', 'rsa_pss_keygen_saltlen:10',
  44. '-out', 'testrsapss.pem'])),
  45. "openssl genpkey RSA-PSS with pss parameters");
  46. ok(run(app(['openssl', 'pkey', '-in', 'testrsapss.pem', '-pubout', '-text'])),
  47. "openssl pkey, execute rsa_pub_encode with pss parameters");
  48. unlink 'testrsapss.pem';