| Index: content/renderer/webcrypto/webcrypto_impl_unittest.cc
|
| diff --git a/content/renderer/webcrypto/webcrypto_impl_unittest.cc b/content/renderer/webcrypto/webcrypto_impl_unittest.cc
|
| index bc38293bbb07626fa67ed109416fe77203581038..9ff6dac2959eeeb866931eeb3772045463f811f9 100644
|
| --- a/content/renderer/webcrypto/webcrypto_impl_unittest.cc
|
| +++ b/content/renderer/webcrypto/webcrypto_impl_unittest.cc
|
| @@ -59,6 +59,19 @@ WebKit::WebCryptoAlgorithm CreateAesCbcAlgorithm(
|
| new WebKit::WebCryptoAesCbcParams(Start(iv), iv.size()));
|
| }
|
|
|
| +WebKit::WebCryptoAlgorithm CreateRsaAlgorithm(
|
| + WebKit::WebCryptoAlgorithmId algorithm_id,
|
| + unsigned modulus_length,
|
| + const std::vector<unsigned char>& public_exponent) {
|
| + DCHECK(algorithm_id == WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 ||
|
| + algorithm_id == WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 ||
|
| + algorithm_id == WebKit::WebCryptoAlgorithmIdRsaOaep);
|
| + return WebKit::WebCryptoAlgorithm::adoptParamsAndCreate(
|
| + algorithm_id,
|
| + new WebKit::WebCryptoRsaKeyGenParams(
|
| + modulus_length, Start(public_exponent), public_exponent.size()));
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace content {
|
| @@ -106,6 +119,13 @@ class WebCryptoImplTest : public testing::Test {
|
| return crypto_.GenerateKeyInternal(algorithm, handle, type);
|
| }
|
|
|
| + bool GenerateKeyPairInternal(
|
| + const WebKit::WebCryptoAlgorithm& algorithm,
|
| + scoped_ptr<WebKit::WebCryptoKeyHandle>* public_key,
|
| + scoped_ptr<WebKit::WebCryptoKeyHandle>* private_key) {
|
| + return crypto_.GenerateKeyPairInternal(algorithm, public_key, private_key);
|
| + }
|
| +
|
| bool ImportKeyInternal(
|
| WebKit::WebCryptoKeyFormat format,
|
| const std::vector<uint8>& key_data,
|
| @@ -669,6 +689,90 @@ TEST_F(WebCryptoImplTest, GenerateKeyHmacNoLength) {
|
| EXPECT_EQ(type, WebKit::WebCryptoKeyTypeSecret);
|
| }
|
|
|
| -#endif //#if !defined(USE_OPENSSL)
|
| +TEST_F(WebCryptoImplTest, GenerateKeyPairRsa) {
|
| +
|
| + // Note: using unrealistic short key lengths here to avoid bogging down tests.
|
| +
|
| + // happy WebCryptoAlgorithmIdRsaEsPkcs1v1_5 key gen
|
| + unsigned modulus_length = 256;
|
| + const unsigned char f4[3] = {0x01, 0x00, 0x01};
|
| + std::vector<unsigned char> public_exponent(&f4[0], &f4[0] + sizeof(f4));
|
| + WebKit::WebCryptoAlgorithm algorithm =
|
| + CreateRsaAlgorithm(WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
|
| + modulus_length,
|
| + public_exponent);
|
| + scoped_ptr<WebKit::WebCryptoKeyHandle> public_key_handle;
|
| + scoped_ptr<WebKit::WebCryptoKeyHandle> private_key_handle;
|
| + EXPECT_TRUE(GenerateKeyPairInternal(
|
| + algorithm, &public_key_handle, &private_key_handle));
|
| + EXPECT_TRUE(public_key_handle);
|
| + EXPECT_TRUE(private_key_handle);
|
| +
|
| + // bad modulus
|
| + modulus_length = 0;
|
| + algorithm = CreateRsaAlgorithm(WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
|
| + modulus_length,
|
| + public_exponent);
|
| + EXPECT_FALSE(GenerateKeyPairInternal(
|
| + algorithm, &public_key_handle, &private_key_handle));
|
| + modulus_length = 256; // restore modulus_length for next test
|
| +
|
| + // bad exponent, larger than unsigned long
|
| + unsigned exponent_length = sizeof(unsigned long) + 1;
|
| + const std::vector<unsigned char> long_exponent(exponent_length, 0x01);
|
| + algorithm = CreateRsaAlgorithm(WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
|
| + modulus_length,
|
| + long_exponent);
|
| + EXPECT_FALSE(GenerateKeyPairInternal(
|
| + algorithm, &public_key_handle, &private_key_handle));
|
| +
|
| + // bad exponent, empty
|
| + const std::vector<unsigned char> empty_exponent;
|
| + algorithm = CreateRsaAlgorithm(WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
|
| + modulus_length,
|
| + empty_exponent);
|
| + EXPECT_FALSE(GenerateKeyPairInternal(
|
| + algorithm, &public_key_handle, &private_key_handle));
|
| +
|
| + // bad exponent, all zeros
|
| + std::vector<unsigned char> exponent_with_leading_zeros(15, 0x00);
|
| + algorithm = CreateRsaAlgorithm(WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
|
| + modulus_length,
|
| + exponent_with_leading_zeros);
|
| + EXPECT_FALSE(GenerateKeyPairInternal(
|
| + algorithm, &public_key_handle, &private_key_handle));
|
| +
|
| + // good exponent with leading zeros
|
| + exponent_with_leading_zeros.insert(exponent_with_leading_zeros.end(),
|
| + public_exponent.begin(),
|
| + public_exponent.end());
|
| + algorithm = CreateRsaAlgorithm(WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
|
| + modulus_length,
|
| + exponent_with_leading_zeros);
|
| + EXPECT_TRUE(GenerateKeyPairInternal(
|
| + algorithm, &public_key_handle, &private_key_handle));
|
| + EXPECT_TRUE(public_key_handle);
|
| + EXPECT_TRUE(private_key_handle);
|
| +
|
| + // happy WebCryptoAlgorithmIdRsaOaep
|
| + algorithm = CreateRsaAlgorithm(WebKit::WebCryptoAlgorithmIdRsaOaep,
|
| + modulus_length,
|
| + public_exponent);
|
| + EXPECT_TRUE(GenerateKeyPairInternal(
|
| + algorithm, &public_key_handle, &private_key_handle));
|
| + EXPECT_TRUE(public_key_handle);
|
| + EXPECT_TRUE(private_key_handle);
|
| +
|
| + // happy WebCryptoAlgorithmIdRsaSsaPkcs1v1_5
|
| + algorithm = CreateRsaAlgorithm(WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
|
| + modulus_length,
|
| + public_exponent);
|
| + EXPECT_TRUE(GenerateKeyPairInternal(
|
| + algorithm, &public_key_handle, &private_key_handle));
|
| + EXPECT_TRUE(public_key_handle);
|
| + EXPECT_TRUE(private_key_handle);
|
| +}
|
| +
|
| +#endif // #if !defined(USE_OPENSSL)
|
|
|
| } // namespace content
|
|
|