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

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

Issue 778543004: Add sanity check to generateKey to make sure usages aren't empty (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/algorithm_dispatch.cc
diff --git a/content/child/webcrypto/algorithm_dispatch.cc b/content/child/webcrypto/algorithm_dispatch.cc
index 1c9b409ace58e4cf87aa1dfa7014a4e46bb6aec4..253dc311a4d4df5412d4bd7d2b29c5d0dbce92bc 100644
--- a/content/child/webcrypto/algorithm_dispatch.cc
+++ b/content/child/webcrypto/algorithm_dispatch.cc
@@ -8,6 +8,7 @@
#include "content/child/webcrypto/algorithm_implementation.h"
#include "content/child/webcrypto/algorithm_registry.h"
#include "content/child/webcrypto/crypto_data.h"
+#include "content/child/webcrypto/generate_key_result.h"
#include "content/child/webcrypto/platform_crypto.h"
#include "content/child/webcrypto/status.h"
#include "content/child/webcrypto/webcrypto_util.h"
@@ -111,7 +112,25 @@ Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
if (status.IsError())
return status;
- return impl->GenerateKey(algorithm, extractable, usages, result);
+ status = impl->GenerateKey(algorithm, extractable, usages, result);
+ if (status.IsError())
+ return status;
+
+ const blink::WebCryptoKey* key = NULL;
+ if (result->type() == GenerateKeyResult::TYPE_SECRET_KEY)
+ key = &result->secret_key();
+ if (result->type() == GenerateKeyResult::TYPE_PUBLIC_PRIVATE_KEY_PAIR)
+ key = &result->private_key();
+ if (key == NULL)
+ return Status::ErrorUnexpected();
+
+ // This should only fail if an algorithm is implemented incorrectly and
+ // does not do its own check of the usages.
+ if (key->usages() == 0) {
+ DCHECK(false) << "Key usages for generateKey() must not be empty";
+ return Status::ErrorCreateKeyEmptyUsages();
+ }
+ return status;
}
Status ImportKey(blink::WebCryptoKeyFormat format,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698