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

Unified Diff: components/webcrypto/algorithms/aes.cc

Issue 2163053002: [webcrypto] Check for empty key usages *after* key creation rather than before, to match the spec's… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months 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 | « components/webcrypto/algorithms/aes.h ('k') | components/webcrypto/algorithms/asymmetric_key_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/webcrypto/algorithms/aes.cc
diff --git a/components/webcrypto/algorithms/aes.cc b/components/webcrypto/algorithms/aes.cc
index 7ba9a5095b9df12fb05ded38cab2670bf159b209..f46ea15a119bf502f399bbf4e3e9cc664db962a3 100644
--- a/components/webcrypto/algorithms/aes.cc
+++ b/components/webcrypto/algorithms/aes.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "components/webcrypto/algorithms/secret_key_util.h"
+#include "components/webcrypto/algorithms/util.h"
#include "components/webcrypto/blink_key_handle.h"
#include "components/webcrypto/crypto_data.h"
#include "components/webcrypto/jwk.h"
@@ -59,7 +60,7 @@ Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
GenerateKeyResult* result) const {
- Status status = CheckSecretKeyCreationUsages(all_key_usages_, usages);
+ Status status = CheckKeyCreationUsages(all_key_usages_, usages);
if (status.IsError())
return status;
@@ -77,23 +78,44 @@ Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
extractable, usages, keylen_bits, result);
}
-Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey(
- blink::WebCryptoKeyFormat format,
- blink::WebCryptoKeyUsageMask usages) const {
+Status AesAlgorithm::ImportKey(blink::WebCryptoKeyFormat format,
+ const CryptoData& key_data,
+ const blink::WebCryptoAlgorithm& algorithm,
+ bool extractable,
+ blink::WebCryptoKeyUsageMask usages,
+ blink::WebCryptoKey* key) const {
switch (format) {
case blink::WebCryptoKeyFormatRaw:
+ return ImportKeyRaw(key_data, algorithm, extractable, usages, key);
case blink::WebCryptoKeyFormatJwk:
- return CheckSecretKeyCreationUsages(all_key_usages_, usages);
+ return ImportKeyJwk(key_data, algorithm, extractable, usages, key);
default:
return Status::ErrorUnsupportedImportKeyFormat();
}
}
+Status AesAlgorithm::ExportKey(blink::WebCryptoKeyFormat format,
+ const blink::WebCryptoKey& key,
+ std::vector<uint8_t>* buffer) const {
+ switch (format) {
+ case blink::WebCryptoKeyFormatRaw:
+ return ExportKeyRaw(key, buffer);
+ case blink::WebCryptoKeyFormatJwk:
+ return ExportKeyJwk(key, buffer);
+ default:
+ return Status::ErrorUnsupportedExportKeyFormat();
+ }
+}
+
Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key) const {
+ Status status = CheckKeyCreationUsages(all_key_usages_, usages);
+ if (status.IsError())
+ return status;
+
const unsigned int keylen_bytes = key_data.byte_length();
// 192-bit AES is intentionally unsupported (http://crbug.com/533699).
@@ -117,10 +139,14 @@ Status AesAlgorithm::ImportKeyJwk(const CryptoData& key_data,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key) const {
+ Status status = CheckKeyCreationUsages(all_key_usages_, usages);
+ if (status.IsError())
+ return status;
+
std::vector<uint8_t> raw_data;
JwkReader jwk;
- Status status = ReadSecretKeyNoExpectedAlgJwk(key_data, extractable, usages,
- &raw_data, &jwk);
+ status = ReadSecretKeyNoExpectedAlgJwk(key_data, extractable, usages,
+ &raw_data, &jwk);
if (status.IsError())
return status;
« no previous file with comments | « components/webcrypto/algorithms/aes.h ('k') | components/webcrypto/algorithms/asymmetric_key_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698