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

Unified Diff: content/child/webcrypto/webcrypto_util.cc

Issue 777403004: [WebCrypto] Throw syntaxError if keyUsage is empty in ImportKey (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated issues in ecdh tests and other review comments. Created 6 years 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
Index: content/child/webcrypto/webcrypto_util.cc
diff --git a/content/child/webcrypto/webcrypto_util.cc b/content/child/webcrypto/webcrypto_util.cc
index 5df16330b7cec68a5b53dc2a7f6f72f277e14145..534aa743f592c6f3a9c81f90e799635d0556712d 100644
--- a/content/child/webcrypto/webcrypto_util.cc
+++ b/content/child/webcrypto/webcrypto_util.cc
@@ -271,7 +271,11 @@ Status VerifyAesKeyLengthForImport(unsigned int keylen_bytes) {
}
Status CheckKeyCreationUsages(blink::WebCryptoKeyUsageMask all_possible_usages,
- blink::WebCryptoKeyUsageMask actual_usages) {
+ blink::WebCryptoKeyUsageMask actual_usages,
+ bool allow_empty_usages) {
+ if (!allow_empty_usages && actual_usages == 0)
+ return Status::ErrorCreateKeyEmptyUsages();
+
if (!ContainsKeyUsages(all_possible_usages, actual_usages))
return Status::ErrorCreateKeyBadUsages();
return Status::Success();
@@ -311,15 +315,17 @@ Status VerifyUsagesBeforeImportAsymmetricKey(
blink::WebCryptoKeyUsageMask usages) {
switch (format) {
case blink::WebCryptoKeyFormatSpki:
- return CheckKeyCreationUsages(all_public_key_usages, usages);
+ return CheckKeyCreationUsages(all_public_key_usages, usages, true);
case blink::WebCryptoKeyFormatPkcs8:
- return CheckKeyCreationUsages(all_private_key_usages, usages);
+ return CheckKeyCreationUsages(all_private_key_usages, usages, false);
case blink::WebCryptoKeyFormatJwk: {
// The JWK could represent either a public key or private key. The usages
// must make sense for one of the two. The usages will be checked again by
// ImportKeyJwk() once the key type has been determined.
- if (CheckKeyCreationUsages(all_public_key_usages, usages).IsError() &&
- CheckKeyCreationUsages(all_private_key_usages, usages).IsError()) {
+ if (CheckKeyCreationUsages(
+ all_public_key_usages, usages, true).IsError() &&
+ CheckKeyCreationUsages(
+ all_private_key_usages, usages, false).IsError()) {
return Status::ErrorCreateKeyBadUsages();
}
return Status::Success();
@@ -388,7 +394,7 @@ Status GetUsagesForGenerateAsymmetricKey(
blink::WebCryptoKeyUsageMask* public_usages,
blink::WebCryptoKeyUsageMask* private_usages) {
Status status = CheckKeyCreationUsages(all_public_usages | all_private_usages,
- combined_usages);
+ combined_usages, true);
if (status.IsError())
return status;

Powered by Google App Engine
This is Rietveld 408576698