2
0

15-test_rsapss.t 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #! /usr/bin/env perl
  2. # Copyright 2017 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 with srctop_file/;
  12. use OpenSSL::Test::Utils;
  13. setup("test_rsapss");
  14. plan tests => 5;
  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:-3',
  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:-3',
  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:-3',
  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:-3',
  38. '-sigopt', 'rsa_mgf1_md:sha512', '-signature', 'testrsapss.sig',
  39. srctop_file('test', 'testrsa.pem')])),
  40. "openssl dgst -prverify");
  41. unlink 'testrsapss.sig';