| Index: net/cert/internal/verify_signed_data_unittest.cc
|
| diff --git a/net/cert/internal/verify_signed_data_unittest.cc b/net/cert/internal/verify_signed_data_unittest.cc
|
| index ebd8e461c1a4b9f5c5bf2368bc91311e73275cb7..0d444614696effb9febc8bb0afbe5d1f2d8e16c4 100644
|
| --- a/net/cert/internal/verify_signed_data_unittest.cc
|
| +++ b/net/cert/internal/verify_signed_data_unittest.cc
|
| @@ -10,10 +10,15 @@
|
| #include "base/files/file_util.h"
|
| #include "base/path_service.h"
|
| #include "net/cert/internal/signature_algorithm.h"
|
| +#include "net/cert/internal/verification_policy.h"
|
| #include "net/cert/pem_tokenizer.h"
|
| #include "net/der/input.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +#if defined(USE_OPENSSL)
|
| +#include <openssl/obj_mac.h>
|
| +#endif
|
| +
|
| namespace net {
|
|
|
| namespace {
|
| @@ -102,14 +107,17 @@ enum VerifyResult {
|
| FAILURE,
|
| };
|
|
|
| -// Reads test data from |file_name| and runs VerifySignedData() over its inputs.
|
| +// Reads test data from |file_name| and runs VerifySignedData() over its
|
| +// inputs, using |policy|.
|
| //
|
| // If expected_result was SUCCESS then the test will only succeed if
|
| // VerifySignedData() returns true.
|
| //
|
| // If expected_result was FAILURE then the test will only succeed if
|
| // VerifySignedData() returns false.
|
| -void RunTestCase(VerifyResult expected_result, const char* file_name) {
|
| +void RunTestCaseUsingPolicy(VerifyResult expected_result,
|
| + const char* file_name,
|
| + const VerificationPolicy* policy) {
|
| #if !defined(USE_OPENSSL)
|
| LOG(INFO) << "Skipping test, only implemented for BoringSSL";
|
| return;
|
| @@ -139,7 +147,15 @@ void RunTestCase(VerifyResult expected_result, const char* file_name) {
|
| expected_result_bool,
|
| VerifySignedData(*signature_algorithm, InputFromString(&signed_data),
|
| InputFromString(&signature_value),
|
| - InputFromString(&public_key)));
|
| + InputFromString(&public_key), policy));
|
| +}
|
| +
|
| +// RunTestCase() is the same as RunTestCaseUsingPolicy(), only it uses a
|
| +// default policy. This policy will accept a basic profile of signature
|
| +// algorithms / key sizes (refer to BaseVerificationPolicy for the details).
|
| +void RunTestCase(VerifyResult expected_result, const char* file_name) {
|
| + BaseVerificationPolicy policy(1024);
|
| + return RunTestCaseUsingPolicy(expected_result, file_name, &policy);
|
| }
|
|
|
| // Read the descriptions in the test files themselves for details on what is
|
| @@ -153,6 +169,10 @@ TEST(VerifySignedDataTest, RsaPkcs1Sha256) {
|
| RunTestCase(SUCCESS, "rsa-pkcs1-sha256.pem");
|
| }
|
|
|
| +TEST(VerifySignedDataTest, Rsa2048Pkcs1Sha512) {
|
| + RunTestCase(SUCCESS, "rsa2048-pkcs1-sha512.pem");
|
| +}
|
| +
|
| TEST(VerifySignedDataTest, RsaPkcs1Sha256KeyEncodedBer) {
|
| // TODO(eroman): This should fail! (SPKI should be DER-encoded).
|
| RunTestCase(SUCCESS, "rsa-pkcs1-sha256-key-encoded-ber.pem");
|
| @@ -276,6 +296,81 @@ TEST(VerifySignedDataTest, EcdsaPrime256v1Sha512SignatureNotBitString) {
|
| RunTestCase(FAILURE, "ecdsa-prime256v1-sha512-signature-not-bitstring.pem");
|
| }
|
|
|
| +// This policy rejects specifically secp384r1 curves.
|
| +class RejectSecp384r1Policy : public BaseVerificationPolicy {
|
| + public:
|
| + RejectSecp384r1Policy() : BaseVerificationPolicy(2048) {}
|
| +
|
| + bool IsAcceptableCurveForEcdsa(int curve_nid) const override {
|
| +#if defined(USE_OPENSSL)
|
| + if (curve_nid == NID_secp384r1)
|
| + return false;
|
| +#endif
|
| + return true;
|
| + }
|
| +};
|
| +
|
| +TEST(VerifySignedDataTest, PolicyIsAcceptableCurveForEcdsa) {
|
| + RejectSecp384r1Policy policy;
|
| +
|
| + // Using the regular policy both secp384r1 and secp256r1 should be accepted.
|
| + RunTestCase(SUCCESS, "ecdsa-secp384r1-sha256.pem");
|
| + RunTestCase(SUCCESS, "ecdsa-prime256v1-sha512.pem");
|
| +
|
| + // However when using a policy that specifically rejects secp384r1, only
|
| + // prime256v1 should be accepted.
|
| + RunTestCaseUsingPolicy(FAILURE, "ecdsa-secp384r1-sha256.pem", &policy);
|
| + RunTestCaseUsingPolicy(SUCCESS, "ecdsa-prime256v1-sha512.pem", &policy);
|
| +}
|
| +
|
| +TEST(VerifySignedDataTest, PolicyIsAcceptableModulusLengthForRsa) {
|
| + BaseVerificationPolicy policy(2048);
|
| +
|
| + // Using the regular policy both 1024-bit and 2048-bit RSA keys should be
|
| + // accepted.
|
| + RunTestCase(SUCCESS, "rsa-pkcs1-sha256.pem");
|
| + RunTestCase(SUCCESS, "rsa2048-pkcs1-sha512.pem");
|
| +
|
| + // However when using a policy that rejects any keys less than 2048-bits, only
|
| + // one of the tests will pass.
|
| + RunTestCaseUsingPolicy(FAILURE, "rsa-pkcs1-sha256.pem", &policy);
|
| + RunTestCaseUsingPolicy(SUCCESS, "rsa2048-pkcs1-sha512.pem", &policy);
|
| +}
|
| +
|
| +// This policy rejects the use of SHA-512.
|
| +class RejectSha512 : public BaseVerificationPolicy {
|
| + public:
|
| + RejectSha512() : BaseVerificationPolicy(1024) {}
|
| +
|
| + bool IsAcceptableDigestAlgorithm(DigestAlgorithm algorithm) const override {
|
| + return algorithm != DigestAlgorithm::Sha512;
|
| + }
|
| +};
|
| +
|
| +TEST(VerifySignedDataTest, PolicyIsAcceptableDigestAlgorithm) {
|
| + RejectSha512 policy;
|
| +
|
| + // Using the regular policy use of either SHA256 or SHA512 should work
|
| + // (whether as the main digest, or the MGF1 for RSASSA-PSS)
|
| + RunTestCase(SUCCESS, "rsa2048-pkcs1-sha512.pem");
|
| + RunTestCase(SUCCESS, "ecdsa-prime256v1-sha512.pem");
|
| + RunTestCase(SUCCESS, "ecdsa-secp384r1-sha256.pem");
|
| + RunTestCase(SUCCESS, "rsa-pkcs1-sha256.pem");
|
| + RunTestCase(SUCCESS, "rsa-pss-sha256-salt10.pem");
|
| + // This one uses both SHA256 and SHA512
|
| + RunTestCase(SUCCESS, "rsa-pss-sha256-mgf1-sha512-salt33.pem");
|
| +
|
| + // However when using a policy that rejects SHA512, only the tests using
|
| + // exclusively SHA256 should pass).
|
| + RunTestCaseUsingPolicy(FAILURE, "rsa2048-pkcs1-sha512.pem", &policy);
|
| + RunTestCaseUsingPolicy(FAILURE, "ecdsa-prime256v1-sha512.pem", &policy);
|
| + RunTestCaseUsingPolicy(SUCCESS, "ecdsa-secp384r1-sha256.pem", &policy);
|
| + RunTestCaseUsingPolicy(SUCCESS, "rsa-pkcs1-sha256.pem", &policy);
|
| + RunTestCaseUsingPolicy(SUCCESS, "rsa-pss-sha256-salt10.pem", &policy);
|
| + RunTestCaseUsingPolicy(FAILURE, "rsa-pss-sha256-mgf1-sha512-salt33.pem",
|
| + &policy);
|
| +}
|
| +
|
| } // namespace
|
|
|
| } // namespace net
|
|
|