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

Unified Diff: components/webcrypto/algorithms/ec.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/ec.h ('k') | components/webcrypto/algorithms/hkdf.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/webcrypto/algorithms/ec.cc
diff --git a/components/webcrypto/algorithms/ec.cc b/components/webcrypto/algorithms/ec.cc
index 09b9ae408c9da802549e4ae5d9440732fc8bfb8a..9aa9bfeced7760270c3f88bf2479ccf0ee48043c 100644
--- a/components/webcrypto/algorithms/ec.cc
+++ b/components/webcrypto/algorithms/ec.cc
@@ -290,11 +290,37 @@ Status EcAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
return Status::Success();
}
-Status EcAlgorithm::VerifyKeyUsagesBeforeImportKey(
- blink::WebCryptoKeyFormat format,
- blink::WebCryptoKeyUsageMask usages) const {
- return VerifyUsagesBeforeImportAsymmetricKey(format, all_public_key_usages_,
- all_private_key_usages_, usages);
+Status EcAlgorithm::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::WebCryptoKeyFormatPkcs8:
+ return ImportKeyPkcs8(key_data, algorithm, extractable, usages, key);
+ case blink::WebCryptoKeyFormatSpki:
+ return ImportKeySpki(key_data, algorithm, extractable, usages, key);
+ case blink::WebCryptoKeyFormatJwk:
+ return ImportKeyJwk(key_data, algorithm, extractable, usages, key);
+ default:
+ return Status::ErrorUnsupportedImportKeyFormat();
+ }
+}
+
+Status EcAlgorithm::ExportKey(blink::WebCryptoKeyFormat format,
+ const blink::WebCryptoKey& key,
+ std::vector<uint8_t>* buffer) const {
+ switch (format) {
+ case blink::WebCryptoKeyFormatPkcs8:
+ return ExportKeyPkcs8(key, buffer);
+ case blink::WebCryptoKeyFormatSpki:
+ return ExportKeySpki(key, buffer);
+ case blink::WebCryptoKeyFormatJwk:
+ return ExportKeyJwk(key, buffer);
+ default:
+ return Status::ErrorUnsupportedExportKeyFormat();
+ }
}
Status EcAlgorithm::ImportKeyPkcs8(const CryptoData& key_data,
@@ -302,9 +328,12 @@ Status EcAlgorithm::ImportKeyPkcs8(const CryptoData& key_data,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key) const {
+ Status status = CheckKeyCreationUsages(all_private_key_usages_, usages);
+ if (status.IsError())
+ return status;
+
crypto::ScopedEVP_PKEY private_key;
- Status status =
- ImportUnverifiedPkeyFromPkcs8(key_data, EVP_PKEY_EC, &private_key);
+ status = ImportUnverifiedPkeyFromPkcs8(key_data, EVP_PKEY_EC, &private_key);
if (status.IsError())
return status;
@@ -327,9 +356,12 @@ Status EcAlgorithm::ImportKeySpki(const CryptoData& key_data,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key) const {
+ Status status = CheckKeyCreationUsages(all_public_key_usages_, usages);
+ if (status.IsError())
+ return status;
+
crypto::ScopedEVP_PKEY public_key;
- Status status =
- ImportUnverifiedPkeyFromSpki(key_data, EVP_PKEY_EC, &public_key);
+ status = ImportUnverifiedPkeyFromSpki(key_data, EVP_PKEY_EC, &public_key);
if (status.IsError())
return status;
@@ -388,9 +420,9 @@ Status EcAlgorithm::ImportKeyJwk(const CryptoData& key_data,
// Now that the key type is known, verify the usages.
if (is_private_key) {
- status = CheckPrivateKeyCreationUsages(all_private_key_usages_, usages);
+ status = CheckKeyCreationUsages(all_private_key_usages_, usages);
} else {
- status = CheckPublicKeyCreationUsages(all_public_key_usages_, usages);
+ status = CheckKeyCreationUsages(all_public_key_usages_, usages);
}
if (status.IsError())
« no previous file with comments | « components/webcrypto/algorithms/ec.h ('k') | components/webcrypto/algorithms/hkdf.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698