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

Unified Diff: Source/modules/crypto/SubtleCrypto.cpp

Issue 21016005: WebCrypto: Add more operations to the platform API. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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 | « Source/modules/crypto/Key.h ('k') | Tools/DumpRenderTree/chromium/TestRunner/src/MockWebCrypto.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/SubtleCrypto.cpp
diff --git a/Source/modules/crypto/SubtleCrypto.cpp b/Source/modules/crypto/SubtleCrypto.cpp
index 84e0d868b0314332d7d63a5af6907075dd50b382..767f901298a252b2ae0d1ff288b49bad00708c04 100644
--- a/Source/modules/crypto/SubtleCrypto.cpp
+++ b/Source/modules/crypto/SubtleCrypto.cpp
@@ -49,8 +49,14 @@ namespace WebCore {
namespace {
-// FIXME: Temporary
-PassRefPtr<CryptoOperation> dummyOperation(const Dictionary& rawAlgorithm, AlgorithmOperation operationType, ExceptionState& es)
+bool keyCanBeUsedForAlgorithm(const WebKit::WebCryptoKey& key, const WebKit::WebCryptoAlgorithm& algorithm, ExceptionState& es)
+{
+ // FIXME: Need to enforce that the key's algorithm matches the operation,
+ // and that the key's usages allow it to be used with this operation.
+ return true;
+}
+
+PassRefPtr<CryptoOperation> createCryptoOperation(const Dictionary& rawAlgorithm, Key* key, AlgorithmOperation operationType, ExceptionState& es)
{
WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto();
if (!platformCrypto) {
@@ -62,9 +68,39 @@ PassRefPtr<CryptoOperation> dummyOperation(const Dictionary& rawAlgorithm, Algor
if (!normalizeAlgorithm(rawAlgorithm, operationType, algorithm, es))
return 0;
+ // All operations other than Digest require a valid Key.
+ if (operationType != Digest) {
+ if (!key) {
+ es.throwDOMException(TypeError);
+ return 0;
+ }
+
+ if (!keyCanBeUsedForAlgorithm(key->key(), algorithm, es)) {
+ return 0;
+ }
+ }
+
RefPtr<CryptoOperationImpl> opImpl = CryptoOperationImpl::create();
WebKit::WebCryptoOperationResult result(opImpl.get());
- platformCrypto->digest(algorithm, result);
+
+ switch (operationType) {
+ case Encrypt:
+ platformCrypto->encrypt(algorithm, key->key(), result);
+ break;
+ case Decrypt:
+ platformCrypto->decrypt(algorithm, key->key(), result);
+ break;
+ case Sign:
+ platformCrypto->sign(algorithm, key->key(), result);
+ break;
+ case Digest:
+ platformCrypto->digest(algorithm, result);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
+
if (opImpl->throwInitializationError(es))
return 0;
return CryptoOperation::create(algorithm, opImpl.get());
@@ -77,44 +113,30 @@ SubtleCrypto::SubtleCrypto()
ScriptWrappable::init(this);
}
-PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key*, ExceptionState& es)
+PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es)
{
- return dummyOperation(rawAlgorithm, Encrypt, es);
+ return createCryptoOperation(rawAlgorithm, key, Encrypt, es);
}
-PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm, Key*, ExceptionState& es)
+PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es)
{
- return dummyOperation(rawAlgorithm, Decrypt, es);
+ return createCryptoOperation(rawAlgorithm, key, Decrypt, es);
}
-PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, Key*, ExceptionState& es)
+PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es)
{
- return dummyOperation(rawAlgorithm, Sign, es);
+ return createCryptoOperation(rawAlgorithm, key, Sign, es);
}
-PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, Key*, ExceptionState& es)
+PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es)
{
- return dummyOperation(rawAlgorithm, Verify, es);
+ // FIXME
abarth-chromium 2013/07/31 00:59:59 Rather than an empty FIXME comment, you can call t
eroman 2013/07/31 01:23:16 Done.
+ return 0;
}
PassRefPtr<CryptoOperation> SubtleCrypto::digest(const Dictionary& rawAlgorithm, ExceptionState& es)
{
- WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto();
- if (!platformCrypto) {
- es.throwDOMException(NotSupportedError);
- return 0;
- }
-
- WebKit::WebCryptoAlgorithm algorithm;
- if (!normalizeAlgorithm(rawAlgorithm, Digest, algorithm, es))
- return 0;
-
- RefPtr<CryptoOperationImpl> opImpl = CryptoOperationImpl::create();
- WebKit::WebCryptoOperationResult result(opImpl.get());
- platformCrypto->digest(algorithm, result);
- if (opImpl->throwInitializationError(es))
- return 0;
- return CryptoOperation::create(algorithm, opImpl.get());
+ return createCryptoOperation(rawAlgorithm, 0, Digest, es);
}
ScriptObject SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView* keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages, ExceptionState& es)
« no previous file with comments | « Source/modules/crypto/Key.h ('k') | Tools/DumpRenderTree/chromium/TestRunner/src/MockWebCrypto.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698