Changeset 221181 in webkit
- Timestamp:
- Aug 25, 2017, 12:20:34 AM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 19 edited
-
ChangeLog (modified) (1 diff)
-
crypto/CryptoAlgorithm.cpp (modified) (2 diffs)
-
crypto/CryptoAlgorithm.h (modified) (1 diff)
-
crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp (modified) (2 diffs)
-
crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h (modified) (1 diff)
-
crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp (modified) (2 diffs)
-
crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h (modified) (1 diff)
-
crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp (modified) (2 diffs)
-
crypto/algorithms/CryptoAlgorithmRSA_OAEP.h (modified) (1 diff)
-
crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp (modified) (2 diffs)
-
crypto/algorithms/CryptoAlgorithmRSA_PSS.h (modified) (1 diff)
-
crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp (modified) (3 diffs)
-
crypto/gcrypt/CryptoAlgorithmRSASSA_PKCS1_v1_5GCrypt.cpp (modified) (2 diffs)
-
crypto/gcrypt/CryptoAlgorithmRSA_OAEPGCrypt.cpp (modified) (2 diffs)
-
crypto/gcrypt/CryptoAlgorithmRSA_PSSGCrypt.cpp (modified) (2 diffs)
-
crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp (modified) (2 diffs)
-
crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp (modified) (2 diffs)
-
crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp (modified) (2 diffs)
-
crypto/mac/CryptoAlgorithmRSA_PSSMac.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r221179 r221181 1 2017-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 1 77 2017-08-24 Chris Dumez <cdumez@apple.com> 2 78 -
trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp
r220941 r221181 28 28 29 29 #if ENABLE(SUBTLE_CRYPTO) 30 31 #include "ScriptExecutionContext.h" 30 32 31 33 namespace WebCore { … … 91 93 } 92 94 95 template<typename ResultCallbackType, typename OperationType> 96 static 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 121 void 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 126 void 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 93 131 } 94 132 -
trunk/Source/WebCore/crypto/CryptoAlgorithm.h
r220949 r221181 77 77 virtual void unwrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&); 78 78 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>()>&&); 79 82 }; 80 83 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp
r220949 r221181 54 54 return; 55 55 } 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 }); 57 61 } 58 62 … … 63 67 return; 64 68 } 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 }); 66 74 } 67 75 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h
r220941 r221181 51 51 void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final; 52 52 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>&); 55 55 }; 56 56 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
r220949 r221181 59 59 return; 60 60 } 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 }); 62 66 } 63 67 … … 68 72 return; 69 73 } 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 }); 71 79 } 72 80 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h
r220941 r221181 50 50 void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final; 51 51 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>&); 54 54 }; 55 55 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp
r220949 r221181 60 60 return; 61 61 } 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 }); 63 67 } 64 68 … … 70 74 return; 71 75 } 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 }); 73 81 } 74 82 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h
r220941 r221181 50 50 void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final; 51 51 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>&); 54 54 }; 55 55 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp
r220811 r221181 59 59 return; 60 60 } 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 }); 62 66 } 63 67 … … 68 72 return; 69 73 } 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 }); 71 79 } 72 80 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.h
r220811 r221181 50 50 void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final; 51 51 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>&); 54 54 }; 55 55 -
trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp
r220941 r221181 31 31 #include "CryptoKeyRSA.h" 32 32 #include "GCryptUtilities.h" 33 #include "ScriptExecutionContext.h"34 33 35 34 namespace WebCore { 36 35 37 static std::optional<Vector<uint8_t>> gcryptEncrypt(gcry_sexp_t keySexp, Vector<uint8_t>&& plainText)36 static std::optional<Vector<uint8_t>> gcryptEncrypt(gcry_sexp_t keySexp, const Vector<uint8_t>& plainText) 38 37 { 39 38 // Embed the plain-text data in a `data` s-expression using PKCS#1 padding. … … 65 64 } 66 65 67 static std::optional<Vector<uint8_t>> gcryptDecrypt(gcry_sexp_t keySexp, Vector<uint8_t>&& cipherText)66 static std::optional<Vector<uint8_t>> gcryptDecrypt(gcry_sexp_t keySexp, const Vector<uint8_t>& cipherText) 68 67 { 69 68 // Embed the cipher-text data in an `enc-val` s-expression using PKCS#1 padding. … … 95 94 } 96 95 97 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)96 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKey& key, const Vector<uint8_t>& plainText) 98 97 { 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); 122 102 } 123 103 124 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)104 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKey& key, const Vector<uint8_t>& cipherText) 125 105 { 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); 149 110 } 150 111 -
trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSASSA_PKCS1_v1_5GCrypt.cpp
r220941 r221181 33 33 #include "GCryptUtilities.h" 34 34 #include "NotImplemented.h" 35 #include "ScriptExecutionContext.h"36 35 37 36 namespace WebCore { … … 136 135 } 137 136 138 void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)137 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoKey& key, const Vector<uint8_t>& data) 139 138 { 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); 163 144 } 164 145 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)146 ExceptionOr<bool> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data) 166 147 { 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; 190 153 } 191 154 -
trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_OAEPGCrypt.cpp
r220941 r221181 33 33 #include "GCryptUtilities.h" 34 34 #include "NotImplemented.h" 35 #include "ScriptExecutionContext.h"36 35 37 36 namespace WebCore { … … 112 111 } 113 112 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)113 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& plainText) 115 114 { 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); 121 117 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); 140 122 } 141 123 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)124 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& cipherText) 143 125 { 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); 149 128 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); 168 133 } 169 134 -
trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_PSSGCrypt.cpp
r219831 r221181 34 34 #include "CryptoKeyRSA.h" 35 35 #include "GCryptUtilities.h" 36 #include "ScriptExecutionContext.h"37 36 38 37 namespace WebCore { … … 142 141 } 143 142 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)143 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& data) 145 144 { 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); 151 147 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); 170 152 } 171 153 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)154 ExceptionOr<bool> CryptoAlgorithmRSA_PSS::platformVerify(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data) 173 155 { 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); 179 158 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); 198 163 } 199 164 -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp
r220953 r221181 31 31 #include "CommonCryptoUtilities.h" 32 32 #include "CryptoKeyRSA.h" 33 #include "ScriptExecutionContext.h"34 33 35 34 namespace WebCore { … … 56 55 } 57 56 58 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)57 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKey& key, const Vector<uint8_t>& plainText) 59 58 { 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); 78 61 } 79 62 80 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)63 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKey& key, const Vector<uint8_t>& cipherText) 81 64 { 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); 100 67 } 101 68 -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
r220953 r221181 32 32 #include "CryptoDigestAlgorithm.h" 33 33 #include "CryptoKeyRSA.h" 34 #include "ScriptExecutionContext.h"35 34 36 35 namespace WebCore { … … 85 84 } 86 85 87 void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)86 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoKey& key, const Vector<uint8_t>& data) 88 87 { 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); 107 90 } 108 91 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)92 ExceptionOr<bool> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data) 110 93 { 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); 129 96 } 130 97 -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp
r220953 r221181 32 32 #include "CryptoAlgorithmRsaOaepParams.h" 33 33 #include "CryptoKeyRSA.h" 34 #include "ScriptExecutionContext.h"35 34 36 35 namespace WebCore { … … 65 64 } 66 65 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)66 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& plainText) 68 67 { 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); 88 71 } 89 72 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)73 ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& cipherText) 91 74 { 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); 111 78 } 112 79 -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_PSSMac.cpp
r219831 r221181 33 33 #include "CryptoDigestAlgorithm.h" 34 34 #include "CryptoKeyRSA.h" 35 #include "ScriptExecutionContext.h"36 35 37 36 namespace WebCore { … … 83 82 } 84 83 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)84 void CryptoAlgorithmRSA_PSS::platformSign(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& data) 86 85 { 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); 106 89 } 107 90 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)91 void CryptoAlgorithmRSA_PSS::platformVerify(CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data) 109 92 { 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); 129 96 } 130 97
Note:
See TracChangeset
for help on using the changeset viewer.