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

Unified Diff: content/renderer/webcrypto/webcrypto_impl.cc

Issue 34583010: [webcrypto] Add RSA key generation using NSS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: re-upload after 500 server failure Created 7 years, 2 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
Index: content/renderer/webcrypto/webcrypto_impl.cc
diff --git a/content/renderer/webcrypto/webcrypto_impl.cc b/content/renderer/webcrypto/webcrypto_impl.cc
index f2510100eb755c3f7d4b7929c6227a4bb7571a67..7c56252fad0647937d59910cc3230f06b64127d5 100644
--- a/content/renderer/webcrypto/webcrypto_impl.cc
+++ b/content/renderer/webcrypto/webcrypto_impl.cc
@@ -12,6 +12,19 @@
namespace content {
+namespace {
+
+bool IsAlgorithmAsymmetric(const WebKit::WebCryptoAlgorithm& algorithm) {
+ const WebKit::WebCryptoAlgorithmId algorithm_id = algorithm.id();
+ // TODO: include all other asymmetric algorithms once they are defined,
eroman 2013/10/23 20:02:46 nit: use the format TODO(padolph): This doesn't m
padolph 2013/10/23 23:21:47 Done.
+ // e.g. EC and DH.
+ return (algorithm_id == WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 ||
+ algorithm_id == WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 ||
+ algorithm_id == WebKit::WebCryptoAlgorithmIdRsaOaep);
+}
+
+} // namespace
+
WebCryptoImpl::WebCryptoImpl() {
Init();
}
@@ -80,15 +93,40 @@ void WebCryptoImpl::generateKey(
bool exportable,
WebKit::WebCryptoKeyUsageMask usage,
WebKit::WebCryptoResult result) {
- scoped_ptr<WebKit::WebCryptoKeyHandle> handle;
- WebKit::WebCryptoKeyType type;
- if (!GenerateKeyInternal(algorithm, &handle, &type)) {
- result.completeWithError();
- } else {
- WebKit::WebCryptoKey key(
- WebKit::WebCryptoKey::create(handle.release(), type, exportable,
- algorithm, usage));
- result.completeWithKey(key);
+ if (IsAlgorithmAsymmetric(algorithm)) {
+ scoped_ptr<WebKit::WebCryptoKeyHandle> public_key_handle;
+ scoped_ptr<WebKit::WebCryptoKeyHandle> private_key_handle;
+ if (!GenerateKeyPairInternal(algorithm,
+ &public_key_handle,
+ &private_key_handle)) {
+ result.completeWithError();
eroman 2013/10/23 20:02:46 I think the structure of this function would be mo
padolph 2013/10/23 23:21:47 Agreed for the error cases. But do you also want t
+ } else {
+ WebKit::WebCryptoKey public_key(
+ WebKit::WebCryptoKey::create(public_key_handle.release(),
+ WebKit::WebCryptoKeyTypePublic,
+ exportable,
+ algorithm,
+ usage));
+ WebKit::WebCryptoKey private_key(
+ WebKit::WebCryptoKey::create(private_key_handle.release(),
+ WebKit::WebCryptoKeyTypePrivate,
+ exportable,
+ algorithm,
+ usage));
+ result.completeWithKeyPair(public_key, private_key);
+ }
+ }
+ else {
+ scoped_ptr<WebKit::WebCryptoKeyHandle> handle;
+ WebKit::WebCryptoKeyType type;
+ if (!GenerateKeyInternal(algorithm, &handle, &type)) {
+ result.completeWithError();
+ } else {
+ WebKit::WebCryptoKey key(
+ WebKit::WebCryptoKey::create(handle.release(), type, exportable,
+ algorithm, usage));
+ result.completeWithKey(key);
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698