Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1641)

Unified Diff: content/child/webcrypto/test/rsa_ssa_unittest.cc

Issue 751883002: Revert of Check that usage isn't empty when generateKey() is called (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/child/webcrypto/test/hmac_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/test/rsa_ssa_unittest.cc
diff --git a/content/child/webcrypto/test/rsa_ssa_unittest.cc b/content/child/webcrypto/test/rsa_ssa_unittest.cc
index fed06879974cfec5d9d878bd6e68ac60dda2a7bf..b4ba71660eb91cec92a023d45fade141c0531681 100644
--- a/content/child/webcrypto/test/rsa_ssa_unittest.cc
+++ b/content/child/webcrypto/test/rsa_ssa_unittest.cc
@@ -344,18 +344,15 @@
modulus_length,
public_exponent);
bool extractable = true;
- const blink::WebCryptoKeyUsageMask public_usages =
- blink::WebCryptoKeyUsageVerify;
- const blink::WebCryptoKeyUsageMask private_usages =
- blink::WebCryptoKeyUsageSign;
- const blink::WebCryptoKeyUsageMask usages = public_usages | private_usages;
+ const blink::WebCryptoKeyUsageMask usages = 0;
blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key;
- EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, extractable, usages,
- &public_key, &private_key));
- ASSERT_FALSE(public_key.isNull());
- ASSERT_FALSE(private_key.isNull());
+ EXPECT_EQ(Status::Success(),
+ GenerateKeyPair(
+ algorithm, extractable, usages, &public_key, &private_key));
+ EXPECT_FALSE(public_key.isNull());
+ EXPECT_FALSE(private_key.isNull());
EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type());
EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type());
EXPECT_EQ(modulus_length,
@@ -368,8 +365,8 @@
private_key.algorithm().rsaHashedParams()->hash().id());
EXPECT_TRUE(public_key.extractable());
EXPECT_EQ(extractable, private_key.extractable());
- EXPECT_EQ(public_usages, public_key.usages());
- EXPECT_EQ(private_usages, private_key.usages());
+ EXPECT_EQ(usages, public_key.usages());
+ EXPECT_EQ(usages, private_key.usages());
// Try exporting the generated key pair, and then re-importing to verify that
// the exported data was valid.
@@ -380,13 +377,15 @@
if (SupportsRsaPrivateKeyImport()) {
public_key = blink::WebCryptoKey::createNull();
- ASSERT_EQ(
- Status::Success(),
- ImportKey(blink::WebCryptoKeyFormatSpki, CryptoData(public_key_spki),
- CreateRsaHashedImportAlgorithm(
- blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
- blink::WebCryptoAlgorithmIdSha256),
- true, public_usages, &public_key));
+ EXPECT_EQ(Status::Success(),
+ ImportKey(blink::WebCryptoKeyFormatSpki,
+ CryptoData(public_key_spki),
+ CreateRsaHashedImportAlgorithm(
+ blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
+ blink::WebCryptoAlgorithmIdSha256),
+ true,
+ usages,
+ &public_key));
EXPECT_EQ(modulus_length,
public_key.algorithm().rsaHashedParams()->modulusLengthBits());
@@ -396,13 +395,15 @@
ExportKey(
blink::WebCryptoKeyFormatPkcs8, private_key, &private_key_pkcs8));
private_key = blink::WebCryptoKey::createNull();
- ASSERT_EQ(
- Status::Success(),
- ImportKey(blink::WebCryptoKeyFormatPkcs8, CryptoData(private_key_pkcs8),
- CreateRsaHashedImportAlgorithm(
- blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
- blink::WebCryptoAlgorithmIdSha256),
- true, private_usages, &private_key));
+ EXPECT_EQ(Status::Success(),
+ ImportKey(blink::WebCryptoKeyFormatPkcs8,
+ CryptoData(private_key_pkcs8),
+ CreateRsaHashedImportAlgorithm(
+ blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
+ blink::WebCryptoAlgorithmIdSha256),
+ true,
+ usages,
+ &private_key));
EXPECT_EQ(modulus_length,
private_key.algorithm().rsaHashedParams()->modulusLengthBits());
}
@@ -460,16 +461,17 @@
blink::WebCryptoAlgorithmIdSha256,
modulus_length,
exponent_with_leading_zeros);
- EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, extractable, usages,
- &public_key, &private_key));
+ EXPECT_EQ(Status::Success(),
+ GenerateKeyPair(
+ algorithm, extractable, usages, &public_key, &private_key));
EXPECT_FALSE(public_key.isNull());
EXPECT_FALSE(private_key.isNull());
EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type());
EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type());
EXPECT_TRUE(public_key.extractable());
EXPECT_EQ(extractable, private_key.extractable());
- EXPECT_EQ(public_usages, public_key.usages());
- EXPECT_EQ(private_usages, private_key.usages());
+ EXPECT_EQ(usages, public_key.usages());
+ EXPECT_EQ(usages, private_key.usages());
// Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation (sha1)
algorithm =
@@ -496,8 +498,8 @@
// extractable.
EXPECT_TRUE(public_key.extractable());
EXPECT_FALSE(private_key.extractable());
- EXPECT_EQ(public_usages, public_key.usages());
- EXPECT_EQ(private_usages, private_key.usages());
+ EXPECT_EQ(usages, public_key.usages());
+ EXPECT_EQ(usages, private_key.usages());
// Exporting a private key as SPKI format doesn't make sense. However this
// will first fail because the key is not extractable.
@@ -507,8 +509,9 @@
// Re-generate an extractable private_key and try to export it as SPKI format.
// This should fail since spki is for public keys.
- EXPECT_EQ(Status::Success(), GenerateKeyPair(algorithm, true, usages,
- &public_key, &private_key));
+ EXPECT_EQ(
+ Status::Success(),
+ GenerateKeyPair(algorithm, true, usages, &public_key, &private_key));
EXPECT_EQ(Status::ErrorUnexpectedKeyType(),
ExportKey(blink::WebCryptoKeyFormatSpki, private_key, &output));
}
@@ -533,7 +536,7 @@
modulus_length_bits,
public_exponent);
bool extractable = true;
- const blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign;
+ const blink::WebCryptoKeyUsageMask usages = 0;
blink::WebCryptoKey public_key;
blink::WebCryptoKey private_key;
@@ -568,8 +571,7 @@
blink::WebCryptoKey private_key;
EXPECT_EQ(Status::ErrorGenerateKeyPublicExponent(),
- GenerateKeyPair(algorithm, true, blink::WebCryptoKeyUsageSign,
- &public_key, &private_key));
+ GenerateKeyPair(algorithm, true, 0, &public_key, &private_key));
}
}
@@ -890,21 +892,6 @@
EXPECT_EQ(blink::WebCryptoKeyUsageSign, private_key.usages());
}
-TEST(WebCryptoRsaSsaTest, GenerateKeyPairEmptyUsages) {
- const unsigned int modulus_length = 256;
- const std::vector<uint8_t> public_exponent = HexStringToBytes("010001");
-
- blink::WebCryptoKey public_key;
- blink::WebCryptoKey private_key;
-
- ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(),
- GenerateKeyPair(CreateRsaHashedKeyGenAlgorithm(
- blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
- blink::WebCryptoAlgorithmIdSha256,
- modulus_length, public_exponent),
- true, 0, &public_key, &private_key));
-}
-
TEST(WebCryptoRsaSsaTest, ImportExportJwkRsaPublicKey) {
struct TestCase {
const blink::WebCryptoAlgorithmId hash;
@@ -1064,15 +1051,12 @@
std::string test_error;
ASSERT_TRUE(test->GetString("error", &test_error));
- blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign;
- if (key_format == blink::WebCryptoKeyFormatSpki)
- usages = blink::WebCryptoKeyUsageVerify;
blink::WebCryptoKey key;
Status status = ImportKey(key_format, CryptoData(key_data),
CreateRsaHashedImportAlgorithm(
blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
blink::WebCryptoAlgorithmIdSha256),
- true, usages, &key);
+ true, 0, &key);
EXPECT_EQ(test_error, StatusToString(status));
}
}
« no previous file with comments | « content/child/webcrypto/test/hmac_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698