Chromium Code Reviews| 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..f48141e095f6dc1631d486f76d5fda802c66640d 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) { |
|
eroman
2013/10/23 20:02:46
make this a const reference.
padolph
2013/10/23 23:21:47
Oops. Thanks for catching that.
|
| + 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,60 @@ 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)); |
| + |
| + // bad exponent |
| + modulus_length = 256; |
| + public_exponent.clear(); |
| + algorithm = CreateRsaAlgorithm(WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
| + modulus_length, |
| + public_exponent); |
| + EXPECT_FALSE(GenerateKeyPairInternal( |
| + algorithm, &public_key_handle, &private_key_handle)); |
| + |
| + // happy WebCryptoAlgorithmIdRsaOaep |
| + public_exponent.assign(&f4[0], &f4[0] + sizeof(f4)); |
| + 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); |
| +} |
|
eroman
2013/10/23 20:02:46
Can you add tests where:
* exponenent is larger t
padolph
2013/10/23 23:21:47
Done.
|
| + |
| +#endif // #if !defined(USE_OPENSSL) |
| } // namespace content |