⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 221181 in webkit


Ignore:
Timestamp:
Aug 25, 2017, 12:20:34 AM (9 years ago)
Author:
zandobersek@gmail.com
Message:

[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):

Location:
trunk/Source/WebCore
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r221179 r221181  
     12017-08-25  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [WebCrypto] Push WorkQueue dispatches for RSA algorithms into shared code
     4        https://bugs.webkit.org/show_bug.cgi?id=175621
     5
     6        Reviewed by Darin Adler.
     7
     8        Push the WorkQueue dispatch code and other code duplicated between the
     9        Mac and libgcrypt implementations of Web Crypto into the shared layer.
     10        This patch focuses on the RSA-based algorithms.
     11
     12        The WorkQueue dispatch code is condensed into two static functions on
     13        the CryptoAlgorithm class, the first variation handling VectorCallback
     14        as the callback type and the other handling BoolCallback. The operation
     15        is kept in a WTF::Function<> object that returns an ExceptionOr<> value
     16        embedding either a Vector<uint8_t> object or a boolean value, as
     17        appropriate for the callback type.
     18
     19        Functions with platform-specific implementations that are invoked from
     20        these asynchronous dispatches are made static and return an ExceptionOr
     21        value. CryptoAlgorithmParameters objects are passed through non-const
     22        references because data getters could lazily construct the underlying
     23        Vector objects. CryptoKey objects are passed through const references.
     24        Implementations can then manually retrieve and further validate any key
     25        or parameter data, as required for that specific implementation. Input
     26        data is passed through const references to the original Vector objects.
     27
     28        No new tests -- no changes in behavior that's covered by existing tests.
     29
     30        * crypto/CryptoAlgorithm.cpp:
     31        (WebCore::dispatchOperationImpl):
     32        (WebCore::CryptoAlgorithm::dispatchOperation):
     33        * crypto/CryptoAlgorithm.h:
     34        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
     35        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt):
     36        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt):
     37        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h:
     38        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
     39        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
     40        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
     41        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
     42        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
     43        (WebCore::CryptoAlgorithmRSA_OAEP::encrypt):
     44        (WebCore::CryptoAlgorithmRSA_OAEP::decrypt):
     45        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
     46        * crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp:
     47        (WebCore::CryptoAlgorithmRSA_PSS::sign):
     48        (WebCore::CryptoAlgorithmRSA_PSS::verify):
     49        * crypto/algorithms/CryptoAlgorithmRSA_PSS.h:
     50        * crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp:
     51        (WebCore::gcryptEncrypt):
     52        (WebCore::gcryptDecrypt):
     53        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
     54        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
     55        * crypto/gcrypt/CryptoAlgorithmRSASSA_PKCS1_v1_5GCrypt.cpp:
     56        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):
     57        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify):
     58        * crypto/gcrypt/CryptoAlgorithmRSA_OAEPGCrypt.cpp:
     59        (WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt):
     60        (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):
     61        * crypto/gcrypt/CryptoAlgorithmRSA_PSSGCrypt.cpp:
     62        (WebCore::CryptoAlgorithmRSA_PSS::platformSign):
     63        (WebCore::CryptoAlgorithmRSA_PSS::platformVerify):
     64        * crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp:
     65        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
     66        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
     67        * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
     68        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign):
     69        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify):
     70        * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp:
     71        (WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt):
     72        (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):
     73        * crypto/mac/CryptoAlgorithmRSA_PSSMac.cpp:
     74        (WebCore::CryptoAlgorithmRSA_PSS::platformSign):
     75        (WebCore::CryptoAlgorithmRSA_PSS::platformVerify):
     76
    1772017-08-24  Chris Dumez  <cdumez@apple.com>
    278
  • trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp

    r220941 r221181  
    2828
    2929#if ENABLE(SUBTLE_CRYPTO)
     30
     31#include "ScriptExecutionContext.h"
    3032
    3133namespace WebCore {
    … …  
    9193}
    9294
     95template<typename ResultCallbackType, typename OperationType>
     96static void dispatchAlgorithmOperation(WorkQueue& workQueue, ScriptExecutionContext& context, ResultCallbackType&& callback, CryptoAlgorithm::ExceptionCallback&& exceptionCallback, OperationType&& operation)
     97{
     98    context.ref();
     99    workQueue.dispatch(
     100        [operation = WTFMove(operation), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
     101            auto result = operation();
     102            if (result.hasException()) {
     103                // We should only dereference callbacks after being back to the Document/Worker threads.
     104                context.postTask(
     105                    [ec = result.releaseException().code(), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
     106                        exceptionCallback(ec);
     107                        context.deref();
     108                    });
     109                return;
     110            }
     111
     112            // We should only dereference callbacks after being back to the Document/Worker threads.
     113            context.postTask(
     114                [result = result.releaseReturnValue(), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
     115                    callback(result);
     116                    context.deref();
     117                });
     118        });
     119}
     120
     121void CryptoAlgorithm::dispatchOperation(WorkQueue& workQueue, ScriptExecutionContext& context, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, WTF::Function<ExceptionOr<Vector<uint8_t>>()>&& operation)
     122{
     123    dispatchAlgorithmOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback), WTFMove(operation));
     124}
     125
     126void CryptoAlgorithm::dispatchOperation(WorkQueue& workQueue, ScriptExecutionContext& context, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, WTF::Function<ExceptionOr<bool>()>&& operation)
     127{
     128    dispatchAlgorithmOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback), WTFMove(operation));
     129}
     130
    93131}
    94132
  • trunk/Source/WebCore/crypto/CryptoAlgorithm.h

    r220949 r221181  
    7777    virtual void unwrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&);
    7878    virtual ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&);
     79
     80    static void dispatchOperation(WorkQueue&, ScriptExecutionContext&, VectorCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<Vector<uint8_t>>()>&&);
     81    static void dispatchOperation(WorkQueue&, ScriptExecutionContext&, BoolCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<bool>()>&&);
    7982};
    8083
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp

    r220949 r221181  
    5454        return;
    5555    }
    56     platformEncrypt(WTFMove(key), WTFMove(plainText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     56
     57    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
     58        [key = WTFMove(key), plainText = WTFMove(plainText)] {
     59            return platformEncrypt(key, plainText);
     60        });
    5761}
    5862
    … …  
    6367        return;
    6468    }
    65     platformDecrypt(WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     69
     70    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
     71        [key = WTFMove(key), cipherText = WTFMove(cipherText)] {
     72            return platformDecrypt(key, cipherText);
     73        });
    6674}
    6775
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h

    r220941 r221181  
    5151    void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
    5252
    53     void platformEncrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    54     void platformDecrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     53    static ExceptionOr<Vector<uint8_t>> platformEncrypt(const CryptoKey&, const Vector<uint8_t>&);
     54    static ExceptionOr<Vector<uint8_t>> platformDecrypt(const CryptoKey&, const Vector<uint8_t>&);
    5555};
    5656
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp

    r220949 r221181  
    5959        return;
    6060    }
    61     platformSign(WTFMove(key), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     61
     62    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
     63        [key = WTFMove(key), data = WTFMove(data)] {
     64            return platformSign(key, data);
     65        });
    6266}
    6367
    … …  
    6872        return;
    6973    }
    70     platformVerify(WTFMove(key), WTFMove(signature), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     74
     75    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
     76        [key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data)] {
     77            return platformVerify(key, signature, data);
     78        });
    7179}
    7280
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h

    r220941 r221181  
    5050    void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
    5151
    52     void platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    53     void platformVerify(Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     52    static ExceptionOr<Vector<uint8_t>> platformSign(const CryptoKey&, const Vector<uint8_t>&);
     53    static ExceptionOr<bool> platformVerify(const CryptoKey&, const Vector<uint8_t>&, const Vector<uint8_t>&);
    5454};
    5555
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp

    r220949 r221181  
    6060        return;
    6161    }
    62     platformEncrypt(WTFMove(parameters), WTFMove(key), WTFMove(plainText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     62
     63    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
     64        [parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
     65            return platformEncrypt(*parameters, key, plainText);
     66        });
    6367}
    6468
    … …  
    7074        return;
    7175    }
    72     platformDecrypt(WTFMove(parameters), WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     76
     77    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
     78        [parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
     79            return platformDecrypt(*parameters, key, cipherText);
     80        });
    7381}
    7482
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h

    r220941 r221181  
    5050    void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
    5151
    52     void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    53     void platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     52    static ExceptionOr<Vector<uint8_t>> platformEncrypt(CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&);
     53    static ExceptionOr<Vector<uint8_t>> platformDecrypt(CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&);
    5454};
    5555
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp

    r220811 r221181  
    5959        return;
    6060    }
    61     platformSign(WTFMove(parameters), WTFMove(key), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     61
     62    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
     63        [parameters = WTFMove(parameters), key = WTFMove(key), data = WTFMove(data)] {
     64            return platformSign(*parameters, key, data);
     65        });
    6266}
    6367
    … …  
    6872        return;
    6973    }
    70     platformVerify(WTFMove(parameters), WTFMove(key), WTFMove(signature), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
     74
     75    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
     76        [parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data)] {
     77            return platformVerify(*parameters, key, signature, data);
     78        });
    7179}
    7280
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.h

    r220811 r221181  
    5050    void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
    5151
    52     void platformSign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
    53     void platformVerify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     52    static ExceptionOr<Vector<uint8_t>> platformSign(CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&);
     53    static ExceptionOr<bool> platformVerify(CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&, const Vector<uint8_t>&);
    5454};
    5555
  • trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp

    r220941 r221181  
    3131#include "CryptoKeyRSA.h"
    3232#include "GCryptUtilities.h"
    33 #include "ScriptExecutionContext.h"
    3433
    3534namespace WebCore {
    3635
    37 static std::optional<Vector<uint8_t>> gcryptEncrypt(gcry_sexp_t keySexp, Vector<uint8_t>&& plainText)
     36static std::optional<Vector<uint8_t>> gcryptEncrypt(gcry_sexp_t keySexp, const Vector<uint8_t>& plainText)
    3837{
    3938    // Embed the plain-text data in a `data` s-expression using PKCS#1 padding.
    … …  
    6564}
    6665
    67 static std::optional<Vector<uint8_t>> gcryptDecrypt(gcry_sexp_t keySexp, Vector<uint8_t>&& cipherText)
     66static std::optional<Vector<uint8_t>> gcryptDecrypt(gcry_sexp_t keySexp, const Vector<uint8_t>& cipherText)
    6867{
    6968    // Embed the cipher-text data in an `enc-val` s-expression using PKCS#1 padding.
    … …  
    9594}
    9695
    97 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     96ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKey& key, const Vector<uint8_t>& plainText)
    9897{
    99     context.ref();
    100     workQueue.dispatch(
    101         [key = WTFMove(key), plainText = WTFMove(plainText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    102             auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    103 
    104             auto output = gcryptEncrypt(rsaKey.platformKey(), WTFMove(plainText));
    105             if (!output) {
    106                 // We should only dereference callbacks after being back to the Document/Worker threads.
    107                 context.postTask(
    108                     [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    109                         exceptionCallback(OperationError);
    110                         context.deref();
    111                     });
    112                 return;
    113             }
    114 
    115             // We should only dereference callbacks after being back to the Document/Worker threads.
    116             context.postTask(
    117                 [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) mutable {
    118                     callback(WTFMove(output));
    119                     context.deref();
    120                 });
    121         });
     98    auto output = gcryptEncrypt(downcast<CryptoKeyRSA>(key).platformKey(), plainText);
     99    if (!output)
     100        return Exception { OperationError };
     101    return WTFMove(*output);
    122102}
    123103
    124 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     104ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKey& key, const Vector<uint8_t>& cipherText)
    125105{
    126     context.ref();
    127     workQueue.dispatch(
    128         [key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    129             auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    130 
    131             auto output = gcryptDecrypt(rsaKey.platformKey(), WTFMove(cipherText));
    132             if (!output) {
    133                 // We should only dereference callbacks after being back to the Document/Worker threads.
    134                 context.postTask(
    135                     [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    136                         exceptionCallback(OperationError);
    137                         context.deref();
    138                     });
    139                 return;
    140             }
    141 
    142             // We should only dereference callbacks after being back to the Document/Worker threads.
    143             context.postTask(
    144                 [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) mutable {
    145                     callback(WTFMove(output));
    146                     context.deref();
    147                 });
    148         });
     106    auto output = gcryptDecrypt(downcast<CryptoKeyRSA>(key).platformKey(), cipherText);
     107    if (!output)
     108        return Exception { OperationError };
     109    return WTFMove(*output);
    149110}
    150111
  • trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSASSA_PKCS1_v1_5GCrypt.cpp

    r220941 r221181  
    3333#include "GCryptUtilities.h"
    3434#include "NotImplemented.h"
    35 #include "ScriptExecutionContext.h"
    3635
    3736namespace WebCore {
    … …  
    136135}
    137136
    138 void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     137ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoKey& key, const Vector<uint8_t>& data)
    139138{
    140     context.ref();
    141     workQueue.dispatch(
    142         [key = WTFMove(key), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    143             auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    144 
    145             auto output = gcryptSign(rsaKey.platformKey(), data, rsaKey.hashAlgorithmIdentifier());
    146             if (!output) {
    147                 // We should only dereference callbacks after being back to the Document/Worker threads.
    148                 context.postTask(
    149                     [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    150                         exceptionCallback(OperationError);
    151                         context.deref();
    152                     });
    153                 return;
    154             }
    155 
    156             // We should only dereference callbacks after being back to the Document/Worker threads.
    157             context.postTask(
    158                 [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    159                     callback(output);
    160                     context.deref();
    161                 });
    162         });
     139    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     140    auto output = gcryptSign(rsaKey.platformKey(), data, rsaKey.hashAlgorithmIdentifier());
     141    if (!output)
     142        return Exception { OperationError };
     143    return WTFMove(*output);
    163144}
    164145
    165 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)
     146ExceptionOr<bool> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
    166147{
    167     context.ref();
    168     workQueue.dispatch(
    169         [key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    170             auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    171 
    172             auto output = gcryptVerify(rsaKey.platformKey(), signature, data, rsaKey.hashAlgorithmIdentifier());
    173             if (!output) {
    174                 // We should only dereference callbacks after being back to the Document/Worker threads.
    175                 context.postTask(
    176                     [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    177                         exceptionCallback(OperationError);
    178                         context.deref();
    179                     });
    180                 return;
    181             }
    182 
    183             // We should only dereference callbacks after being back to the Document/Worker threads.
    184             context.postTask(
    185                 [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    186                     callback(output);
    187                     context.deref();
    188                 });
    189         });
     148    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     149    auto output = gcryptVerify(rsaKey.platformKey(), signature, data, rsaKey.hashAlgorithmIdentifier());
     150    if (!output)
     151        return Exception { OperationError };
     152    return *output;
    190153}
    191154
  • trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_OAEPGCrypt.cpp

    r220941 r221181  
    3333#include "GCryptUtilities.h"
    3434#include "NotImplemented.h"
    35 #include "ScriptExecutionContext.h"
    3635
    3736namespace WebCore {
    … …  
    112111}
    113112
    114 void CryptoAlgorithmRSA_OAEP::platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     113ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& plainText)
    115114{
    116     context.ref();
    117     workQueue.dispatch(
    118         [parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    119             auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
    120             auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
     115    auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(parameters);
     116    auto& rsaKey = downcast<CryptoKeyRSA>(key);
    121117
    122             auto output = gcryptEncrypt(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaParameters.labelVector(), plainText);
    123             if (!output) {
    124                 // We should only dereference callbacks after being back to the Document/Worker threads.
    125                 context.postTask(
    126                     [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    127                         exceptionCallback(OperationError);
    128                         context.deref();
    129                     });
    130                 return;
    131             }
    132 
    133             // We should only dereference callbacks after being back to the Document/Worker threads.
    134             context.postTask(
    135                 [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    136                     callback(output);
    137                     context.deref();
    138                 });
    139         });
     118    auto output = gcryptEncrypt(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaParameters.labelVector(), plainText);
     119    if (!output)
     120        return Exception { OperationError };
     121    return WTFMove(*output);
    140122}
    141123
    142 void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     124ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& cipherText)
    143125{
    144     context.ref();
    145     workQueue.dispatch(
    146         [parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    147             auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
    148             auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
     126    auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(parameters);
     127    auto& rsaKey = downcast<CryptoKeyRSA>(key);
    149128
    150             auto output = gcryptDecrypt(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaParameters.labelVector(), cipherText);
    151             if (!output) {
    152                 // We should only dereference callbacks after being back to the Document/Worker threads.
    153                 context.postTask(
    154                     [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    155                         exceptionCallback(OperationError);
    156                         context.deref();
    157                     });
    158                 return;
    159             }
    160 
    161             // We should only dereference callbacks after being back to the Document/Worker threads.
    162             context.postTask(
    163                 [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    164                     callback(output);
    165                     context.deref();
    166                 });
    167         });
     129    auto output = gcryptDecrypt(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaParameters.labelVector(), cipherText);
     130    if (!output)
     131        return Exception { OperationError };
     132    return WTFMove(*output);
    168133}
    169134
  • trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_PSSGCrypt.cpp

    r219831 r221181  
    3434#include "CryptoKeyRSA.h"
    3535#include "GCryptUtilities.h"
    36 #include "ScriptExecutionContext.h"
    3736
    3837namespace WebCore {
    … …  
    142141}
    143142
    144 void CryptoAlgorithmRSA_PSS::platformSign(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     143ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& data)
    145144{
    146     context.ref();
    147     workQueue.dispatch(
    148         [parameters = WTFMove(parameters), key = WTFMove(key), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    149             auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    150             auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(*parameters);
     145    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     146    auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(parameters);
    151147
    152             auto output = gcryptSign(rsaKey.platformKey(), rsaKey.keySizeInBits(), data, rsaKey.hashAlgorithmIdentifier(), rsaParameters.saltLength);
    153             if (!output) {
    154                 // We should only dereference callbacks after being back to the Document/Worker threads.
    155                 context.postTask(
    156                     [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    157                         exceptionCallback(OperationError);
    158                         context.deref();
    159                     });
    160                 return;
    161             }
    162 
    163             // We should only dereference callbacks after being back to the Document/Worker threads.
    164             context.postTask(
    165                 [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    166                     callback(output);
    167                     context.deref();
    168                 });
    169         });
     148    auto output = gcryptSign(rsaKey.platformKey(), rsaKey.keySizeInBits(), data, rsaKey.hashAlgorithmIdentifier(), rsaParameters.saltLength);
     149    if (!output)
     150        return Exception { OperationError };
     151    return WTFMove(*output);
    170152}
    171153
    172 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)
     154ExceptionOr<bool> CryptoAlgorithmRSA_PSS::platformVerify(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
    173155{
    174     context.ref();
    175     workQueue.dispatch(
    176         [parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    177             auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    178             auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(*parameters);
     156    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     157    auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(parameters);
    179158
    180             auto output = gcryptVerify(rsaKey.platformKey(), signature, data, rsaKey.hashAlgorithmIdentifier(), rsaParameters.saltLength);
    181             if (!output) {
    182                 // We should only dereference callbacks after being back to the Document/Worker threads.
    183                 context.postTask(
    184                     [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    185                         exceptionCallback(OperationError);
    186                         context.deref();
    187                     });
    188                 return;
    189             }
    190 
    191             // We should only dereference callbacks after being back to the Document/Worker threads.
    192             context.postTask(
    193                 [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    194                     callback(output);
    195                     context.deref();
    196                 });
    197         });
     159    auto output = gcryptVerify(rsaKey.platformKey(), signature, data, rsaKey.hashAlgorithmIdentifier(), rsaParameters.saltLength);
     160    if (!output)
     161        return Exception { OperationError };
     162    return WTFMove(*output);
    198163}
    199164
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp

    r220953 r221181  
    3131#include "CommonCryptoUtilities.h"
    3232#include "CryptoKeyRSA.h"
    33 #include "ScriptExecutionContext.h"
    3433
    3534namespace WebCore {
    … …  
    5655}
    5756
    58 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     57ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKey& key, const Vector<uint8_t>& plainText)
    5958{
    60     context.ref();
    61     workQueue.dispatch([key = WTFMove(key), plainText = WTFMove(plainText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    62         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    63         auto result = encryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText);
    64         if (result.hasException()) {
    65             // We should only dereference callbacks after being back to the Document/Worker threads.
    66             context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
    67                 exceptionCallback(ec);
    68                 context.deref();
    69             });
    70             return;
    71         }
    72         // We should only dereference callbacks after being back to the Document/Worker threads.
    73         context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    74             callback(result);
    75             context.deref();
    76         });
    77     });
     59    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     60    return encryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText);
    7861}
    7962
    80 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     63ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKey& key, const Vector<uint8_t>& cipherText)
    8164{
    82     context.ref();
    83     workQueue.dispatch([key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    84         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    85         auto result = decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText);
    86         if (result.hasException()) {
    87             // We should only dereference callbacks after being back to the Document/Worker threads.
    88             context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
    89                 exceptionCallback(ec);
    90                 context.deref();
    91             });
    92             return;
    93         }
    94         // We should only dereference callbacks after being back to the Document/Worker threads.
    95         context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    96             callback(result);
    97             context.deref();
    98         });
    99     });
     65    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     66    return decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText);
    10067}
    10168
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp

    r220953 r221181  
    3232#include "CryptoDigestAlgorithm.h"
    3333#include "CryptoKeyRSA.h"
    34 #include "ScriptExecutionContext.h"
    3534
    3635namespace WebCore {
    … …  
    8584}
    8685
    87 void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     86ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoKey& key, const Vector<uint8_t>& data)
    8887{
    89     context.ref();
    90     workQueue.dispatch([key = WTFMove(key), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    91         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    92         auto result = signRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data);
    93         if (result.hasException()) {
    94             // We should only dereference callbacks after being back to the Document/Worker threads.
    95             context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
    96                 exceptionCallback(ec);
    97                 context.deref();
    98             });
    99             return;
    100         }
    101         // We should only dereference callbacks after being back to the Document/Worker threads.
    102         context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    103             callback(result);
    104             context.deref();
    105         });
    106     });
     88    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     89    return signRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data);
    10790}
    10891
    109 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)
     92ExceptionOr<bool> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
    11093{
    111     context.ref();
    112     workQueue.dispatch([key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    113         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    114         auto result = verifyRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature, data);
    115         if (result.hasException()) {
    116             // We should only dereference callbacks after being back to the Document/Worker threads.
    117             context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
    118                 exceptionCallback(ec);
    119                 context.deref();
    120             });
    121             return;
    122         }
    123         // We should only dereference callbacks after being back to the Document/Worker threads.
    124         context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    125             callback(result);
    126             context.deref();
    127         });
    128     });
     94    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     95    return verifyRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature, data);
    12996}
    13097
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp

    r220953 r221181  
    3232#include "CryptoAlgorithmRsaOaepParams.h"
    3333#include "CryptoKeyRSA.h"
    34 #include "ScriptExecutionContext.h"
    3534
    3635namespace WebCore {
    … …  
    6564}
    6665
    67 void CryptoAlgorithmRSA_OAEP::platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     66ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& plainText)
    6867{
    69     context.ref();
    70     workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    71         auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
    72         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    73         auto result = encryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText);
    74         if (result.hasException()) {
    75             // We should only dereference callbacks after being back to the Document/Worker threads.
    76             context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
    77                 exceptionCallback(ec);
    78                 context.deref();
    79             });
    80             return;
    81         }
    82         // We should only dereference callbacks after being back to the Document/Worker threads.
    83         context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    84             callback(result);
    85             context.deref();
    86         });
    87     });
     68    auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(parameters);
     69    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     70    return encryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText);
    8871}
    8972
    90 void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     73ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& cipherText)
    9174{
    92     context.ref();
    93     workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    94         auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
    95         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    96         auto result = decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText);
    97         if (result.hasException()) {
    98             // We should only dereference callbacks after being back to the Document/Worker threads.
    99             context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
    100                 exceptionCallback(ec);
    101                 context.deref();
    102             });
    103             return;
    104         }
    105         // We should only dereference callbacks after being back to the Document/Worker threads.
    106         context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    107             callback(result);
    108             context.deref();
    109         });
    110     });
     75    auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(parameters);
     76    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     77    return decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText);
    11178}
    11279
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_PSSMac.cpp

    r219831 r221181  
    3333#include "CryptoDigestAlgorithm.h"
    3434#include "CryptoKeyRSA.h"
    35 #include "ScriptExecutionContext.h"
    3635
    3736namespace WebCore {
    … …  
    8382}
    8483
    85 void CryptoAlgorithmRSA_PSS::platformSign(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
     84void CryptoAlgorithmRSA_PSS::platformSign(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& data)
    8685{
    87     context.ref();
    88     workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    89         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    90         auto& rsaParams = downcast<CryptoAlgorithmRsaPssParams>(*parameters);
    91         auto result = signRSA_PSS(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data, rsaParams.saltLength);
    92         if (result.hasException()) {
    93             // We should only dereference callbacks after being back to the Document/Worker threads.
    94             context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
    95                 exceptionCallback(ec);
    96                 context.deref();
    97             });
    98             return;
    99         }
    100         // We should only dereference callbacks after being back to the Document/Worker threads.
    101         context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    102             callback(result);
    103             context.deref();
    104         });
    105     });
     86    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     87    auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(parameters);
     88    return signRSA_PSS(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data, rsaParameters.saltLength);
    10689}
    10790
    108 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)
     91void CryptoAlgorithmRSA_PSS::platformVerify(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
    10992{
    110     context.ref();
    111     workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
    112         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
    113         auto& rsaParams = downcast<CryptoAlgorithmRsaPssParams>(*parameters);
    114         auto result = verifyRSA_PSS(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature, data, rsaParams.saltLength);
    115         if (result.hasException()) {
    116             // We should only dereference callbacks after being back to the Document/Worker threads.
    117             context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
    118                 exceptionCallback(ec);
    119                 context.deref();
    120             });
    121             return;
    122         }
    123         // We should only dereference callbacks after being back to the Document/Worker threads.
    124         context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
    125             callback(result);
    126             context.deref();
    127         });
    128     });
     93    auto& rsaKey = downcast<CryptoKeyRSA>(key);
     94    auto& rsaParameters = downcast<CryptoAlgorithmRsaPssParams>(parameters);
     95    return verifyRSA_PSS(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature, data, rsaParameters.saltLength);
    12996}
    13097
Note: See TracChangeset for help on using the changeset viewer.