Diff
Modified: trunk/Source/WebCore/ChangeLog (221180 => 221181)
--- trunk/Source/WebCore/ChangeLog 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/ChangeLog 2017-08-25 07:20:34 UTC (rev 221181)
@@ -1,3 +1,79 @@
+2017-08-25 Zan Dobersek <zdober...@igalia.com>
+
+ [WebCrypto] Push WorkQueue dispatches for RSA algorithms into shared code
+ https://bugs.webkit.org/show_bug.cgi?id=175621
+
+ Reviewed by Darin Adler.
+
+ Push the WorkQueue dispatch code and other code duplicated between the
+ Mac and libgcrypt implementations of Web Crypto into the shared layer.
+ This patch focuses on the RSA-based algorithms.
+
+ The WorkQueue dispatch code is condensed into two static functions on
+ the CryptoAlgorithm class, the first variation handling VectorCallback
+ as the callback type and the other handling BoolCallback. The operation
+ is kept in a WTF::Function<> object that returns an ExceptionOr<> value
+ embedding either a Vector<uint8_t> object or a boolean value, as
+ appropriate for the callback type.
+
+ Functions with platform-specific implementations that are invoked from
+ these asynchronous dispatches are made static and return an ExceptionOr
+ value. CryptoAlgorithmParameters objects are passed through non-const
+ references because data getters could lazily construct the underlying
+ Vector objects. CryptoKey objects are passed through const references.
+ Implementations can then manually retrieve and further validate any key
+ or parameter data, as required for that specific implementation. Input
+ data is passed through const references to the original Vector objects.
+
+ No new tests -- no changes in behavior that's covered by existing tests.
+
+ * crypto/CryptoAlgorithm.cpp:
+ (WebCore::dispatchOperationImpl):
+ (WebCore::CryptoAlgorithm::dispatchOperation):
+ * crypto/CryptoAlgorithm.h:
+ * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
+ (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt):
+ (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt):
+ * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h:
+ * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
+ (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
+ (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
+ * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
+ * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
+ (WebCore::CryptoAlgorithmRSA_OAEP::encrypt):
+ (WebCore::CryptoAlgorithmRSA_OAEP::decrypt):
+ * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
+ * crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp:
+ (WebCore::CryptoAlgorithmRSA_PSS::sign):
+ (WebCore::CryptoAlgorithmRSA_PSS::verify):
+ * crypto/algorithms/CryptoAlgorithmRSA_PSS.h:
+ * crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp:
+ (WebCore::gcryptEncrypt):
+ (WebCore::gcryptDecrypt):
+ (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
+ (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
+ * crypto/gcrypt/CryptoAlgorithmRSASSA_PKCS1_v1_5GCrypt.cpp:
+ (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):
+ (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify):
+ * crypto/gcrypt/CryptoAlgorithmRSA_OAEPGCrypt.cpp:
+ (WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt):
+ (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):
+ * crypto/gcrypt/CryptoAlgorithmRSA_PSSGCrypt.cpp:
+ (WebCore::CryptoAlgorithmRSA_PSS::platformSign):
+ (WebCore::CryptoAlgorithmRSA_PSS::platformVerify):
+ * crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp:
+ (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
+ (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
+ * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
+ (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):
+ (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify):
+ * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp:
+ (WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt):
+ (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):
+ * crypto/mac/CryptoAlgorithmRSA_PSSMac.cpp:
+ (WebCore::CryptoAlgorithmRSA_PSS::platformSign):
+ (WebCore::CryptoAlgorithmRSA_PSS::platformVerify):
+
2017-08-24 Chris Dumez <cdu...@apple.com>
Unreviewed, add File and Directory Entries API to status page.
Modified: trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -28,6 +28,8 @@
#if ENABLE(SUBTLE_CRYPTO)
+#include "ScriptExecutionContext.h"
+
namespace WebCore {
void CryptoAlgorithm::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
@@ -90,6 +92,42 @@
return Exception { NotSupportedError };
}
+template<typename ResultCallbackType, typename OperationType>
+static void dispatchAlgorithmOperation(WorkQueue& workQueue, ScriptExecutionContext& context, ResultCallbackType&& callback, CryptoAlgorithm::ExceptionCallback&& exceptionCallback, OperationType&& operation)
+{
+ context.ref();
+ workQueue.dispatch(
+ [operation = WTFMove(operation), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
+ auto result = operation();
+ if (result.hasException()) {
+ // We should only dereference callbacks after being back to the Document/Worker threads.
+ context.postTask(
+ [ec = result.releaseException().code(), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
+ exceptionCallback(ec);
+ context.deref();
+ });
+ return;
+ }
+
+ // We should only dereference callbacks after being back to the Document/Worker threads.
+ context.postTask(
+ [result = result.releaseReturnValue(), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
+ callback(result);
+ context.deref();
+ });
+ });
}
+void CryptoAlgorithm::dispatchOperation(WorkQueue& workQueue, ScriptExecutionContext& context, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, WTF::Function<ExceptionOr<Vector<uint8_t>>()>&& operation)
+{
+ dispatchAlgorithmOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback), WTFMove(operation));
+}
+
+void CryptoAlgorithm::dispatchOperation(WorkQueue& workQueue, ScriptExecutionContext& context, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, WTF::Function<ExceptionOr<bool>()>&& operation)
+{
+ dispatchAlgorithmOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback), WTFMove(operation));
+}
+
+}
+
#endif
Modified: trunk/Source/WebCore/crypto/CryptoAlgorithm.h (221180 => 221181)
--- trunk/Source/WebCore/crypto/CryptoAlgorithm.h 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithm.h 2017-08-25 07:20:34 UTC (rev 221181)
@@ -76,6 +76,9 @@
virtual void wrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&);
virtual void unwrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&);
virtual ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&);
+
+ static void dispatchOperation(WorkQueue&, ScriptExecutionContext&, VectorCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<Vector<uint8_t>>()>&&);
+ static void dispatchOperation(WorkQueue&, ScriptExecutionContext&, BoolCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<bool>()>&&);
};
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -53,7 +53,11 @@
exceptionCallback(InvalidAccessError);
return;
}
- platformEncrypt(WTFMove(key), WTFMove(plainText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+ dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+ [key = WTFMove(key), plainText = WTFMove(plainText)] {
+ return platformEncrypt(key, plainText);
+ });
}
void CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
@@ -62,7 +66,11 @@
exceptionCallback(InvalidAccessError);
return;
}
- platformDecrypt(WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+ dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+ [key = WTFMove(key), cipherText = WTFMove(cipherText)] {
+ return platformDecrypt(key, cipherText);
+ });
}
void CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h (221180 => 221181)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h 2017-08-25 07:20:34 UTC (rev 221181)
@@ -50,8 +50,8 @@
void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
- void platformEncrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
- void platformDecrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+ static ExceptionOr<Vector<uint8_t>> platformEncrypt(const CryptoKey&, const Vector<uint8_t>&);
+ static ExceptionOr<Vector<uint8_t>> platformDecrypt(const CryptoKey&, const Vector<uint8_t>&);
};
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -58,7 +58,11 @@
exceptionCallback(InvalidAccessError);
return;
}
- platformSign(WTFMove(key), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+ dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+ [key = WTFMove(key), data = "" {
+ return platformSign(key, data);
+ });
}
void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
@@ -67,7 +71,11 @@
exceptionCallback(InvalidAccessError);
return;
}
- platformVerify(WTFMove(key), WTFMove(signature), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+ dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+ [key = WTFMove(key), signature = WTFMove(signature), data = "" {
+ return platformVerify(key, signature, data);
+ });
}
void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h (221180 => 221181)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h 2017-08-25 07:20:34 UTC (rev 221181)
@@ -49,8 +49,8 @@
void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
- void platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
- void platformVerify(Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+ static ExceptionOr<Vector<uint8_t>> platformSign(const CryptoKey&, const Vector<uint8_t>&);
+ static ExceptionOr<bool> platformVerify(const CryptoKey&, const Vector<uint8_t>&, const Vector<uint8_t>&);
};
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -59,7 +59,11 @@
exceptionCallback(InvalidAccessError);
return;
}
- platformEncrypt(WTFMove(parameters), WTFMove(key), WTFMove(plainText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+ dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+ [parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
+ return platformEncrypt(*parameters, key, plainText);
+ });
}
void CryptoAlgorithmRSA_OAEP::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
@@ -69,7 +73,11 @@
exceptionCallback(InvalidAccessError);
return;
}
- platformDecrypt(WTFMove(parameters), WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+ dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+ [parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
+ return platformDecrypt(*parameters, key, cipherText);
+ });
}
void CryptoAlgorithmRSA_OAEP::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h (221180 => 221181)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h 2017-08-25 07:20:34 UTC (rev 221181)
@@ -49,8 +49,8 @@
void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
- void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
- void platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+ static ExceptionOr<Vector<uint8_t>> platformEncrypt(CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&);
+ static ExceptionOr<Vector<uint8_t>> platformDecrypt(CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&);
};
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -58,7 +58,11 @@
exceptionCallback(InvalidAccessError);
return;
}
- platformSign(WTFMove(parameters), WTFMove(key), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+ dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+ [parameters = WTFMove(parameters), key = WTFMove(key), data = "" {
+ return platformSign(*parameters, key, data);
+ });
}
void CryptoAlgorithmRSA_PSS::verify(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
@@ -67,7 +71,11 @@
exceptionCallback(InvalidAccessError);
return;
}
- platformVerify(WTFMove(parameters), WTFMove(key), WTFMove(signature), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+ dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+ [parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = "" {
+ return platformVerify(*parameters, key, signature, data);
+ });
}
void CryptoAlgorithmRSA_PSS::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context)
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.h (221180 => 221181)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.h 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.h 2017-08-25 07:20:34 UTC (rev 221181)
@@ -49,8 +49,8 @@
void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
- void platformSign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
- void platformVerify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+ static ExceptionOr<Vector<uint8_t>> platformSign(CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&);
+ static ExceptionOr<bool> platformVerify(CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&, const Vector<uint8_t>&);
};
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -30,11 +30,10 @@
#include "CryptoKeyRSA.h"
#include "GCryptUtilities.h"
-#include "ScriptExecutionContext.h"
namespace WebCore {
-static std::optional<Vector<uint8_t>> gcryptEncrypt(gcry_sexp_t keySexp, Vector<uint8_t>&& plainText)
+static std::optional<Vector<uint8_t>> gcryptEncrypt(gcry_sexp_t keySexp, const Vector<uint8_t>& plainText)
{
// Embed the plain-text data in a `data` s-_expression_ using PKCS#1 padding.
PAL::GCrypt::Handle<gcry_sexp_t> dataSexp;
@@ -64,7 +63,7 @@
return mpiData(aSexp);
}
-static std::optional<Vector<uint8_t>> gcryptDecrypt(gcry_sexp_t keySexp, Vector<uint8_t>&& cipherText)
+static std::optional<Vector<uint8_t>> gcryptDecrypt(gcry_sexp_t keySexp, const Vector<uint8_t>& cipherText)
{
// Embed the cipher-text data in an `enc-val` s-_expression_ using PKCS#1 padding.
PAL::GCrypt::Handle<gcry_sexp_t> encValSexp;
@@ -94,58 +93,20 @@
return mpiData(valueSexp);
}
-void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKey& key, const Vector<uint8_t>& plainText)
{
- context.ref();
- workQueue.dispatch(
- [key = WTFMove(key), plainText = WTFMove(plainText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
-
- auto output = gcryptEncrypt(rsaKey.platformKey(), WTFMove(plainText));
- if (!output) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- exceptionCallback(OperationError);
- context.deref();
- });
- return;
- }
-
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) mutable {
- callback(WTFMove(output));
- context.deref();
- });
- });
+ auto output = gcryptEncrypt(downcast<CryptoKeyRSA>(key).platformKey(), plainText);
+ if (!output)
+ return Exception { OperationError };
+ return WTFMove(*output);
}
-void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKey& key, const Vector<uint8_t>& cipherText)
{
- context.ref();
- workQueue.dispatch(
- [key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
-
- auto output = gcryptDecrypt(rsaKey.platformKey(), WTFMove(cipherText));
- if (!output) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- exceptionCallback(OperationError);
- context.deref();
- });
- return;
- }
-
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) mutable {
- callback(WTFMove(output));
- context.deref();
- });
- });
+ auto output = gcryptDecrypt(downcast<CryptoKeyRSA>(key).platformKey(), cipherText);
+ if (!output)
+ return Exception { OperationError };
+ return WTFMove(*output);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSASSA_PKCS1_v1_5GCrypt.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSASSA_PKCS1_v1_5GCrypt.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSASSA_PKCS1_v1_5GCrypt.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -32,7 +32,6 @@
#include "CryptoKeyRSA.h"
#include "GCryptUtilities.h"
#include "NotImplemented.h"
-#include "ScriptExecutionContext.h"
namespace WebCore {
@@ -135,58 +134,22 @@
return { error == GPG_ERR_NO_ERROR };
}
-void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoKey& key, const Vector<uint8_t>& data)
{
- context.ref();
- workQueue.dispatch(
- [key = WTFMove(key), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
-
- auto output = gcryptSign(rsaKey.platformKey(), data, rsaKey.hashAlgorithmIdentifier());
- if (!output) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- exceptionCallback(OperationError);
- context.deref();
- });
- return;
- }
-
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(output);
- context.deref();
- });
- });
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ auto output = gcryptSign(rsaKey.platformKey(), data, rsaKey.hashAlgorithmIdentifier());
+ if (!output)
+ return Exception { OperationError };
+ return WTFMove(*output);
}
-void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<bool> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
{
- context.ref();
- workQueue.dispatch(
- [key = WTFMove(key), signature = WTFMove(signature), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
-
- auto output = gcryptVerify(rsaKey.platformKey(), signature, data, rsaKey.hashAlgorithmIdentifier());
- if (!output) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- exceptionCallback(OperationError);
- context.deref();
- });
- return;
- }
-
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(output);
- context.deref();
- });
- });
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ auto output = gcryptVerify(rsaKey.platformKey(), signature, data, rsaKey.hashAlgorithmIdentifier());
+ if (!output)
+ return Exception { OperationError };
+ return *output;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_OAEPGCrypt.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_OAEPGCrypt.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_OAEPGCrypt.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -32,7 +32,6 @@
#include "CryptoKeyRSA.h"
#include "GCryptUtilities.h"
#include "NotImplemented.h"
-#include "ScriptExecutionContext.h"
namespace WebCore {
@@ -111,60 +110,26 @@
return mpiData(valueSexp);
}
-void CryptoAlgorithmRSA_OAEP::platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& plainText)
{
- context.ref();
- workQueue.dispatch(
- [parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
+ auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(parameters);
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
- auto output = gcryptEncrypt(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaParameters.labelVector(), plainText);
- if (!output) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- exceptionCallback(OperationError);
- context.deref();
- });
- return;
- }
-
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(output);
- context.deref();
- });
- });
+ auto output = gcryptEncrypt(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaParameters.labelVector(), plainText);
+ if (!output)
+ return Exception { OperationError };
+ return WTFMove(*output);
}
-void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& cipherText)
{
- context.ref();
- workQueue.dispatch(
- [parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
+ auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(parameters);
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
- auto output = gcryptDecrypt(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaParameters.labelVector(), cipherText);
- if (!output) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- exceptionCallback(OperationError);
- context.deref();
- });
- return;
- }
-
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(output);
- context.deref();
- });
- });
+ auto output = gcryptDecrypt(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaParameters.labelVector(), cipherText);
+ if (!output)
+ return Exception { OperationError };
+ return WTFMove(*output);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_PSSGCrypt.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_PSSGCrypt.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_PSSGCrypt.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -33,7 +33,6 @@
#include "CryptoAlgorithmRsaPssParams.h"
#include "CryptoKeyRSA.h"
#include "GCryptUtilities.h"
-#include "ScriptExecutionContext.h"
namespace WebCore {
@@ -141,60 +140,26 @@
return { error == GPG_ERR_NO_ERROR };
}
-void CryptoAlgorithmRSA_PSS::platformSign(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& data)
{
- context.ref();
- workQueue.dispatch(
- [parameters = WTFMove(parameters), key = WTFMove(key), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(*parameters);
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(parameters);
- auto output = gcryptSign(rsaKey.platformKey(), rsaKey.keySizeInBits(), data, rsaKey.hashAlgorithmIdentifier(), rsaParameters.saltLength);
- if (!output) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- exceptionCallback(OperationError);
- context.deref();
- });
- return;
- }
-
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(output);
- context.deref();
- });
- });
+ auto output = gcryptSign(rsaKey.platformKey(), rsaKey.keySizeInBits(), data, rsaKey.hashAlgorithmIdentifier(), rsaParameters.saltLength);
+ if (!output)
+ return Exception { OperationError };
+ return WTFMove(*output);
}
-void CryptoAlgorithmRSA_PSS::platformVerify(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<bool> CryptoAlgorithmRSA_PSS::platformVerify(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
{
- context.ref();
- workQueue.dispatch(
- [parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(*parameters);
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(parameters);
- auto output = gcryptVerify(rsaKey.platformKey(), signature, data, rsaKey.hashAlgorithmIdentifier(), rsaParameters.saltLength);
- if (!output) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- exceptionCallback(OperationError);
- context.deref();
- });
- return;
- }
-
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask(
- [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(output);
- context.deref();
- });
- });
+ auto output = gcryptVerify(rsaKey.platformKey(), signature, data, rsaKey.hashAlgorithmIdentifier(), rsaParameters.saltLength);
+ if (!output)
+ return Exception { OperationError };
+ return WTFMove(*output);
}
Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -30,7 +30,6 @@
#include "CommonCryptoUtilities.h"
#include "CryptoKeyRSA.h"
-#include "ScriptExecutionContext.h"
namespace WebCore {
@@ -55,48 +54,16 @@
return WTFMove(plainText);
}
-void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKey& key, const Vector<uint8_t>& plainText)
{
- context.ref();
- workQueue.dispatch([key = WTFMove(key), plainText = WTFMove(plainText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto result = encryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText);
- if (result.hasException()) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
- exceptionCallback(ec);
- context.deref();
- });
- return;
- }
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(result);
- context.deref();
- });
- });
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ return encryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText);
}
-void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKey& key, const Vector<uint8_t>& cipherText)
{
- context.ref();
- workQueue.dispatch([key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto result = decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText);
- if (result.hasException()) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
- exceptionCallback(ec);
- context.deref();
- });
- return;
- }
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(result);
- context.deref();
- });
- });
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ return decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -31,7 +31,6 @@
#include "CommonCryptoUtilities.h"
#include "CryptoDigestAlgorithm.h"
#include "CryptoKeyRSA.h"
-#include "ScriptExecutionContext.h"
namespace WebCore {
@@ -84,48 +83,16 @@
return Exception { OperationError };
}
-void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoKey& key, const Vector<uint8_t>& data)
{
- context.ref();
- workQueue.dispatch([key = WTFMove(key), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto result = signRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data);
- if (result.hasException()) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
- exceptionCallback(ec);
- context.deref();
- });
- return;
- }
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(result);
- context.deref();
- });
- });
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ return signRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data);
}
-void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<bool> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
{
- context.ref();
- workQueue.dispatch([key = WTFMove(key), signature = WTFMove(signature), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto result = verifyRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature, data);
- if (result.hasException()) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
- exceptionCallback(ec);
- context.deref();
- });
- return;
- }
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(result);
- context.deref();
- });
- });
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ return verifyRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature, data);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -31,7 +31,6 @@
#include "CommonCryptoUtilities.h"
#include "CryptoAlgorithmRsaOaepParams.h"
#include "CryptoKeyRSA.h"
-#include "ScriptExecutionContext.h"
namespace WebCore {
@@ -64,50 +63,18 @@
return WTFMove(plainText);
}
-void CryptoAlgorithmRSA_OAEP::platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& plainText)
{
- context.ref();
- workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto result = encryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText);
- if (result.hasException()) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
- exceptionCallback(ec);
- context.deref();
- });
- return;
- }
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(result);
- context.deref();
- });
- });
+ auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(parameters);
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ return encryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText);
}
-void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& cipherText)
{
- context.ref();
- workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto result = decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText);
- if (result.hasException()) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
- exceptionCallback(ec);
- context.deref();
- });
- return;
- }
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(result);
- context.deref();
- });
- });
+ auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(parameters);
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ return decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_PSSMac.cpp (221180 => 221181)
--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_PSSMac.cpp 2017-08-25 05:24:38 UTC (rev 221180)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_PSSMac.cpp 2017-08-25 07:20:34 UTC (rev 221181)
@@ -32,7 +32,6 @@
#include "CryptoAlgorithmRsaPssParams.h"
#include "CryptoDigestAlgorithm.h"
#include "CryptoKeyRSA.h"
-#include "ScriptExecutionContext.h"
namespace WebCore {
@@ -82,50 +81,18 @@
return false;
}
-void CryptoAlgorithmRSA_PSS::platformSign(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSA_PSS::platformSign(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& data)
{
- context.ref();
- workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto& rsaParams = downcast<CryptoAlgorithmRsaPssParams>(*parameters);
- auto result = signRSA_PSS(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data, rsaParams.saltLength);
- if (result.hasException()) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
- exceptionCallback(ec);
- context.deref();
- });
- return;
- }
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(result);
- context.deref();
- });
- });
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(parameters);
+ return signRSA_PSS(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data, rsaParameters.saltLength);
}
-void CryptoAlgorithmRSA_PSS::platformVerify(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSA_PSS::platformVerify(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
{
- context.ref();
- workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
- auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
- auto& rsaParams = downcast<CryptoAlgorithmRsaPssParams>(*parameters);
- auto result = verifyRSA_PSS(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature, data, rsaParams.saltLength);
- if (result.hasException()) {
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
- exceptionCallback(ec);
- context.deref();
- });
- return;
- }
- // We should only dereference callbacks after being back to the Document/Worker threads.
- context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
- callback(result);
- context.deref();
- });
- });
+ auto& rsaKey = downcast<CryptoKeyRSA>(key);
+ auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(parameters);
+ return verifyRSA_PSS(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature, data, rsaParameters.saltLength);
}
} // namespace WebCore