[WebCrypto] Crypto operations should copy their parameters before hoping to another...
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jul 2018 00:31:49 +0000 (00:31 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jul 2018 00:31:49 +0000 (00:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187501
<rdar://problem/41438160>

Reviewed by Youenn Fablet.

Source/WebCore:

This patch aims at making all captured variables in all crypto lambdas that need to be passed
to a worker thread thread safe, which includes:
1) changing ref counted objects to thread safe ref counted object.
2) adding isolatedCopy methods to non ref counted classes, so they can be called by CrossThreadCopy().

In addition to above changes, this patch also does the following things:
1) change the name CryptoAlgorithm::dispatchOperation => CryptoAlgorithm::dispatchOperationInWorkQueue
to make it clear that lambdas will be passed to a secondary thread.
2) make CryptoAlgorithmParameters as const parameters for all methods.

Tests: crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html
       http/wpt/crypto/aes-cbc-crash.any.html
       http/wpt/crypto/aes-cbc-crash.any.worker.html
       http/wpt/crypto/aes-ctr-crash.any.html
       http/wpt/crypto/aes-ctr-crash.any.worker.html
       http/wpt/crypto/aes-gcm-crash.any.html
       http/wpt/crypto/aes-gcm-crash.any.worker.html
       http/wpt/crypto/derive-hmac-key-crash.any.html
       http/wpt/crypto/derive-hmac-key-crash.any.worker.html
       http/wpt/crypto/ecdsa-crash.any.html
       http/wpt/crypto/ecdsa-crash.any.worker.html
       http/wpt/crypto/hkdf-crash.any.html
       http/wpt/crypto/hkdf-crash.any.worker.html
       http/wpt/crypto/pbkdf2-crash.any.html
       http/wpt/crypto/pbkdf2-crash.any.worker.html
       http/wpt/crypto/rsa-oaep-crash.any.html
       http/wpt/crypto/rsa-oaep-crash.any.worker.html
       http/wpt/crypto/rsa-pss-crash.any.html
       http/wpt/crypto/rsa-pss-crash.any.worker.html
       http/wpt/crypto/unwrap-ec-key-crash.any.html
       http/wpt/crypto/unwrap-ec-key-crash.any.worker.html
       http/wpt/crypto/unwrap-rsa-key-crash.any.html
       http/wpt/crypto/unwrap-rsa-key-crash.any.worker.html

* crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::encrypt):
(WebCore::CryptoAlgorithm::decrypt):
(WebCore::CryptoAlgorithm::sign):
(WebCore::CryptoAlgorithm::verify):
(WebCore::CryptoAlgorithm::deriveBits):
(WebCore::CryptoAlgorithm::importKey):
(WebCore::dispatchAlgorithmOperation):
(WebCore::CryptoAlgorithm::dispatchOperationInWorkQueue):
(WebCore::CryptoAlgorithm::dispatchOperation): Deleted.
* crypto/CryptoAlgorithm.h:
* crypto/SubtleCrypto.cpp:
(WebCore::crossThreadCopyImportParams):
(WebCore::SubtleCrypto::encrypt):
(WebCore::SubtleCrypto::decrypt):
(WebCore::SubtleCrypto::sign):
(WebCore::SubtleCrypto::verify):
(WebCore::SubtleCrypto::deriveKey):
(WebCore::SubtleCrypto::deriveBits):
(WebCore::SubtleCrypto::importKey):
(WebCore::SubtleCrypto::wrapKey):
(WebCore::SubtleCrypto::unwrapKey):
* crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
(WebCore::CryptoAlgorithmAES_CBC::encrypt):
(WebCore::CryptoAlgorithmAES_CBC::decrypt):
(WebCore::CryptoAlgorithmAES_CBC::importKey):
* crypto/algorithms/CryptoAlgorithmAES_CBC.h:
* crypto/algorithms/CryptoAlgorithmAES_CFB.cpp:
(WebCore::CryptoAlgorithmAES_CFB::encrypt):
(WebCore::CryptoAlgorithmAES_CFB::decrypt):
(WebCore::CryptoAlgorithmAES_CFB::importKey):
* crypto/algorithms/CryptoAlgorithmAES_CFB.h:
* crypto/algorithms/CryptoAlgorithmAES_CTR.cpp:
(WebCore::parametersAreValid):
(WebCore::CryptoAlgorithmAES_CTR::encrypt):
(WebCore::CryptoAlgorithmAES_CTR::decrypt):
(WebCore::CryptoAlgorithmAES_CTR::importKey):
* crypto/algorithms/CryptoAlgorithmAES_CTR.h:
* crypto/algorithms/CryptoAlgorithmAES_GCM.cpp:
(WebCore::CryptoAlgorithmAES_GCM::encrypt):
(WebCore::CryptoAlgorithmAES_GCM::decrypt):
(WebCore::CryptoAlgorithmAES_GCM::importKey):
* crypto/algorithms/CryptoAlgorithmAES_GCM.h:
* crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
(WebCore::CryptoAlgorithmAES_KW::importKey):
* crypto/algorithms/CryptoAlgorithmAES_KW.h:
* crypto/algorithms/CryptoAlgorithmECDH.cpp:
(WebCore::CryptoAlgorithmECDH::deriveBits):
(WebCore::CryptoAlgorithmECDH::importKey):
* crypto/algorithms/CryptoAlgorithmECDH.h:
* crypto/algorithms/CryptoAlgorithmECDSA.cpp:
(WebCore::CryptoAlgorithmECDSA::sign):
(WebCore::CryptoAlgorithmECDSA::verify):
(WebCore::CryptoAlgorithmECDSA::importKey):
* crypto/algorithms/CryptoAlgorithmECDSA.h:
* crypto/algorithms/CryptoAlgorithmHKDF.cpp:
(WebCore::CryptoAlgorithmHKDF::deriveBits):
(WebCore::CryptoAlgorithmHKDF::importKey):
* crypto/algorithms/CryptoAlgorithmHKDF.h:
* crypto/algorithms/CryptoAlgorithmHMAC.cpp:
(WebCore::CryptoAlgorithmHMAC::sign):
(WebCore::CryptoAlgorithmHMAC::verify):
(WebCore::CryptoAlgorithmHMAC::importKey):
* crypto/algorithms/CryptoAlgorithmHMAC.h:
* crypto/algorithms/CryptoAlgorithmPBKDF2.cpp:
(WebCore::CryptoAlgorithmPBKDF2::deriveBits):
(WebCore::CryptoAlgorithmPBKDF2::importKey):
* crypto/algorithms/CryptoAlgorithmPBKDF2.h:
* crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey):
* 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):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
* crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
(WebCore::CryptoAlgorithmRSA_OAEP::encrypt):
(WebCore::CryptoAlgorithmRSA_OAEP::decrypt):
(WebCore::CryptoAlgorithmRSA_OAEP::importKey):
* crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
* crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp:
(WebCore::CryptoAlgorithmRSA_PSS::sign):
(WebCore::CryptoAlgorithmRSA_PSS::verify):
(WebCore::CryptoAlgorithmRSA_PSS::importKey):
* crypto/algorithms/CryptoAlgorithmRSA_PSS.h:
* crypto/gcrypt/CryptoAlgorithmAES_CBCGCrypt.cpp:
(WebCore::CryptoAlgorithmAES_CBC::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
* crypto/gcrypt/CryptoAlgorithmAES_CFBGCrypt.cpp:
(WebCore::CryptoAlgorithmAES_CFB::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CFB::platformDecrypt):
* crypto/gcrypt/CryptoAlgorithmAES_CTRGCrypt.cpp:
(WebCore::CryptoAlgorithmAES_CTR::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CTR::platformDecrypt):
* crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:
(WebCore::CryptoAlgorithmAES_GCM::platformEncrypt):
(WebCore::CryptoAlgorithmAES_GCM::platformDecrypt):
* crypto/gcrypt/CryptoAlgorithmHKDFGCrypt.cpp:
(WebCore::CryptoAlgorithmHKDF::platformDeriveBits):
* crypto/gcrypt/CryptoAlgorithmPBKDF2GCrypt.cpp:
(WebCore::CryptoAlgorithmPBKDF2::platformDeriveBits):
* 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/CryptoAlgorithmAES_CBCMac.cpp:
(WebCore::CryptoAlgorithmAES_CBC::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
* crypto/mac/CryptoAlgorithmAES_CFBMac.cpp:
(WebCore::CryptoAlgorithmAES_CFB::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CFB::platformDecrypt):
* crypto/mac/CryptoAlgorithmAES_CTRMac.cpp:
(WebCore::CryptoAlgorithmAES_CTR::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CTR::platformDecrypt):
* crypto/mac/CryptoAlgorithmAES_GCMMac.cpp:
(WebCore::CryptoAlgorithmAES_GCM::platformEncrypt):
(WebCore::CryptoAlgorithmAES_GCM::platformDecrypt):
* crypto/mac/CryptoAlgorithmHKDFMac.cpp:
(WebCore::CryptoAlgorithmHKDF::platformDeriveBits):
* crypto/mac/CryptoAlgorithmPBKDF2Mac.cpp:
(WebCore::CryptoAlgorithmPBKDF2::platformDeriveBits):
* 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):
* crypto/parameters/CryptoAlgorithmAesCbcCfbParams.h:
* crypto/parameters/CryptoAlgorithmAesCtrParams.h:
* crypto/parameters/CryptoAlgorithmAesGcmParams.h:
* crypto/parameters/CryptoAlgorithmEcKeyParams.h:
* crypto/parameters/CryptoAlgorithmEcdsaParams.h:
* crypto/parameters/CryptoAlgorithmHkdfParams.h:
* crypto/parameters/CryptoAlgorithmHmacKeyParams.h:
* crypto/parameters/CryptoAlgorithmPbkdf2Params.h:
* crypto/parameters/CryptoAlgorithmRsaHashedImportParams.h:
* crypto/parameters/CryptoAlgorithmRsaOaepParams.h:
* crypto/parameters/CryptoAlgorithmRsaPssParams.h:

LayoutTests:

crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html is an exception of this series of tests as
it only aims to test the correct behavoir of suggested algorithms. This patch aslo does some test
gardening.

* TestExpectations:
* crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key-expected.txt: Added.
* crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html: Added.
* http/wpt/crypto/aes-cbc-crash.any-expected.txt: Added.
* http/wpt/crypto/aes-cbc-crash.any.html: Added.
* http/wpt/crypto/aes-cbc-crash.any.js: Added.
* http/wpt/crypto/aes-cbc-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/aes-cbc-crash.any.worker.html: Added.
* http/wpt/crypto/aes-ctr-crash.any-expected.txt: Added.
* http/wpt/crypto/aes-ctr-crash.any.html: Added.
* http/wpt/crypto/aes-ctr-crash.any.js: Added.
* http/wpt/crypto/aes-ctr-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/aes-ctr-crash.any.worker.html: Added.
* http/wpt/crypto/aes-gcm-crash.any-expected.txt: Added.
* http/wpt/crypto/aes-gcm-crash.any.html: Added.
* http/wpt/crypto/aes-gcm-crash.any.js: Added.
* http/wpt/crypto/aes-gcm-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/aes-gcm-crash.any.worker.html: Added.
* http/wpt/crypto/derive-hmac-key-crash.any-expected.txt: Added.
* http/wpt/crypto/derive-hmac-key-crash.any.html: Added.
* http/wpt/crypto/derive-hmac-key-crash.any.js: Added.
* http/wpt/crypto/derive-hmac-key-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/derive-hmac-key-crash.any.worker.html: Added.
* http/wpt/crypto/ecdsa-crash.any-expected.txt: Added.
* http/wpt/crypto/ecdsa-crash.any.html: Added.
* http/wpt/crypto/ecdsa-crash.any.js: Added.
* http/wpt/crypto/ecdsa-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/ecdsa-crash.any.worker.html: Added.
* http/wpt/crypto/hkdf-crash.any-expected.txt: Added.
* http/wpt/crypto/hkdf-crash.any.html: Added.
* http/wpt/crypto/hkdf-crash.any.js: Added.
* http/wpt/crypto/hkdf-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/hkdf-crash.any.worker.html: Added.
* http/wpt/crypto/pbkdf2-crash.any-expected.txt: Added.
* http/wpt/crypto/pbkdf2-crash.any.html: Added.
* http/wpt/crypto/pbkdf2-crash.any.js: Added.
* http/wpt/crypto/pbkdf2-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/pbkdf2-crash.any.worker.html: Added.
* http/wpt/crypto/resources/common.js: Added.
* http/wpt/crypto/rsa-oaep-crash.any-expected.txt: Added.
* http/wpt/crypto/rsa-oaep-crash.any.html: Added.
* http/wpt/crypto/rsa-oaep-crash.any.js: Added.
* http/wpt/crypto/rsa-oaep-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/rsa-oaep-crash.any.worker.html: Added.
* http/wpt/crypto/rsa-pss-crash.any-expected.txt: Added.
* http/wpt/crypto/rsa-pss-crash.any.html: Added.
* http/wpt/crypto/rsa-pss-crash.any.js: Added.
* http/wpt/crypto/rsa-pss-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/rsa-pss-crash.any.worker.html: Added.
* http/wpt/crypto/unwrap-ec-key-crash.any-expected.txt: Added.
* http/wpt/crypto/unwrap-ec-key-crash.any.html: Added.
* http/wpt/crypto/unwrap-ec-key-crash.any.js: Added.
* http/wpt/crypto/unwrap-ec-key-crash.any.worker-expected.txt: Added.
* http/wpt/crypto/unwrap-ec-key-crash.any.worker.html: Added.
* http/wpt/crypto/unwrap-rsa-key-crash.any-expected.txt: Added.
* http/wpt/crypto/unwrap-rsa-key-crash.any.html: Added.
* http/wpt/crypto/unwrap-rsa-key-crash.any.js: Added.
* http/wpt/crypto/unwrap-rsa-key-crash.any.worker.html: Added.
* http/wpt/crypto/unwrap-rsa-key-crash.any.worker-expected.txt: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233873 268f45cc-cd09-0410-ab3c-d52691b4dbfc

119 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-cbc-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-cbc-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-cbc-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-cbc-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-cbc-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-ctr-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-ctr-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-ctr-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-ctr-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-ctr-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-gcm-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-gcm-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-gcm-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-gcm-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/aes-gcm-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/ecdsa-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/ecdsa-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/ecdsa-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/ecdsa-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/ecdsa-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/hkdf-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/hkdf-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/hkdf-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/hkdf-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/hkdf-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/pbkdf2-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/pbkdf2-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/pbkdf2-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/pbkdf2-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/pbkdf2-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/resources/common.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-oaep-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-pss-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-pss-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-pss-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-pss-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/rsa-pss-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.worker.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.html [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.js [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.worker.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/crypto/CryptoAlgorithm.cpp
Source/WebCore/crypto/CryptoAlgorithm.h
Source/WebCore/crypto/SubtleCrypto.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CFB.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CFB.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CTR.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CTR.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmHKDF.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmHKDF.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmPBKDF2.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmPBKDF2.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_PSS.h
Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_CBCGCrypt.cpp
Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_CFBGCrypt.cpp
Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_CTRGCrypt.cpp
Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp
Source/WebCore/crypto/gcrypt/CryptoAlgorithmHKDFGCrypt.cpp
Source/WebCore/crypto/gcrypt/CryptoAlgorithmPBKDF2GCrypt.cpp
Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_OAEPGCrypt.cpp
Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSA_PSSGCrypt.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CFBMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CTRMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmAES_GCMMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmHKDFMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmPBKDF2Mac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmRSA_PSSMac.cpp
Source/WebCore/crypto/parameters/CryptoAlgorithmAesCbcCfbParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmAesCtrParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmAesGcmParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmEcKeyParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmEcdsaParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmHkdfParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmHmacKeyParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmPbkdf2Params.h
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaHashedImportParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaOaepParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaPssParams.h

index 5dfc932..744c5cf 100644 (file)
@@ -1,3 +1,75 @@
+2018-07-15  Jiewen Tan  <jiewen_tan@apple.com>
+
+        [WebCrypto] Crypto operations should copy their parameters before hoping to another thread
+        https://bugs.webkit.org/show_bug.cgi?id=187501
+        <rdar://problem/41438160>
+
+        Reviewed by Youenn Fablet.
+
+        crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html is an exception of this series of tests as
+        it only aims to test the correct behavoir of suggested algorithms. This patch aslo does some test
+        gardening.
+
+        * TestExpectations:
+        * crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key-expected.txt: Added.
+        * crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html: Added.
+        * http/wpt/crypto/aes-cbc-crash.any-expected.txt: Added.
+        * http/wpt/crypto/aes-cbc-crash.any.html: Added.
+        * http/wpt/crypto/aes-cbc-crash.any.js: Added.
+        * http/wpt/crypto/aes-cbc-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/aes-cbc-crash.any.worker.html: Added.
+        * http/wpt/crypto/aes-ctr-crash.any-expected.txt: Added.
+        * http/wpt/crypto/aes-ctr-crash.any.html: Added.
+        * http/wpt/crypto/aes-ctr-crash.any.js: Added.
+        * http/wpt/crypto/aes-ctr-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/aes-ctr-crash.any.worker.html: Added.
+        * http/wpt/crypto/aes-gcm-crash.any-expected.txt: Added.
+        * http/wpt/crypto/aes-gcm-crash.any.html: Added.
+        * http/wpt/crypto/aes-gcm-crash.any.js: Added.
+        * http/wpt/crypto/aes-gcm-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/aes-gcm-crash.any.worker.html: Added.
+        * http/wpt/crypto/derive-hmac-key-crash.any-expected.txt: Added.
+        * http/wpt/crypto/derive-hmac-key-crash.any.html: Added.
+        * http/wpt/crypto/derive-hmac-key-crash.any.js: Added.
+        * http/wpt/crypto/derive-hmac-key-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/derive-hmac-key-crash.any.worker.html: Added.
+        * http/wpt/crypto/ecdsa-crash.any-expected.txt: Added.
+        * http/wpt/crypto/ecdsa-crash.any.html: Added.
+        * http/wpt/crypto/ecdsa-crash.any.js: Added.
+        * http/wpt/crypto/ecdsa-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/ecdsa-crash.any.worker.html: Added.
+        * http/wpt/crypto/hkdf-crash.any-expected.txt: Added.
+        * http/wpt/crypto/hkdf-crash.any.html: Added.
+        * http/wpt/crypto/hkdf-crash.any.js: Added.
+        * http/wpt/crypto/hkdf-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/hkdf-crash.any.worker.html: Added.
+        * http/wpt/crypto/pbkdf2-crash.any-expected.txt: Added.
+        * http/wpt/crypto/pbkdf2-crash.any.html: Added.
+        * http/wpt/crypto/pbkdf2-crash.any.js: Added.
+        * http/wpt/crypto/pbkdf2-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/pbkdf2-crash.any.worker.html: Added.
+        * http/wpt/crypto/resources/common.js: Added.
+        * http/wpt/crypto/rsa-oaep-crash.any-expected.txt: Added.
+        * http/wpt/crypto/rsa-oaep-crash.any.html: Added.
+        * http/wpt/crypto/rsa-oaep-crash.any.js: Added.
+        * http/wpt/crypto/rsa-oaep-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/rsa-oaep-crash.any.worker.html: Added.
+        * http/wpt/crypto/rsa-pss-crash.any-expected.txt: Added.
+        * http/wpt/crypto/rsa-pss-crash.any.html: Added.
+        * http/wpt/crypto/rsa-pss-crash.any.js: Added.
+        * http/wpt/crypto/rsa-pss-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/rsa-pss-crash.any.worker.html: Added.
+        * http/wpt/crypto/unwrap-ec-key-crash.any-expected.txt: Added.
+        * http/wpt/crypto/unwrap-ec-key-crash.any.html: Added.
+        * http/wpt/crypto/unwrap-ec-key-crash.any.js: Added.
+        * http/wpt/crypto/unwrap-ec-key-crash.any.worker-expected.txt: Added.
+        * http/wpt/crypto/unwrap-ec-key-crash.any.worker.html: Added.
+        * http/wpt/crypto/unwrap-rsa-key-crash.any-expected.txt: Added.
+        * http/wpt/crypto/unwrap-rsa-key-crash.any.html: Added.
+        * http/wpt/crypto/unwrap-rsa-key-crash.any.js: Added.
+        * http/wpt/crypto/unwrap-rsa-key-crash.any.worker.html: Added.
+        * http/wpt/crypto/unwrap-rsa-key-crash.any.worker-expected.txt: Added.
+
 2018-07-16  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         [iOS] When bringing MobileSafari to the foreground, images, which are pending decoding, won't be drawn into the immediate-paint transaction
index 30cfb3c..d95195f 100644 (file)
@@ -1483,14 +1483,9 @@ workers/wasm-long-compile.html [ Slow ]
 
 # Flaky WebCrypto API tests
 imported/w3c/web-platform-tests/WebCryptoAPI/wrapKey_unwrapKey/test_wrapKey_unwrapKey.https.html [ Pass Failure ]
-imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/pbkdf2.https.worker.html [ Pass Failure Slow ]
-webkit.org/b/186940 imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_RSASSA-PKCS1-v1_5.https.any.html [ Pass Failure Slow ]
-webkit.org/b/186940 imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_RSA-PSS.https.any.html [ Pass Failure Slow ]
-webkit.org/b/187025 imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_RSASSA-PKCS1-v1_5.https.any.worker.html  [ Pass Failure Slow ]
 
 # WebCryptoAPI tests that take too long to complete
-imported/w3c/web-platform-tests/WebCryptoAPI/import_export/rsa_importKey.https.worker.html [ Slow ]
-imported/w3c/web-platform-tests/WebCryptoAPI/import_export/test_rsa_importKey.https.html [ Slow ]
+imported/w3c/web-platform-tests/WebCryptoAPI/ [ Slow ]
 
 # Imported Beacon test that is flaky because its last check is very slow.
 webkit.org/b/175202 imported/w3c/web-platform-tests/beacon/beacon-basic-string.html [ Pass Failure ]
diff --git a/LayoutTests/crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key-expected.txt b/LayoutTests/crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key-expected.txt
new file mode 100644 (file)
index 0000000..4b29490
--- /dev/null
@@ -0,0 +1,10 @@
+Test unwrapping an EC raw key with AES-GCM using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(unwrappedKey) is expectedRawKey
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html b/LayoutTests/crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html
new file mode 100644 (file)
index 0000000..a306dc2
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../resources/js-test-pre.js"></script>
+    <script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("Test unwrapping an EC raw key with AES-GCM using an imported key");
+
+    jsTestIsAsync = true;
+
+    var extractable = true;
+    var expectedRawKey = "04d454955a2793be2905906d4d3b286450268c6dd421c701fa682bb8133fac46d0f6398d4cba8ce1c8c185d0271dc348f58415dcef0b166a3e11d65693c9ed01a2";
+    var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+    var aesGcmParams = {
+        name: "aes-gcm",
+        iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+    };
+    var wrappedKey = hexStringToUint8Array("b50b299894672c25341db938ad7dc3f87f05e29a36e062b08f7022f9bb7ee41a6d503bfa460e63333c2d1b6fe5b62169276f511ed928cdf0ad9af40807b8a5674af07016e5af5476f6aec5266321e300eb");
+
+
+    crypto.subtle.importKey("raw", rawKey, "aes-gcm", extractable, ["unwrapKey"]).then(function(unwrappingKey) {
+        return crypto.subtle.unwrapKey("raw", wrappedKey, unwrappingKey, aesGcmParams, { name: "ECDH", namedCurve: "P-256" }, extractable, []);
+    }).then(function(cryptoKey) {
+        return crypto.subtle.exportKey("raw", cryptoKey);
+    }).then(function(result) {
+        unwrappedKey = result;
+
+        shouldBe("bytesToHexString(unwrappedKey)", "expectedRawKey");
+
+        finishJSTest();
+    });
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/wpt/crypto/aes-cbc-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/aes-cbc-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/aes-cbc-crash.any.html b/LayoutTests/http/wpt/crypto/aes-cbc-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/aes-cbc-crash.any.js b/LayoutTests/http/wpt/crypto/aes-cbc-crash.any.js
new file mode 100644 (file)
index 0000000..7147840
--- /dev/null
@@ -0,0 +1,15 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const plainText = asciiToUint8Array("Hello, World!");
+    const aesCbcParams = {
+        name: "aes-cbc",
+        iv: asciiToUint8Array("jnOw99oOZFLIEPMr")
+    };
+    const rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+    crypto.subtle.importKey('raw', rawKey, "aes-cbc", false, ["encrypt"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.encrypt(aesCbcParams, key, plainText);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/aes-cbc-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/aes-cbc-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/aes-cbc-crash.any.worker.html b/LayoutTests/http/wpt/crypto/aes-cbc-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/aes-ctr-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/aes-ctr-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/aes-ctr-crash.any.html b/LayoutTests/http/wpt/crypto/aes-ctr-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/aes-ctr-crash.any.js b/LayoutTests/http/wpt/crypto/aes-ctr-crash.any.js
new file mode 100644 (file)
index 0000000..508b9aa
--- /dev/null
@@ -0,0 +1,16 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const plainText = asciiToUint8Array("Hello, World!");
+    const aesCtrParams = {
+        name: "aes-ctr",
+        counter: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+        length: 8,
+    };
+    const rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+    crypto.subtle.importKey('raw', rawKey, "aes-ctr", false, ["encrypt"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.encrypt(aesCtrParams, key, plainText);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/aes-ctr-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/aes-ctr-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/aes-ctr-crash.any.worker.html b/LayoutTests/http/wpt/crypto/aes-ctr-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/aes-gcm-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/aes-gcm-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/aes-gcm-crash.any.html b/LayoutTests/http/wpt/crypto/aes-gcm-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/aes-gcm-crash.any.js b/LayoutTests/http/wpt/crypto/aes-gcm-crash.any.js
new file mode 100644 (file)
index 0000000..ff7b86e
--- /dev/null
@@ -0,0 +1,15 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const plainText = asciiToUint8Array("Hello, World!");
+    const aesGcmParams = {
+        name: "aes-gcm",
+        iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+    };
+    const rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+    crypto.subtle.importKey('raw', rawKey, "aes-gcm", false, ["encrypt"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.encrypt(aesGcmParams, key, plainText);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/aes-gcm-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/aes-gcm-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/aes-gcm-crash.any.worker.html b/LayoutTests/http/wpt/crypto/aes-gcm-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.html b/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.js b/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.js
new file mode 100644 (file)
index 0000000..05fe73d
--- /dev/null
@@ -0,0 +1,12 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+    const salt = asciiToUint8Array("jnOw99oO");
+    const info = asciiToUint8Array("jnOw99oO");
+    crypto.subtle.importKey("raw", rawKey, "HKDF", false, ["deriveKey"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.deriveKey({name: "HKDF", salt: salt, info: info, hash: "sha-1"}, key, {name: "hmac", hash: "sha-1"}, false, ['sign', 'verify']);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.worker.html b/LayoutTests/http/wpt/crypto/derive-hmac-key-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/ecdsa-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/ecdsa-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/ecdsa-crash.any.html b/LayoutTests/http/wpt/crypto/ecdsa-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/ecdsa-crash.any.js b/LayoutTests/http/wpt/crypto/ecdsa-crash.any.js
new file mode 100644 (file)
index 0000000..306d98f
--- /dev/null
@@ -0,0 +1,22 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const jwkPrivateKey = {
+        kty: "EC",
+        crv: "P-256",
+        x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA",
+        y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI",
+        d: "ppxBSov3N8_AUcisAuvmLV4yE8e_L_BLE8bZb9Z1Xjg",
+    };
+    const ecdsaParams = {
+        name: "ECDSA",
+        hash: "SHA-256",
+    };
+    const data = asciiToUint8Array("Hello, World!");
+
+    crypto.subtle.importKey("jwk", jwkPrivateKey, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.sign(ecdsaParams, key, data);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/ecdsa-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/ecdsa-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/ecdsa-crash.any.worker.html b/LayoutTests/http/wpt/crypto/ecdsa-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/hkdf-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/hkdf-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/hkdf-crash.any.html b/LayoutTests/http/wpt/crypto/hkdf-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/hkdf-crash.any.js b/LayoutTests/http/wpt/crypto/hkdf-crash.any.js
new file mode 100644 (file)
index 0000000..244c4cd
--- /dev/null
@@ -0,0 +1,12 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const rawKey = hexStringToUint8Array("0b0b0b0b0b0b0b0b0b0b0b");
+    const info = hexStringToUint8Array("f0f1f2f3f4f5f6f7f8f9");
+    const salt = hexStringToUint8Array("000102030405060708090a0b0c");
+    crypto.subtle.importKey("raw", rawKey, "HKDF", false, ["deriveBits"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.deriveBits({name: "HKDF", salt: salt, info: info, hash: "sha-1"}, key, 336);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/hkdf-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/hkdf-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/hkdf-crash.any.worker.html b/LayoutTests/http/wpt/crypto/hkdf-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/pbkdf2-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/pbkdf2-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/pbkdf2-crash.any.html b/LayoutTests/http/wpt/crypto/pbkdf2-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/pbkdf2-crash.any.js b/LayoutTests/http/wpt/crypto/pbkdf2-crash.any.js
new file mode 100644 (file)
index 0000000..e9d3988
--- /dev/null
@@ -0,0 +1,9 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    crypto.subtle.importKey('raw', new Uint8Array(32), {name: 'PBKDF2', hash: {name: 'SHA-256'}}, false, ['deriveBits']).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.deriveBits({name: 'PBKDF2', hash: {name: 'SHA-256'}, salt: new Uint8Array(32), iterations: 1000}, key, 256);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/pbkdf2-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/pbkdf2-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/pbkdf2-crash.any.worker.html b/LayoutTests/http/wpt/crypto/pbkdf2-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/resources/common.js b/LayoutTests/http/wpt/crypto/resources/common.js
new file mode 100644 (file)
index 0000000..5f5c15a
--- /dev/null
@@ -0,0 +1,23 @@
+function hexStringToUint8Array(hexString)
+{
+    if (hexString.length % 2 != 0)
+        throw "Invalid hexString";
+    var arrayBuffer = new Uint8Array(hexString.length / 2);
+
+    for (var i = 0; i < hexString.length; i += 2) {
+        var byteValue = parseInt(hexString.substr(i, 2), 16);
+        if (byteValue == NaN)
+            throw "Invalid hexString";
+        arrayBuffer[i/2] = byteValue;
+    }
+
+    return arrayBuffer;
+}
+
+function asciiToUint8Array(str)
+{
+    var chars = [];
+    for (var i = 0; i < str.length; ++i)
+        chars.push(str.charCodeAt(i));
+    return new Uint8Array(chars);
+}
diff --git a/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.html b/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.js b/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.js
new file mode 100644 (file)
index 0000000..698d288
--- /dev/null
@@ -0,0 +1,22 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const plainText = asciiToUint8Array("Hello, World!");
+    const jwkKey = {
+        kty: "RSA",
+        alg: "RSA-OAEP",
+        use: "enc",
+        key_ops: ["encrypt", "wrapKey"],
+        ext: true,
+        n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+        e: "AQAB"
+    };
+    const rsaOaepParams = {
+        name: "rsa-oaep"
+    };
+    crypto.subtle.importKey('jwk', jwkKey, {name: "RSA-OAEP", hash: "SHA-1"}, false, ["encrypt"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.encrypt(rsaOaepParams, key, plainText);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.worker.html b/LayoutTests/http/wpt/crypto/rsa-oaep-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/rsa-pss-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/rsa-pss-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/rsa-pss-crash.any.html b/LayoutTests/http/wpt/crypto/rsa-pss-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/rsa-pss-crash.any.js b/LayoutTests/http/wpt/crypto/rsa-pss-crash.any.js
new file mode 100644 (file)
index 0000000..ec8cb27
--- /dev/null
@@ -0,0 +1,30 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const jwkKey = {
+        kty: "RSA",
+        alg: "PS1",
+        use: "sig",
+        key_ops: ["sign"],
+        ext: true,
+        n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+        e: "AQAB",
+        d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
+        p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
+        q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
+        dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
+        dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
+        qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk",
+    };
+    const rsaPssParams = {
+        name: "RSA-PSS",
+        saltLength: 16
+    };
+    const data = asciiToUint8Array("Hello, World!");
+
+    crypto.subtle.importKey("jwk", jwkKey, { name: "RSA-PSS", hash: "SHA-1" }, false, ["sign"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.sign(rsaPssParams, key, data);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/rsa-pss-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/rsa-pss-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/rsa-pss-crash.any.worker.html b/LayoutTests/http/wpt/crypto/rsa-pss-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.html b/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.js b/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.js
new file mode 100644 (file)
index 0000000..8da71ba
--- /dev/null
@@ -0,0 +1,15 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const wrappedKey = hexStringToUint8Array( "b50b299894672c25341db938ad7dc3f87f05e29a36e062b08f7022f9bb7ee41a6d503bfa460e63333c2d1b6fe5b62169276f511ed928cdf0ad9af40807b8a5674af07016e5af5476f6aec5266321e300eb");
+    const rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+    const aesGcmParams = {
+        name: "aes-gcm",
+        iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+    };
+    crypto.subtle.importKey('raw', rawKey, "aes-gcm", false, ["unwrapKey"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.unwrapKey("raw", wrappedKey, key, aesGcmParams, { name: "ECDH", namedCurve: "P-256" }, false, [ ]);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.worker.html b/LayoutTests/http/wpt/crypto/unwrap-ec-key-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any-expected.txt b/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.html b/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.js b/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.js
new file mode 100644 (file)
index 0000000..a3b5d0e
--- /dev/null
@@ -0,0 +1,15 @@
+// META: script=./resources/common.js
+
+test(() => {
+    const max = 10000;
+    const wrappedKey = hexStringToUint8Array( "7aedac7ca0885c4c8340e7414b45b160a872c38eb56f25fa17eeb885abcbd72ce35fb0d8dcfa023dcb0bf94b0fe2a98a693b30e8a993207d646f2b14f673eddddc53815cb3b63cadf3b275bd0c387276e792fbdfd0bab94951ce109ff42ad4c739e5bd6e3f21140d0de7fbd3b60b8a05b29e1aae6385ced993546140a143db854d5b54e2a5d0be425d2aa8a4eee00b779a7b905c3e7fc4a91c37582871eb0b6daddba5d9497271e82e71589a31058fe0c38a7506f72acbc70f88139654cb1a26580f9c20b228c8f22865233d6a705eb68249a906f7d022ef28c84a5dccba26455391f4ce3572e9cfa50b7b4cefcdadf1eec50afc1df31a43f9dda40cd14524aa075b8f081a8b708ce1214b8ec0bd1c9a9af21596d7520b032a7588edaff8116e8710b47f8cda2caace8386cf176507c664f2757d3d728f6ea3be81abe58f36f751a32833d8689b7008a66b72d325ae729bb1064e88ace17c767c376d5c88eff8e8f1cf377639e66390614af43b4aa171fe144ad69c5a0d4d5d4129461da5250fb389b0eb0d53e65263a4b6265ad3fc0d375d42426f3ca1373c044aa47ec9973c77c46ae34f07ba6cc7d43c56438a9d678bf961f7bd7a4155f7cf813dd7a6fe434f04f052d86f5fc79813e85c0817f952e13e99ddea5d21d92e517a8f269a8da660c1d1432ad2d476bd2d13c1f3207b0a5c3f0f250fc195f406e89c1c107d5733cbaaacefc411ea7377880caa09847560b4dfe86f1ce8a0aac3d142eb9aa315a7e36383b5aa4f027f6ee6603053dd877e57755ae13a0b01453b3806610f98ed85ea574a2c040d0df9e861091f72a285fb563da4ac9d6098a2e4cf232455d8529e80ec8b9334690bca941caa8d8c6c2ebb29c73176c736b2e1cd897aaecdb7d51fbf2eeb5716bb441c0a2646643530f1618a5923b7fe3c6d8fcd55ec18ddbc5053d09af3f3ca058b3471d3cc327cdcdaa8a0dcada0dd3e52365d5ad2d36643769e8f274ef2020ce47975dceefb1fa3a4ff092927ebd2dc9017b4e36ab0591358a65c98d981f1e687e9cde16b3953b0f4b5a8f0b305fdfbbc60d11046d633a8c96e705290300a145a58f61983a3b95dc57615863faa2c217f3656a627b6a3e438ff55cd87c6462699a3db064213f30831e8be8d058ea6313af2d468904dfa544b4caf0598fcb2e59d5a1b4ee022f32e86b4ef0fd2e55ecb38edc114758d97718bc3c43f300614554a19320b7c7687d3d2218bb7fef7a01950c028c14f0bdede849924c0cab8161a7d0600d46f9e37bdbb7f7b2d3ca72e75eb6da10e015c5c2bed171ac50ff94a3291a6fc5b5a093d4c9cfbc269fc4f295c881676706f1fadda515c6f9441f5f05af0a8255706b18f8b76bf4b5f729cddea05b099470f02f71df46a3b0b53ec5429bdfd29c9c50f72c0359bdf4ee7435dcbc415fa5b2633ebdc5d6213fe5eefcfdeda6a14b9f4d9ba837afae59549a31428a9ead0c3e32c66cf93e42d5b0266e0ad7d6ed5027923c6d0eb8191f55d987a2ebf4c87f4d49c1b75c3e938c8c54d502877e54ef1fbae0851e6b55c3fbc443fe6ae1ef97aa4d4c4a0dd7a74191fa72bf1f127b63001f36c9b3d1bb8d9d1fe609cf24423b84cc96afed8e38508efb9bf01638ca75abcc46fc371aac26c493ee9b0a71c95e310eeb30460ef6baf622cbc74c89b01558d0913e4394369a782d3536c8ca0b90aaf087004a7d18836c0b9d45a48fd235a12e687d80c6e");
+    const rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+    const aesCbcParams = {
+        name: "aes-cbc",
+        iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+    };
+    crypto.subtle.importKey('raw', rawKey, "aes-cbc", false, ["unwrapKey"]).then(key => {
+        for (let i = 0; i < max; i++)
+            crypto.subtle.unwrapKey("pkcs8", wrappedKey, key, aesCbcParams, {name: "rsa-oaep", hash: "sha-1"}, false, ["decrypt"]);
+    });
+}, "Test passed if no crashes.");
diff --git a/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.worker-expected.txt b/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..f1aa120
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test passed if no crashes. 
+
diff --git a/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.worker.html b/LayoutTests/http/wpt/crypto/unwrap-rsa-key-crash.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
index ae41084..aecfda7 100644 (file)
@@ -1,3 +1,189 @@
+2018-07-15  Jiewen Tan  <jiewen_tan@apple.com>
+
+        [WebCrypto] Crypto operations should copy their parameters before hoping to another thread
+        https://bugs.webkit.org/show_bug.cgi?id=187501
+        <rdar://problem/41438160>
+
+        Reviewed by Youenn Fablet.
+
+        This patch aims at making all captured variables in all crypto lambdas that need to be passed
+        to a worker thread thread safe, which includes:
+        1) changing ref counted objects to thread safe ref counted object.
+        2) adding isolatedCopy methods to non ref counted classes, so they can be called by CrossThreadCopy().
+
+        In addition to above changes, this patch also does the following things:
+        1) change the name CryptoAlgorithm::dispatchOperation => CryptoAlgorithm::dispatchOperationInWorkQueue
+        to make it clear that lambdas will be passed to a secondary thread.
+        2) make CryptoAlgorithmParameters as const parameters for all methods.
+
+        Tests: crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html
+               http/wpt/crypto/aes-cbc-crash.any.html
+               http/wpt/crypto/aes-cbc-crash.any.worker.html
+               http/wpt/crypto/aes-ctr-crash.any.html
+               http/wpt/crypto/aes-ctr-crash.any.worker.html
+               http/wpt/crypto/aes-gcm-crash.any.html
+               http/wpt/crypto/aes-gcm-crash.any.worker.html
+               http/wpt/crypto/derive-hmac-key-crash.any.html
+               http/wpt/crypto/derive-hmac-key-crash.any.worker.html
+               http/wpt/crypto/ecdsa-crash.any.html
+               http/wpt/crypto/ecdsa-crash.any.worker.html
+               http/wpt/crypto/hkdf-crash.any.html
+               http/wpt/crypto/hkdf-crash.any.worker.html
+               http/wpt/crypto/pbkdf2-crash.any.html
+               http/wpt/crypto/pbkdf2-crash.any.worker.html
+               http/wpt/crypto/rsa-oaep-crash.any.html
+               http/wpt/crypto/rsa-oaep-crash.any.worker.html
+               http/wpt/crypto/rsa-pss-crash.any.html
+               http/wpt/crypto/rsa-pss-crash.any.worker.html
+               http/wpt/crypto/unwrap-ec-key-crash.any.html
+               http/wpt/crypto/unwrap-ec-key-crash.any.worker.html
+               http/wpt/crypto/unwrap-rsa-key-crash.any.html
+               http/wpt/crypto/unwrap-rsa-key-crash.any.worker.html
+
+        * crypto/CryptoAlgorithm.cpp:
+        (WebCore::CryptoAlgorithm::encrypt):
+        (WebCore::CryptoAlgorithm::decrypt):
+        (WebCore::CryptoAlgorithm::sign):
+        (WebCore::CryptoAlgorithm::verify):
+        (WebCore::CryptoAlgorithm::deriveBits):
+        (WebCore::CryptoAlgorithm::importKey):
+        (WebCore::dispatchAlgorithmOperation):
+        (WebCore::CryptoAlgorithm::dispatchOperationInWorkQueue):
+        (WebCore::CryptoAlgorithm::dispatchOperation): Deleted.
+        * crypto/CryptoAlgorithm.h:
+        * crypto/SubtleCrypto.cpp:
+        (WebCore::crossThreadCopyImportParams):
+        (WebCore::SubtleCrypto::encrypt):
+        (WebCore::SubtleCrypto::decrypt):
+        (WebCore::SubtleCrypto::sign):
+        (WebCore::SubtleCrypto::verify):
+        (WebCore::SubtleCrypto::deriveKey):
+        (WebCore::SubtleCrypto::deriveBits):
+        (WebCore::SubtleCrypto::importKey):
+        (WebCore::SubtleCrypto::wrapKey):
+        (WebCore::SubtleCrypto::unwrapKey):
+        * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
+        (WebCore::CryptoAlgorithmAES_CBC::encrypt):
+        (WebCore::CryptoAlgorithmAES_CBC::decrypt):
+        (WebCore::CryptoAlgorithmAES_CBC::importKey):
+        * crypto/algorithms/CryptoAlgorithmAES_CBC.h:
+        * crypto/algorithms/CryptoAlgorithmAES_CFB.cpp:
+        (WebCore::CryptoAlgorithmAES_CFB::encrypt):
+        (WebCore::CryptoAlgorithmAES_CFB::decrypt):
+        (WebCore::CryptoAlgorithmAES_CFB::importKey):
+        * crypto/algorithms/CryptoAlgorithmAES_CFB.h:
+        * crypto/algorithms/CryptoAlgorithmAES_CTR.cpp:
+        (WebCore::parametersAreValid):
+        (WebCore::CryptoAlgorithmAES_CTR::encrypt):
+        (WebCore::CryptoAlgorithmAES_CTR::decrypt):
+        (WebCore::CryptoAlgorithmAES_CTR::importKey):
+        * crypto/algorithms/CryptoAlgorithmAES_CTR.h:
+        * crypto/algorithms/CryptoAlgorithmAES_GCM.cpp:
+        (WebCore::CryptoAlgorithmAES_GCM::encrypt):
+        (WebCore::CryptoAlgorithmAES_GCM::decrypt):
+        (WebCore::CryptoAlgorithmAES_GCM::importKey):
+        * crypto/algorithms/CryptoAlgorithmAES_GCM.h:
+        * crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
+        (WebCore::CryptoAlgorithmAES_KW::importKey):
+        * crypto/algorithms/CryptoAlgorithmAES_KW.h:
+        * crypto/algorithms/CryptoAlgorithmECDH.cpp:
+        (WebCore::CryptoAlgorithmECDH::deriveBits):
+        (WebCore::CryptoAlgorithmECDH::importKey):
+        * crypto/algorithms/CryptoAlgorithmECDH.h:
+        * crypto/algorithms/CryptoAlgorithmECDSA.cpp:
+        (WebCore::CryptoAlgorithmECDSA::sign):
+        (WebCore::CryptoAlgorithmECDSA::verify):
+        (WebCore::CryptoAlgorithmECDSA::importKey):
+        * crypto/algorithms/CryptoAlgorithmECDSA.h:
+        * crypto/algorithms/CryptoAlgorithmHKDF.cpp:
+        (WebCore::CryptoAlgorithmHKDF::deriveBits):
+        (WebCore::CryptoAlgorithmHKDF::importKey):
+        * crypto/algorithms/CryptoAlgorithmHKDF.h:
+        * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
+        (WebCore::CryptoAlgorithmHMAC::sign):
+        (WebCore::CryptoAlgorithmHMAC::verify):
+        (WebCore::CryptoAlgorithmHMAC::importKey):
+        * crypto/algorithms/CryptoAlgorithmHMAC.h:
+        * crypto/algorithms/CryptoAlgorithmPBKDF2.cpp:
+        (WebCore::CryptoAlgorithmPBKDF2::deriveBits):
+        (WebCore::CryptoAlgorithmPBKDF2::importKey):
+        * crypto/algorithms/CryptoAlgorithmPBKDF2.h:
+        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt):
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt):
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey):
+        * 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):
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
+        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
+        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
+        (WebCore::CryptoAlgorithmRSA_OAEP::encrypt):
+        (WebCore::CryptoAlgorithmRSA_OAEP::decrypt):
+        (WebCore::CryptoAlgorithmRSA_OAEP::importKey):
+        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
+        * crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp:
+        (WebCore::CryptoAlgorithmRSA_PSS::sign):
+        (WebCore::CryptoAlgorithmRSA_PSS::verify):
+        (WebCore::CryptoAlgorithmRSA_PSS::importKey):
+        * crypto/algorithms/CryptoAlgorithmRSA_PSS.h:
+        * crypto/gcrypt/CryptoAlgorithmAES_CBCGCrypt.cpp:
+        (WebCore::CryptoAlgorithmAES_CBC::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
+        * crypto/gcrypt/CryptoAlgorithmAES_CFBGCrypt.cpp:
+        (WebCore::CryptoAlgorithmAES_CFB::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_CFB::platformDecrypt):
+        * crypto/gcrypt/CryptoAlgorithmAES_CTRGCrypt.cpp:
+        (WebCore::CryptoAlgorithmAES_CTR::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_CTR::platformDecrypt):
+        * crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:
+        (WebCore::CryptoAlgorithmAES_GCM::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_GCM::platformDecrypt):
+        * crypto/gcrypt/CryptoAlgorithmHKDFGCrypt.cpp:
+        (WebCore::CryptoAlgorithmHKDF::platformDeriveBits):
+        * crypto/gcrypt/CryptoAlgorithmPBKDF2GCrypt.cpp:
+        (WebCore::CryptoAlgorithmPBKDF2::platformDeriveBits):
+        * 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/CryptoAlgorithmAES_CBCMac.cpp:
+        (WebCore::CryptoAlgorithmAES_CBC::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
+        * crypto/mac/CryptoAlgorithmAES_CFBMac.cpp:
+        (WebCore::CryptoAlgorithmAES_CFB::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_CFB::platformDecrypt):
+        * crypto/mac/CryptoAlgorithmAES_CTRMac.cpp:
+        (WebCore::CryptoAlgorithmAES_CTR::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_CTR::platformDecrypt):
+        * crypto/mac/CryptoAlgorithmAES_GCMMac.cpp:
+        (WebCore::CryptoAlgorithmAES_GCM::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_GCM::platformDecrypt):
+        * crypto/mac/CryptoAlgorithmHKDFMac.cpp:
+        (WebCore::CryptoAlgorithmHKDF::platformDeriveBits):
+        * crypto/mac/CryptoAlgorithmPBKDF2Mac.cpp:
+        (WebCore::CryptoAlgorithmPBKDF2::platformDeriveBits):
+        * 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):
+        * crypto/parameters/CryptoAlgorithmAesCbcCfbParams.h:
+        * crypto/parameters/CryptoAlgorithmAesCtrParams.h:
+        * crypto/parameters/CryptoAlgorithmAesGcmParams.h:
+        * crypto/parameters/CryptoAlgorithmEcKeyParams.h:
+        * crypto/parameters/CryptoAlgorithmEcdsaParams.h:
+        * crypto/parameters/CryptoAlgorithmHkdfParams.h:
+        * crypto/parameters/CryptoAlgorithmHmacKeyParams.h:
+        * crypto/parameters/CryptoAlgorithmPbkdf2Params.h:
+        * crypto/parameters/CryptoAlgorithmRsaHashedImportParams.h:
+        * crypto/parameters/CryptoAlgorithmRsaOaepParams.h:
+        * crypto/parameters/CryptoAlgorithmRsaPssParams.h:
+
 2018-07-16  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         [iOS] When bringing MobileSafari to the foreground, images, which are pending decoding, won't be drawn into the flush immediate transaction
index 4bfbd7d..c4111a3 100644 (file)
 
 namespace WebCore {
 
-void CryptoAlgorithm::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
+void CryptoAlgorithm::encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
 {
     exceptionCallback(NotSupportedError);
 }
 
-void CryptoAlgorithm::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
+void CryptoAlgorithm::decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
 {
     exceptionCallback(NotSupportedError);
 }
 
-void CryptoAlgorithm::sign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
+void CryptoAlgorithm::sign(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
 {
     exceptionCallback(NotSupportedError);
 }
 
-void CryptoAlgorithm::verify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
+void CryptoAlgorithm::verify(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
 {
     exceptionCallback(NotSupportedError);
 }
@@ -62,12 +62,12 @@ void CryptoAlgorithm::generateKey(const CryptoAlgorithmParameters&, bool, Crypto
     exceptionCallback(NotSupportedError);
 }
 
-void CryptoAlgorithm::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, size_t, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
+void CryptoAlgorithm::deriveBits(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, size_t, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
 {
     exceptionCallback(NotSupportedError);
 }
 
-void CryptoAlgorithm::importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithm::importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&& exceptionCallback)
 {
     exceptionCallback(NotSupportedError);
 }
@@ -95,7 +95,6 @@ ExceptionOr<size_t> CryptoAlgorithm::getKeyLength(const CryptoAlgorithmParameter
 template<typename ResultCallbackType, typename OperationType>
 static void dispatchAlgorithmOperation(WorkQueue& workQueue, ScriptExecutionContext& context, ResultCallbackType&& callback, CryptoAlgorithm::ExceptionCallback&& exceptionCallback, OperationType&& operation)
 {
-    // There is no guarantee that callback and exceptionCallback will be destroyed in the thread in which they were created.
     workQueue.dispatch(
         [operation = WTFMove(operation), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), contextIdentifier = context.contextIdentifier()]() mutable {
             auto result = operation();
@@ -109,12 +108,12 @@ static void dispatchAlgorithmOperation(WorkQueue& workQueue, ScriptExecutionCont
         });
 }
 
-void CryptoAlgorithm::dispatchOperation(WorkQueue& workQueue, ScriptExecutionContext& context, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, WTF::Function<ExceptionOr<Vector<uint8_t>>()>&& operation)
+void CryptoAlgorithm::dispatchOperationInWorkQueue(WorkQueue& workQueue, ScriptExecutionContext& context, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, WTF::Function<ExceptionOr<Vector<uint8_t>>()>&& operation)
 {
     dispatchAlgorithmOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback), WTFMove(operation));
 }
 
-void CryptoAlgorithm::dispatchOperation(WorkQueue& workQueue, ScriptExecutionContext& context, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, WTF::Function<ExceptionOr<bool>()>&& operation)
+void CryptoAlgorithm::dispatchOperationInWorkQueue(WorkQueue& workQueue, ScriptExecutionContext& context, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, WTF::Function<ExceptionOr<bool>()>&& operation)
 {
     dispatchAlgorithmOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback), WTFMove(operation));
 }
index e708213..1ed8aa3 100644 (file)
@@ -33,6 +33,7 @@
 #include "JsonWebKey.h"
 #include "SubtleCrypto.h"
 #include <wtf/Function.h>
+#include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/Variant.h>
 #include <wtf/Vector.h>
 #include <wtf/WorkQueue.h>
@@ -48,7 +49,7 @@ class ScriptExecutionContext;
 using KeyData = Variant<Vector<uint8_t>, JsonWebKey>;
 using KeyOrKeyPair = Variant<RefPtr<CryptoKey>, CryptoKeyPair>;
 
-class CryptoAlgorithm : public RefCounted<CryptoAlgorithm> {
+class CryptoAlgorithm : public ThreadSafeRefCounted<CryptoAlgorithm> {
 public:
     virtual ~CryptoAlgorithm() = default;
 
@@ -63,22 +64,22 @@ public:
     using ExceptionCallback = WTF::Function<void(ExceptionCode)>;
     using KeyDataCallback = WTF::Function<void(CryptoKeyFormat, KeyData&&)>;
 
-    virtual void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
-    virtual void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
-    virtual void sign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
-    virtual void verify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+    virtual void encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+    virtual void decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+    virtual void sign(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+    virtual void verify(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     virtual void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&);
-    virtual void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+    virtual void deriveBits(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=169262
-    virtual void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&);
+    virtual void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&);
     virtual void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&);
     virtual void wrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&);
     virtual void unwrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&);
     virtual ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&);
 
-    static void dispatchOperation(WorkQueue&, ScriptExecutionContext&, VectorCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<Vector<uint8_t>>()>&&);
-    static void dispatchOperation(WorkQueue&, ScriptExecutionContext&, BoolCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<bool>()>&&);
+    static void dispatchOperationInWorkQueue(WorkQueue&, ScriptExecutionContext&, VectorCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<Vector<uint8_t>>()>&&);
+    static void dispatchOperationInWorkQueue(WorkQueue&, ScriptExecutionContext&, BoolCallback&&, ExceptionCallback&&, WTF::Function<ExceptionOr<bool>()>&&);
 };
 
 } // namespace WebCore
index 8673642..bf7ef46 100644 (file)
@@ -516,6 +516,26 @@ RefPtr<DeferredPromise> getPromise(DeferredPromise* index, WeakPtr<SubtleCrypto>
     return nullptr;
 }
 
+static std::unique_ptr<CryptoAlgorithmParameters> crossThreadCopyImportParams(const CryptoAlgorithmParameters& importParams)
+{
+    switch (importParams.parametersClass()) {
+    case CryptoAlgorithmParameters::Class::None: {
+        auto result = std::make_unique<CryptoAlgorithmRsaHashedImportParams>();
+        result->identifier = importParams.identifier;
+        return result;
+    }
+    case CryptoAlgorithmParameters::Class::EcKeyParams:
+        return std::make_unique<CryptoAlgorithmEcKeyParams>(crossThreadCopy(downcast<CryptoAlgorithmEcKeyParams>(importParams)));
+    case CryptoAlgorithmParameters::Class::HmacKeyParams:
+        return std::make_unique<CryptoAlgorithmHmacKeyParams>(crossThreadCopy(downcast<CryptoAlgorithmHmacKeyParams>(importParams)));
+    case CryptoAlgorithmParameters::Class::RsaHashedImportParams:
+        return std::make_unique<CryptoAlgorithmRsaHashedImportParams>(crossThreadCopy(downcast<CryptoAlgorithmRsaHashedImportParams>(importParams)));
+    default:
+        ASSERT_NOT_REACHED();
+        return nullptr;
+    }
+}
+
 // MARK: - Exposed functions.
 
 void SubtleCrypto::encrypt(JSC::ExecState& state, AlgorithmIdentifier&& algorithmIdentifier, CryptoKey& key, BufferSource&& dataBufferSource, Ref<DeferredPromise>&& promise)
@@ -553,7 +573,7 @@ void SubtleCrypto::encrypt(JSC::ExecState& state, AlgorithmIdentifier&& algorith
             rejectWithException(promise.releaseNonNull(), ec);
     };
 
-    algorithm->encrypt(WTFMove(params), key, WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
+    algorithm->encrypt(*params, key, WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
 }
 
 void SubtleCrypto::decrypt(JSC::ExecState& state, AlgorithmIdentifier&& algorithmIdentifier, CryptoKey& key, BufferSource&& dataBufferSource, Ref<DeferredPromise>&& promise)
@@ -591,7 +611,7 @@ void SubtleCrypto::decrypt(JSC::ExecState& state, AlgorithmIdentifier&& algorith
             rejectWithException(promise.releaseNonNull(), ec);
     };
 
-    algorithm->decrypt(WTFMove(params), key, WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
+    algorithm->decrypt(*params, key, WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
 }
 
 void SubtleCrypto::sign(JSC::ExecState& state, AlgorithmIdentifier&& algorithmIdentifier, CryptoKey& key, BufferSource&& dataBufferSource, Ref<DeferredPromise>&& promise)
@@ -629,7 +649,7 @@ void SubtleCrypto::sign(JSC::ExecState& state, AlgorithmIdentifier&& algorithmId
             rejectWithException(promise.releaseNonNull(), ec);
     };
 
-    algorithm->sign(WTFMove(params), key, WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
+    algorithm->sign(*params, key, WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
 }
 
 void SubtleCrypto::verify(JSC::ExecState& state, AlgorithmIdentifier&& algorithmIdentifier, CryptoKey& key, BufferSource&& signatureBufferSource, BufferSource&& dataBufferSource, Ref<DeferredPromise>&& promise)
@@ -668,7 +688,7 @@ void SubtleCrypto::verify(JSC::ExecState& state, AlgorithmIdentifier&& algorithm
             rejectWithException(promise.releaseNonNull(), ec);
     };
 
-    algorithm->verify(WTFMove(params), key, WTFMove(signature), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
+    algorithm->verify(*params, key, WTFMove(signature), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
 }
 
 void SubtleCrypto::digest(JSC::ExecState& state, AlgorithmIdentifier&& algorithmIdentifier, BufferSource&& dataBufferSource, Ref<DeferredPromise>&& promise)
@@ -796,7 +816,7 @@ void SubtleCrypto::deriveKey(JSC::ExecState& state, AlgorithmIdentifier&& algori
     auto index = promise.ptr();
     m_pendingPromises.add(index, WTFMove(promise));
     auto subtleCryptoWeakPointer = makeWeakPtr(*this);
-    auto callback = [index, subtleCryptoWeakPointer, importAlgorithm, importParams = WTFMove(importParams), extractable, keyUsagesBitmap](const Vector<uint8_t>& derivedKey) mutable {
+    auto callback = [index, subtleCryptoWeakPointer, importAlgorithm = WTFMove(importAlgorithm), importParams = crossThreadCopyImportParams(*importParams), extractable, keyUsagesBitmap](const Vector<uint8_t>& derivedKey) mutable {
         // FIXME: https://bugs.webkit.org/show_bug.cgi?id=169395
         KeyData data = derivedKey;
         auto callback = [index, subtleCryptoWeakPointer](CryptoKey& key) mutable {
@@ -813,14 +833,14 @@ void SubtleCrypto::deriveKey(JSC::ExecState& state, AlgorithmIdentifier&& algori
                 rejectWithException(promise.releaseNonNull(), ec);
         };
 
-        importAlgorithm->importKey(SubtleCrypto::KeyFormat::Raw, WTFMove(data), WTFMove(importParams), extractable, keyUsagesBitmap, WTFMove(callback), WTFMove(exceptionCallback));
+        importAlgorithm->importKey(SubtleCrypto::KeyFormat::Raw, WTFMove(data), *importParams, extractable, keyUsagesBitmap, WTFMove(callback), WTFMove(exceptionCallback));
     };
     auto exceptionCallback = [index, subtleCryptoWeakPointer](ExceptionCode ec) mutable {
         if (auto promise = getPromise(index, subtleCryptoWeakPointer))
             rejectWithException(promise.releaseNonNull(), ec);
     };
 
-    algorithm->deriveBits(WTFMove(params), baseKey, length, WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
+    algorithm->deriveBits(*params, baseKey, length, WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
 }
 
 void SubtleCrypto::deriveBits(JSC::ExecState& state, AlgorithmIdentifier&& algorithmIdentifier, CryptoKey& baseKey, unsigned length, Ref<DeferredPromise>&& promise)
@@ -856,7 +876,7 @@ void SubtleCrypto::deriveBits(JSC::ExecState& state, AlgorithmIdentifier&& algor
             rejectWithException(promise.releaseNonNull(), ec);
     };
 
-    algorithm->deriveBits(WTFMove(params), baseKey, length, WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
+    algorithm->deriveBits(*params, baseKey, length, WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
 }
 
 void SubtleCrypto::importKey(JSC::ExecState& state, KeyFormat format, KeyDataVariant&& keyDataVariant, AlgorithmIdentifier&& algorithmIdentifier, bool extractable, Vector<CryptoKeyUsage>&& keyUsages, Ref<DeferredPromise>&& promise)
@@ -899,7 +919,7 @@ void SubtleCrypto::importKey(JSC::ExecState& state, KeyFormat format, KeyDataVar
     // The 11 December 2014 version of the specification suggests we should perform the following task asynchronously:
     // https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-importKey
     // It is not beneficial for less time consuming operations. Therefore, we perform it synchronously.
-    algorithm->importKey(format, WTFMove(keyData), WTFMove(params), extractable, keyUsagesBitmap, WTFMove(callback), WTFMove(exceptionCallback));
+    algorithm->importKey(format, WTFMove(keyData), *params, extractable, keyUsagesBitmap, WTFMove(callback), WTFMove(exceptionCallback));
 }
 
 void SubtleCrypto::exportKey(KeyFormat format, CryptoKey& key, Ref<DeferredPromise>&& promise)
@@ -1029,7 +1049,7 @@ void SubtleCrypto::wrapKey(JSC::ExecState& state, KeyFormat format, CryptoKey& k
                     return;
                 }
                 // The following operation should be performed asynchronously.
-                wrapAlgorithm->encrypt(WTFMove(wrapParams), WTFMove(wrappingKey), WTFMove(bytes), WTFMove(callback), WTFMove(exceptionCallback), *context, workQueue);
+                wrapAlgorithm->encrypt(*wrapParams, WTFMove(wrappingKey), WTFMove(bytes), WTFMove(callback), WTFMove(exceptionCallback), *context, workQueue);
             }
         }
     };
@@ -1096,7 +1116,7 @@ void SubtleCrypto::unwrapKey(JSC::ExecState& state, KeyFormat format, BufferSour
     auto index = promise.ptr();
     m_pendingPromises.add(index, WTFMove(promise));
     auto subtleCryptoWeakPointer = makeWeakPtr(*this);
-    auto callback = [index, subtleCryptoWeakPointer, format, importAlgorithm, unwrappedKeyAlgorithm = WTFMove(unwrappedKeyAlgorithm), extractable, keyUsagesBitmap](const Vector<uint8_t>& bytes) mutable {
+    auto callback = [index, subtleCryptoWeakPointer, format, importAlgorithm, unwrappedKeyAlgorithm = crossThreadCopyImportParams(*unwrappedKeyAlgorithm), extractable, keyUsagesBitmap](const Vector<uint8_t>& bytes) mutable {
         if (subtleCryptoWeakPointer) {
             if (auto promise = subtleCryptoWeakPointer->m_pendingPromises.get(index)) {
                 KeyData keyData;
@@ -1142,7 +1162,7 @@ void SubtleCrypto::unwrapKey(JSC::ExecState& state, KeyFormat format, BufferSour
                 };
 
                 // The following operation should be performed synchronously.
-                importAlgorithm->importKey(format, WTFMove(keyData), WTFMove(unwrappedKeyAlgorithm), extractable, keyUsagesBitmap, WTFMove(callback), WTFMove(exceptionCallback));
+                importAlgorithm->importKey(format, WTFMove(keyData), *unwrappedKeyAlgorithm, extractable, keyUsagesBitmap, WTFMove(callback), WTFMove(exceptionCallback));
             }
         }
     };
@@ -1159,7 +1179,7 @@ void SubtleCrypto::unwrapKey(JSC::ExecState& state, KeyFormat format, BufferSour
         return;
     }
 
-    unwrapAlgorithm->decrypt(WTFMove(unwrapParams), unwrappingKey, WTFMove(wrappedKey), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
+    unwrapAlgorithm->decrypt(*unwrapParams, unwrappingKey, WTFMove(wrappedKey), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContext(), m_workQueue);
 }
 
 }
index c2f7558..5a87b77 100644 (file)
@@ -31,6 +31,7 @@
 #include "CryptoAlgorithmAesCbcCfbParams.h"
 #include "CryptoAlgorithmAesKeyParams.h"
 #include "CryptoKeyAES.h"
+#include <wtf/CrossThreadCopier.h>
 
 namespace WebCore {
 
@@ -56,35 +57,35 @@ CryptoAlgorithmIdentifier CryptoAlgorithmAES_CBC::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmAES_CBC::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     using namespace CryptoAlgorithmAES_CBCInternal;
-    ASSERT(parameters);
-    auto& aesParameters = downcast<CryptoAlgorithmAesCbcCfbParams>(*parameters);
+
+    auto& aesParameters = downcast<CryptoAlgorithmAesCbcCfbParams>(parameters);
     if (aesParameters.ivVector().size() != IVSIZE) {
         exceptionCallback(OperationError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
-            return platformEncrypt(downcast<CryptoAlgorithmAesCbcCfbParams>(*parameters), downcast<CryptoKeyAES>(key.get()), plainText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(aesParameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
+            return platformEncrypt(parameters, downcast<CryptoKeyAES>(key.get()), plainText);
         });
 }
 
-void CryptoAlgorithmAES_CBC::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     using namespace CryptoAlgorithmAES_CBCInternal;
-    ASSERT(parameters);
-    auto& aesParameters = downcast<CryptoAlgorithmAesCbcCfbParams>(*parameters);
+
+    auto& aesParameters = downcast<CryptoAlgorithmAesCbcCfbParams>(parameters);
     if (aesParameters.ivVector().size() != IVSIZE) {
         exceptionCallback(OperationError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
-            return platformDecrypt(downcast<CryptoAlgorithmAesCbcCfbParams>(*parameters), downcast<CryptoKeyAES>(key.get()), cipherText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(aesParameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
+            return platformDecrypt(parameters, downcast<CryptoKeyAES>(key.get()), cipherText);
         });
 }
 
@@ -106,10 +107,10 @@ void CryptoAlgorithmAES_CBC::generateKey(const CryptoAlgorithmParameters& parame
     callback(WTFMove(result));
 }
 
-void CryptoAlgorithmAES_CBC::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmAES_CBC::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace CryptoAlgorithmAES_CBCInternal;
-    ASSERT(parameters);
+
     if (usagesAreInvalidForCryptoAlgorithmAES_CBC(usages)) {
         exceptionCallback(SyntaxError);
         return;
@@ -118,7 +119,7 @@ void CryptoAlgorithmAES_CBC::importKey(CryptoKeyFormat format, KeyData&& data, c
     RefPtr<CryptoKeyAES> result;
     switch (format) {
     case CryptoKeyFormat::Raw:
-        result = CryptoKeyAES::importRaw(parameters->identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyAES::importRaw(parameters.identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     case CryptoKeyFormat::Jwk: {
         auto checkAlgCallback = [](size_t length, const String& alg) -> bool {
@@ -132,7 +133,7 @@ void CryptoAlgorithmAES_CBC::importKey(CryptoKeyFormat format, KeyData&& data, c
             }
             return false;
         };
-        result = CryptoKeyAES::importJwk(parameters->identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, WTFMove(checkAlgCallback));
+        result = CryptoKeyAES::importJwk(parameters.identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, WTFMove(checkAlgCallback));
         break;
     }
     default:
index ab25bc2..1fd8f50 100644 (file)
@@ -44,15 +44,15 @@ private:
     CryptoAlgorithmAES_CBC() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
 
-    static ExceptionOr<Vector<uint8_t>> platformEncrypt(CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
-    static ExceptionOr<Vector<uint8_t>> platformDecrypt(CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformEncrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformDecrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
 };
 
 } // namespace WebCore
index 3a11311..51c333a 100644 (file)
@@ -31,6 +31,7 @@
 #include "CryptoAlgorithmAesCbcCfbParams.h"
 #include "CryptoAlgorithmAesKeyParams.h"
 #include "CryptoKeyAES.h"
+#include <wtf/CrossThreadCopier.h>
 
 namespace WebCore {
 
@@ -56,35 +57,35 @@ CryptoAlgorithmIdentifier CryptoAlgorithmAES_CFB::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmAES_CFB::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmAES_CFB::encrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     using namespace CryptoAlgorithmAES_CFBInternal;
-    ASSERT(parameters);
-    auto& aesParameters = downcast<CryptoAlgorithmAesCbcCfbParams>(*parameters);
+
+    auto& aesParameters = downcast<CryptoAlgorithmAesCbcCfbParams>(parameters);
     if (aesParameters.ivVector().size() != IVSIZE) {
         exceptionCallback(OperationError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
-            return platformEncrypt(downcast<CryptoAlgorithmAesCbcCfbParams>(*parameters), downcast<CryptoKeyAES>(key.get()), plainText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(aesParameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
+            return platformEncrypt(parameters, downcast<CryptoKeyAES>(key.get()), plainText);
         });
 }
 
-void CryptoAlgorithmAES_CFB::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmAES_CFB::decrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     using namespace CryptoAlgorithmAES_CFBInternal;
-    ASSERT(parameters);
-    auto& aesParameters = downcast<CryptoAlgorithmAesCbcCfbParams>(*parameters);
+
+    auto& aesParameters = downcast<CryptoAlgorithmAesCbcCfbParams>(parameters);
     if (aesParameters.ivVector().size() != IVSIZE) {
         exceptionCallback(OperationError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
-            return platformDecrypt(downcast<CryptoAlgorithmAesCbcCfbParams>(*parameters), downcast<CryptoKeyAES>(key.get()), cipherText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(aesParameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
+            return platformDecrypt(parameters, downcast<CryptoKeyAES>(key.get()), cipherText);
         });
 }
 
@@ -106,10 +107,10 @@ void CryptoAlgorithmAES_CFB::generateKey(const CryptoAlgorithmParameters& parame
     callback(WTFMove(result));
 }
 
-void CryptoAlgorithmAES_CFB::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmAES_CFB::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace CryptoAlgorithmAES_CFBInternal;
-    ASSERT(parameters);
+    
     if (usagesAreInvalidForCryptoAlgorithmAES_CFB(usages)) {
         exceptionCallback(SyntaxError);
         return;
@@ -118,7 +119,7 @@ void CryptoAlgorithmAES_CFB::importKey(CryptoKeyFormat format, KeyData&& data, c
     RefPtr<CryptoKeyAES> result;
     switch (format) {
     case CryptoKeyFormat::Raw:
-        result = CryptoKeyAES::importRaw(parameters->identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyAES::importRaw(parameters.identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     case CryptoKeyFormat::Jwk: {
         auto checkAlgCallback = [](size_t length, const String& alg) -> bool {
@@ -132,7 +133,7 @@ void CryptoAlgorithmAES_CFB::importKey(CryptoKeyFormat format, KeyData&& data, c
             }
             return false;
         };
-        result = CryptoKeyAES::importJwk(parameters->identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, WTFMove(checkAlgCallback));
+        result = CryptoKeyAES::importJwk(parameters.identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, WTFMove(checkAlgCallback));
         break;
     }
     default:
index 03ab05a..34ece4a 100644 (file)
@@ -44,15 +44,15 @@ private:
     CryptoAlgorithmAES_CFB() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
 
-    static ExceptionOr<Vector<uint8_t>> platformEncrypt(CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
-    static ExceptionOr<Vector<uint8_t>> platformDecrypt(CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformEncrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformDecrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
 };
 
 } // namespace WebCore
index abea471..ad5bb4b 100644 (file)
@@ -31,6 +31,7 @@
 #include "CryptoAlgorithmAesCtrParams.h"
 #include "CryptoAlgorithmAesKeyParams.h"
 #include "CryptoKeyAES.h"
+#include <wtf/CrossThreadCopier.h>
 
 namespace WebCore {
 
@@ -46,7 +47,7 @@ static inline bool usagesAreInvalidForCryptoAlgorithmAES_CTR(CryptoKeyUsageBitma
     return usages & (CryptoKeyUsageSign | CryptoKeyUsageVerify | CryptoKeyUsageDeriveKey | CryptoKeyUsageDeriveBits);
 }
 
-static bool parametersAreValid(CryptoAlgorithmAesCtrParams& parameters)
+static bool parametersAreValid(const CryptoAlgorithmAesCtrParams& parameters)
 {
     using namespace CryptoAlgorithmAES_CTRInternal;
     if (parameters.counterVector().size() != CounterSize)
@@ -66,33 +67,31 @@ CryptoAlgorithmIdentifier CryptoAlgorithmAES_CTR::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmAES_CTR::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmAES_CTR::encrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
-    ASSERT(parameters);
-    auto& aesParameters = downcast<CryptoAlgorithmAesCtrParams>(*parameters);
+    auto& aesParameters = downcast<CryptoAlgorithmAesCtrParams>(parameters);
     if (!parametersAreValid(aesParameters)) {
         exceptionCallback(OperationError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
-            return platformEncrypt(downcast<CryptoAlgorithmAesCtrParams>(*parameters), downcast<CryptoKeyAES>(key.get()), plainText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(aesParameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
+            return platformEncrypt(parameters, downcast<CryptoKeyAES>(key.get()), plainText);
         });
 }
 
-void CryptoAlgorithmAES_CTR::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmAES_CTR::decrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
-    ASSERT(parameters);
-    auto& aesParameters = downcast<CryptoAlgorithmAesCtrParams>(*parameters);
+    auto& aesParameters = downcast<CryptoAlgorithmAesCtrParams>(parameters);
     if (!parametersAreValid(aesParameters)) {
         exceptionCallback(OperationError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
-            return platformDecrypt(downcast<CryptoAlgorithmAesCtrParams>(*parameters), downcast<CryptoKeyAES>(key.get()), cipherText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(aesParameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
+            return platformDecrypt(parameters, downcast<CryptoKeyAES>(key.get()), cipherText);
         });
 }
 
@@ -114,10 +113,10 @@ void CryptoAlgorithmAES_CTR::generateKey(const CryptoAlgorithmParameters& parame
     callback(WTFMove(result));
 }
 
-void CryptoAlgorithmAES_CTR::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmAES_CTR::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace CryptoAlgorithmAES_CTRInternal;
-    ASSERT(parameters);
+
     if (usagesAreInvalidForCryptoAlgorithmAES_CTR(usages)) {
         exceptionCallback(SyntaxError);
         return;
@@ -126,7 +125,7 @@ void CryptoAlgorithmAES_CTR::importKey(CryptoKeyFormat format, KeyData&& data, c
     RefPtr<CryptoKeyAES> result;
     switch (format) {
     case CryptoKeyFormat::Raw:
-        result = CryptoKeyAES::importRaw(parameters->identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyAES::importRaw(parameters.identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     case CryptoKeyFormat::Jwk: {
         auto checkAlgCallback = [](size_t length, const String& alg) -> bool {
@@ -140,7 +139,7 @@ void CryptoAlgorithmAES_CTR::importKey(CryptoKeyFormat format, KeyData&& data, c
             }
             return false;
         };
-        result = CryptoKeyAES::importJwk(parameters->identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, WTFMove(checkAlgCallback));
+        result = CryptoKeyAES::importJwk(parameters.identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, WTFMove(checkAlgCallback));
         break;
     }
     default:
index 9e8bf05..5d32ed7 100644 (file)
@@ -44,15 +44,15 @@ private:
     CryptoAlgorithmAES_CTR() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
 
-    static ExceptionOr<Vector<uint8_t>> platformEncrypt(CryptoAlgorithmAesCtrParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
-    static ExceptionOr<Vector<uint8_t>> platformDecrypt(CryptoAlgorithmAesCtrParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformEncrypt(const CryptoAlgorithmAesCtrParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformDecrypt(const CryptoAlgorithmAesCtrParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
 };
 
 } // namespace WebCore
index 4fc1315..305f7e5 100644 (file)
@@ -31,6 +31,7 @@
 #include "CryptoAlgorithmAesGcmParams.h"
 #include "CryptoAlgorithmAesKeyParams.h"
 #include "CryptoKeyAES.h"
+#include <wtf/CrossThreadCopier.h>
 
 namespace WebCore {
 
@@ -70,11 +71,11 @@ CryptoAlgorithmIdentifier CryptoAlgorithmAES_GCM::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmAES_GCM::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmAES_GCM::encrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     using namespace CryptoAlgorithmAES_GCMInternal;
-    ASSERT(parameters);
-    auto& aesParameters = downcast<CryptoAlgorithmAesGcmParams>(*parameters);
+
+    auto& aesParameters = downcast<CryptoAlgorithmAesGcmParams>(parameters);
 
 #if __WORDSIZE >= 64
     if (plainText.size() > PlainTextMaxLength) {
@@ -97,17 +98,17 @@ void CryptoAlgorithmAES_GCM::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
-            return platformEncrypt(downcast<CryptoAlgorithmAesGcmParams>(*parameters), downcast<CryptoKeyAES>(key.get()), plainText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(aesParameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
+            return platformEncrypt(parameters, downcast<CryptoKeyAES>(key.get()), plainText);
         });
 }
 
-void CryptoAlgorithmAES_GCM::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmAES_GCM::decrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     using namespace CryptoAlgorithmAES_GCMInternal;
-    ASSERT(parameters);
-    auto& aesParameters = downcast<CryptoAlgorithmAesGcmParams>(*parameters);
+
+    auto& aesParameters = downcast<CryptoAlgorithmAesGcmParams>(parameters);
 
     aesParameters.tagLength = aesParameters.tagLength ? aesParameters.tagLength : DefaultTagLength;
     if (!tagLengthIsValid(*(aesParameters.tagLength))) {
@@ -130,9 +131,9 @@ void CryptoAlgorithmAES_GCM::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&
     }
 #endif
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
-            return platformDecrypt(downcast<CryptoAlgorithmAesGcmParams>(*parameters), downcast<CryptoKeyAES>(key.get()), cipherText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(aesParameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
+            return platformDecrypt(parameters, downcast<CryptoKeyAES>(key.get()), cipherText);
         });
 }
 
@@ -154,10 +155,10 @@ void CryptoAlgorithmAES_GCM::generateKey(const CryptoAlgorithmParameters& parame
     callback(WTFMove(result));
 }
 
-void CryptoAlgorithmAES_GCM::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmAES_GCM::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace CryptoAlgorithmAES_GCMInternal;
-    ASSERT(parameters);
+
     if (usagesAreInvalidForCryptoAlgorithmAES_GCM(usages)) {
         exceptionCallback(SyntaxError);
         return;
@@ -166,7 +167,7 @@ void CryptoAlgorithmAES_GCM::importKey(CryptoKeyFormat format, KeyData&& data, c
     RefPtr<CryptoKeyAES> result;
     switch (format) {
     case CryptoKeyFormat::Raw:
-        result = CryptoKeyAES::importRaw(parameters->identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyAES::importRaw(parameters.identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     case CryptoKeyFormat::Jwk: {
         auto checkAlgCallback = [](size_t length, const String& alg) -> bool {
@@ -180,7 +181,7 @@ void CryptoAlgorithmAES_GCM::importKey(CryptoKeyFormat format, KeyData&& data, c
             }
             return false;
         };
-        result = CryptoKeyAES::importJwk(parameters->identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, WTFMove(checkAlgCallback));
+        result = CryptoKeyAES::importJwk(parameters.identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, WTFMove(checkAlgCallback));
         break;
     }
     default:
index a520fd6..3c42858 100644 (file)
@@ -44,15 +44,15 @@ private:
     CryptoAlgorithmAES_GCM() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
 
-    static ExceptionOr<Vector<uint8_t>> platformEncrypt(CryptoAlgorithmAesGcmParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
-    static ExceptionOr<Vector<uint8_t>> platformDecrypt(CryptoAlgorithmAesGcmParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformEncrypt(const CryptoAlgorithmAesGcmParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformDecrypt(const CryptoAlgorithmAesGcmParams&, const CryptoKeyAES&, const Vector<uint8_t>&);
 };
 
 } // namespace WebCore
index 804dff0..1782c96 100644 (file)
@@ -71,10 +71,10 @@ void CryptoAlgorithmAES_KW::generateKey(const CryptoAlgorithmParameters& paramet
     callback(WTFMove(result));
 }
 
-void CryptoAlgorithmAES_KW::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmAES_KW::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace CryptoAlgorithmAES_KWInternal;
-    ASSERT(parameters);
+
     if (usagesAreInvalidForCryptoAlgorithmAES_KW(usages)) {
         exceptionCallback(SyntaxError);
         return;
@@ -83,10 +83,10 @@ void CryptoAlgorithmAES_KW::importKey(CryptoKeyFormat format, KeyData&& data, co
     RefPtr<CryptoKeyAES> result;
     switch (format) {
     case CryptoKeyFormat::Raw:
-        result = CryptoKeyAES::importRaw(parameters->identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyAES::importRaw(parameters.identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     case CryptoKeyFormat::Jwk: {
-        result = CryptoKeyAES::importJwk(parameters->identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, [](size_t length, const String& alg) -> bool {
+        result = CryptoKeyAES::importJwk(parameters.identifier, WTFMove(WTF::get<JsonWebKey>(data)), extractable, usages, [](size_t length, const String& alg) -> bool {
             switch (length) {
             case CryptoKeyAES::s_length128:
                 return alg.isNull() || alg == ALG128;
index e0a557f..ed657be 100644 (file)
@@ -44,7 +44,7 @@ private:
     CryptoAlgorithmIdentifier identifier() const final;
 
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     void wrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&) final;
     void unwrapKey(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&) final;
index 163bd9c..a6d309d 100644 (file)
@@ -66,7 +66,7 @@ void CryptoAlgorithmECDH::generateKey(const CryptoAlgorithmParameters& parameter
     callback(WTFMove(pair));
 }
 
-void CryptoAlgorithmECDH::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmECDH::deriveBits(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     // We only accept length that is a multiple of 8.
     if (length % 8) {
@@ -74,8 +74,7 @@ void CryptoAlgorithmECDH::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&
         return;
     }
 
-    ASSERT(parameters);
-    auto& ecParameters = downcast<CryptoAlgorithmEcdhKeyDeriveParams>(*parameters);
+    auto& ecParameters = downcast<CryptoAlgorithmEcdhKeyDeriveParams>(parameters);
 
     if (baseKey->type() != CryptoKey::Type::Private) {
         exceptionCallback(InvalidAccessError);
@@ -117,18 +116,17 @@ void CryptoAlgorithmECDH::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&
     // This is a special case that can't use dispatchOperation() because it bundles
     // the result validation and callback dispatch into unifiedCallback.
     workQueue.dispatch(
-        [baseKey = WTFMove(baseKey), publicKey = ecParameters.publicKey.releaseNonNull(), length, unifiedCallback = WTFMove(unifiedCallback), contextIdentifier = context.contextIdentifier()]() mutable {
-            auto derivedKey = platformDeriveBits(downcast<CryptoKeyEC>(baseKey.get()), downcast<CryptoKeyEC>(publicKey.get()));
+        [baseKey = WTFMove(baseKey), publicKey = ecParameters.publicKey, length, unifiedCallback = WTFMove(unifiedCallback), contextIdentifier = context.contextIdentifier()]() mutable {
+            auto derivedKey = platformDeriveBits(downcast<CryptoKeyEC>(baseKey.get()), downcast<CryptoKeyEC>(*publicKey));
             ScriptExecutionContext::postTaskTo(contextIdentifier, [derivedKey = WTFMove(derivedKey), length, unifiedCallback = WTFMove(unifiedCallback)](auto&) mutable {
                 unifiedCallback(WTFMove(derivedKey), length);
             });
         });
 }
 
-void CryptoAlgorithmECDH::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmECDH::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
-    ASSERT(parameters);
-    const auto& ecParameters = downcast<CryptoAlgorithmEcKeyParams>(*parameters);
+    const auto& ecParameters = downcast<CryptoAlgorithmEcKeyParams>(parameters);
 
     RefPtr<CryptoKeyEC> result;
     switch (format) {
index 123ee69..9796fb9 100644 (file)
@@ -44,8 +44,8 @@ private:
     CryptoAlgorithmIdentifier identifier() const final;
 
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void deriveBits(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
 
     static std::optional<Vector<uint8_t>> platformDeriveBits(const CryptoKeyEC&, const CryptoKeyEC&);
index 131ddce..97317e0 100644 (file)
@@ -31,6 +31,8 @@
 #include "CryptoAlgorithmEcKeyParams.h"
 #include "CryptoAlgorithmEcdsaParams.h"
 #include "CryptoKeyEC.h"
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <wtf/CrossThreadCopier.h>
 
 namespace WebCore {
 
@@ -51,29 +53,29 @@ CryptoAlgorithmIdentifier CryptoAlgorithmECDSA::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmECDSA::sign(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmECDSA::sign(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (key->type() != CryptoKeyType::Private) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), data = WTFMove(data)] {
-            return platformSign(downcast<CryptoAlgorithmEcdsaParams>(*parameters), downcast<CryptoKeyEC>(key.get()), data);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(downcast<CryptoAlgorithmEcdsaParams>(parameters)), key = WTFMove(key), data = WTFMove(data)] {
+            return platformSign(parameters, downcast<CryptoKeyEC>(key.get()), data);
         });
 }
 
-void CryptoAlgorithmECDSA::verify(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmECDSA::verify(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (key->type() != CryptoKeyType::Public) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data)] {
-            return platformVerify(downcast<CryptoAlgorithmEcdsaParams>(*parameters), downcast<CryptoKeyEC>(key.get()), signature, data);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(downcast<CryptoAlgorithmEcdsaParams>(parameters)), key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data)] {
+            return platformVerify(parameters, downcast<CryptoKeyEC>(key.get()), signature, data);
         });
 }
 
@@ -98,10 +100,9 @@ void CryptoAlgorithmECDSA::generateKey(const CryptoAlgorithmParameters& paramete
     callback(WTFMove(pair));
 }
 
-void CryptoAlgorithmECDSA::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmECDSA::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
-    ASSERT(parameters);
-    const auto& ecParameters = downcast<CryptoAlgorithmEcKeyParams>(*parameters);
+    const auto& ecParameters = downcast<CryptoAlgorithmEcKeyParams>(parameters);
 
     RefPtr<CryptoKeyEC> result;
     switch (format) {
index 738fa60..059c911 100644 (file)
@@ -44,10 +44,10 @@ private:
     CryptoAlgorithmECDSA() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void sign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void verify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void sign(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void verify(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
 
     static ExceptionOr<Vector<uint8_t>> platformSign(const CryptoAlgorithmEcdsaParams&, const CryptoKeyEC&, const Vector<uint8_t>&);
index 879f1ff..99fc697 100644 (file)
@@ -30,6 +30,8 @@
 
 #include "CryptoAlgorithmHkdfParams.h"
 #include "CryptoKeyRaw.h"
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <wtf/CrossThreadCopier.h>
 
 namespace WebCore {
 
@@ -43,20 +45,20 @@ CryptoAlgorithmIdentifier CryptoAlgorithmHKDF::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmHKDF::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmHKDF::deriveBits(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (!length || length % 8) {
         exceptionCallback(OperationError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), baseKey = WTFMove(baseKey), length] {
-            return platformDeriveBits(downcast<CryptoAlgorithmHkdfParams>(*parameters), downcast<CryptoKeyRaw>(baseKey.get()), length);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(downcast<CryptoAlgorithmHkdfParams>(parameters)), baseKey = WTFMove(baseKey), length] {
+            return platformDeriveBits(parameters, downcast<CryptoKeyRaw>(baseKey.get()), length);
         });
 }
 
-void CryptoAlgorithmHKDF::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmHKDF::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     if (format != CryptoKeyFormat::Raw) {
         exceptionCallback(NotSupportedError);
@@ -71,7 +73,7 @@ void CryptoAlgorithmHKDF::importKey(CryptoKeyFormat format, KeyData&& data, cons
         return;
     }
 
-    callback(CryptoKeyRaw::create(parameters->identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), usages));
+    callback(CryptoKeyRaw::create(parameters.identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), usages));
 }
 
 ExceptionOr<size_t> CryptoAlgorithmHKDF::getKeyLength(const CryptoAlgorithmParameters&)
index edf67db..f23f996 100644 (file)
@@ -44,11 +44,11 @@ private:
     CryptoAlgorithmHKDF() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void deriveBits(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
 
-    static ExceptionOr<Vector<uint8_t>> platformDeriveBits(CryptoAlgorithmHkdfParams&, const CryptoKeyRaw&, size_t);
+    static ExceptionOr<Vector<uint8_t>> platformDeriveBits(const CryptoAlgorithmHkdfParams&, const CryptoKeyRaw&, size_t);
 };
 
 } // namespace WebCore
index e04c5b9..8a08738 100644 (file)
@@ -57,17 +57,17 @@ CryptoAlgorithmIdentifier CryptoAlgorithmHMAC::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmHMAC::sign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters&, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
         [key = WTFMove(key), data = WTFMove(data)] {
             return platformSign(downcast<CryptoKeyHMAC>(key.get()), data);
         });
 }
 
-void CryptoAlgorithmHMAC::verify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters&, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
         [key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data)] {
             return platformVerify(downcast<CryptoKeyHMAC>(key.get()), signature, data);
         });
@@ -96,11 +96,11 @@ void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameter
     callback(WTFMove(result));
 }
 
-void CryptoAlgorithmHMAC::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmHMAC::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace CryptoAlgorithmHMACInternal;
-    ASSERT(parameters);
-    const auto& hmacParameters = downcast<CryptoAlgorithmHmacKeyParams>(*parameters);
+
+    const auto& hmacParameters = downcast<CryptoAlgorithmHmacKeyParams>(parameters);
 
     if (usagesAreInvalidForCryptoAlgorithmHMAC(usages)) {
         exceptionCallback(SyntaxError);
index 7d8f7b4..d394cb7 100644 (file)
@@ -43,10 +43,10 @@ private:
     CryptoAlgorithmHMAC() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void sign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void verify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void sign(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void verify(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
     ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
 
index 0562e5b..237802f 100644 (file)
@@ -30,6 +30,8 @@
 
 #include "CryptoAlgorithmPbkdf2Params.h"
 #include "CryptoKeyRaw.h"
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <wtf/CrossThreadCopier.h>
 
 namespace WebCore {
 
@@ -43,20 +45,20 @@ CryptoAlgorithmIdentifier CryptoAlgorithmPBKDF2::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmPBKDF2::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmPBKDF2::deriveBits(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (!length || length % 8) {
         exceptionCallback(OperationError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), baseKey = WTFMove(baseKey), length] {
-            return platformDeriveBits(downcast<CryptoAlgorithmPbkdf2Params>(*parameters), downcast<CryptoKeyRaw>(baseKey.get()), length);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(downcast<CryptoAlgorithmPbkdf2Params>(parameters)), baseKey = WTFMove(baseKey), length] {
+            return platformDeriveBits(parameters, downcast<CryptoKeyRaw>(baseKey.get()), length);
         });
 }
 
-void CryptoAlgorithmPBKDF2::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmPBKDF2::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     if (format != CryptoKeyFormat::Raw) {
         exceptionCallback(NotSupportedError);
@@ -71,7 +73,7 @@ void CryptoAlgorithmPBKDF2::importKey(CryptoKeyFormat format, KeyData&& data, co
         return;
     }
 
-    callback(CryptoKeyRaw::create(parameters->identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), usages));
+    callback(CryptoKeyRaw::create(parameters.identifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), usages));
 }
 
 ExceptionOr<size_t> CryptoAlgorithmPBKDF2::getKeyLength(const CryptoAlgorithmParameters&)
index e21e186..7832130 100644 (file)
@@ -44,11 +44,11 @@ private:
     CryptoAlgorithmPBKDF2() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void deriveBits(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, size_t length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     ExceptionOr<size_t> getKeyLength(const CryptoAlgorithmParameters&) final;
 
-    static ExceptionOr<Vector<uint8_t>> platformDeriveBits(CryptoAlgorithmPbkdf2Params&, const CryptoKeyRaw&, size_t);
+    static ExceptionOr<Vector<uint8_t>> platformDeriveBits(const CryptoAlgorithmPbkdf2Params&, const CryptoKeyRaw&, size_t);
 };
 
 } // namespace WebCore
index 76eeeb5..3794475 100644 (file)
@@ -47,27 +47,27 @@ CryptoAlgorithmIdentifier CryptoAlgorithmRSAES_PKCS1_v1_5::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (key->type() != CryptoKeyType::Public) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
         [key = WTFMove(key), plainText = WTFMove(plainText)] {
             return platformEncrypt(downcast<CryptoKeyRSA>(key.get()), plainText);
         });
 }
 
-void CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (key->type() != CryptoKeyType::Private) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
         [key = WTFMove(key), cipherText = WTFMove(cipherText)] {
             return platformDecrypt(downcast<CryptoKeyRSA>(key.get()), cipherText);
         });
@@ -94,9 +94,8 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameter
     CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5, CryptoAlgorithmIdentifier::SHA_1, false, rsaParameters.modulusLength, rsaParameters.publicExponentVector(), extractable, usages, WTFMove(keyPairCallback), WTFMove(failureCallback), &context);
 }
 
-void CryptoAlgorithmRSAES_PKCS1_v1_5::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmRSAES_PKCS1_v1_5::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
-    ASSERT(parameters);
     RefPtr<CryptoKeyRSA> result;
     switch (format) {
     case CryptoKeyFormat::Jwk: {
@@ -113,7 +112,7 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::importKey(CryptoKeyFormat format, KeyData&
             exceptionCallback(DataError);
             return;
         }
-        result = CryptoKeyRSA::importJwk(parameters->identifier, std::nullopt, WTFMove(key), extractable, usages);
+        result = CryptoKeyRSA::importJwk(parameters.identifier, std::nullopt, WTFMove(key), extractable, usages);
         break;
     }
     case CryptoKeyFormat::Spki: {
@@ -121,7 +120,7 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::importKey(CryptoKeyFormat format, KeyData&
             exceptionCallback(SyntaxError);
             return;
         }
-        result = CryptoKeyRSA::importSpki(parameters->identifier, std::nullopt, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyRSA::importSpki(parameters.identifier, std::nullopt, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     }
     case CryptoKeyFormat::Pkcs8: {
@@ -129,7 +128,7 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::importKey(CryptoKeyFormat format, KeyData&
             exceptionCallback(SyntaxError);
             return;
         }
-        result = CryptoKeyRSA::importPkcs8(parameters->identifier, std::nullopt, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyRSA::importPkcs8(parameters.identifier, std::nullopt, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     }
     default:
index 31f69a6..6b21041 100644 (file)
@@ -43,10 +43,10 @@ private:
     CryptoAlgorithmRSAES_PKCS1_v1_5() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
 
     static ExceptionOr<Vector<uint8_t>> platformEncrypt(const CryptoKeyRSA&, const Vector<uint8_t>&);
index e15276d..5fb55ca 100644 (file)
@@ -54,27 +54,27 @@ CryptoAlgorithmIdentifier CryptoAlgorithmRSASSA_PKCS1_v1_5::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters&, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (key->type() != CryptoKeyType::Private) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
         [key = WTFMove(key), data = WTFMove(data)] {
             return platformSign(downcast<CryptoKeyRSA>(key.get()), data);
         });
 }
 
-void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters&, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (key->type() != CryptoKeyType::Public) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
         [key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data)] {
             return platformVerify(downcast<CryptoKeyRSA>(key.get()), signature, data);
         });
@@ -100,11 +100,11 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParamete
     CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaParameters.hashIdentifier, true, rsaParameters.modulusLength, rsaParameters.publicExponentVector(), extractable, usages, WTFMove(keyPairCallback), WTFMove(failureCallback), &context);
 }
 
-void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace CryptoAlgorithmRSASSA_PKCS1_v1_5Internal;
-    ASSERT(parameters);
-    const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedImportParams>(*parameters);
+
+    const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedImportParams>(parameters);
 
     RefPtr<CryptoKeyRSA> result;
     switch (format) {
@@ -163,7 +163,7 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(CryptoKeyFormat format, KeyData
             return;
         }
         // FIXME: <webkit.org/b/165436>
-        result = CryptoKeyRSA::importPkcs8(parameters->identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyRSA::importPkcs8(parameters.identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     }
     default:
index d47b182..1d668cb 100644 (file)
@@ -43,10 +43,10 @@ private:
     CryptoAlgorithmRSASSA_PKCS1_v1_5() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void sign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void verify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void sign(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void verify(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
 
     static ExceptionOr<Vector<uint8_t>> platformSign(const CryptoKeyRSA&, const Vector<uint8_t>&);
index 3ae1f0a..210aec8 100644 (file)
@@ -33,6 +33,7 @@
 #include "CryptoAlgorithmRsaOaepParams.h"
 #include "CryptoKeyPair.h"
 #include "CryptoKeyRSA.h"
+#include <wtf/CrossThreadCopier.h>
 #include <wtf/Variant.h>
 
 namespace WebCore {
@@ -55,31 +56,29 @@ CryptoAlgorithmIdentifier CryptoAlgorithmRSA_OAEP::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmRSA_OAEP::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSA_OAEP::encrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
-    ASSERT(parameters);
     if (key->type() != CryptoKeyType::Public) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), plainText = WTFMove(plainText)] {
-            return platformEncrypt(downcast<CryptoAlgorithmRsaOaepParams>(*parameters), downcast<CryptoKeyRSA>(key.get()), plainText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(downcast<CryptoAlgorithmRsaOaepParams>(parameters)), key = WTFMove(key), plainText = WTFMove(plainText)] {
+            return platformEncrypt(parameters, downcast<CryptoKeyRSA>(key.get()), plainText);
         });
 }
 
-void CryptoAlgorithmRSA_OAEP::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSA_OAEP::decrypt(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
-    ASSERT(parameters);
     if (key->type() != CryptoKeyType::Private) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
-            return platformDecrypt(downcast<CryptoAlgorithmRsaOaepParams>(*parameters), downcast<CryptoKeyRSA>(key.get()), cipherText);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(downcast<CryptoAlgorithmRsaOaepParams>(parameters)), key = WTFMove(key), cipherText = WTFMove(cipherText)] {
+            return platformDecrypt(parameters, downcast<CryptoKeyRSA>(key.get()), cipherText);
         });
 }
 
@@ -103,11 +102,11 @@ void CryptoAlgorithmRSA_OAEP::generateKey(const CryptoAlgorithmParameters& param
     CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSA_OAEP, rsaParameters.hashIdentifier, true, rsaParameters.modulusLength, rsaParameters.publicExponentVector(), extractable, usages, WTFMove(keyPairCallback), WTFMove(failureCallback), &context);
 }
 
-void CryptoAlgorithmRSA_OAEP::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmRSA_OAEP::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace CryptoAlgorithmRSA_OAEPInternal;
-    ASSERT(parameters);
-    const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedImportParams>(*parameters);
+
+    const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedImportParams>(parameters);
 
     RefPtr<CryptoKeyRSA> result;
     switch (format) {
@@ -178,7 +177,7 @@ void CryptoAlgorithmRSA_OAEP::importKey(CryptoKeyFormat format, KeyData&& data,
             return;
         }
         // FIXME: <webkit.org/b/165436>
-        result = CryptoKeyRSA::importPkcs8(parameters->identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyRSA::importPkcs8(parameters.identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     }
     default:
index 0028bef..a8a7e19 100644 (file)
@@ -44,14 +44,14 @@ private:
     CryptoAlgorithmRSA_OAEP() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void encrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void decrypt(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
 
-    static ExceptionOr<Vector<uint8_t>> platformEncrypt(CryptoAlgorithmRsaOaepParams&, const CryptoKeyRSA&, const Vector<uint8_t>&);
-    static ExceptionOr<Vector<uint8_t>> platformDecrypt(CryptoAlgorithmRsaOaepParams&, const CryptoKeyRSA&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformEncrypt(const CryptoAlgorithmRsaOaepParams&, const CryptoKeyRSA&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformDecrypt(const CryptoAlgorithmRsaOaepParams&, const CryptoKeyRSA&, const Vector<uint8_t>&);
 };
 
 } // namespace WebCore
index 124d64e..0500d8a 100644 (file)
@@ -33,6 +33,7 @@
 #include "CryptoAlgorithmRsaPssParams.h"
 #include "CryptoKeyPair.h"
 #include "CryptoKeyRSA.h"
+#include <wtf/CrossThreadCopier.h>
 #include <wtf/Variant.h>
 
 namespace WebCore {
@@ -55,29 +56,29 @@ CryptoAlgorithmIdentifier CryptoAlgorithmRSA_PSS::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmRSA_PSS::sign(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSA_PSS::sign(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (key->type() != CryptoKeyType::Private) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), data = WTFMove(data)] {
-            return platformSign(downcast<CryptoAlgorithmRsaPssParams>(*parameters), downcast<CryptoKeyRSA>(key.get()), data);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(downcast<CryptoAlgorithmRsaPssParams>(parameters)), key = WTFMove(key), data = WTFMove(data)] {
+            return platformSign(parameters, downcast<CryptoKeyRSA>(key.get()), data);
         });
 }
 
-void CryptoAlgorithmRSA_PSS::verify(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+void CryptoAlgorithmRSA_PSS::verify(const CryptoAlgorithmParameters& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
 {
     if (key->type() != CryptoKeyType::Public) {
         exceptionCallback(InvalidAccessError);
         return;
     }
 
-    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
-        [parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data)] {
-            return platformVerify(downcast<CryptoAlgorithmRsaPssParams>(*parameters), downcast<CryptoKeyRSA>(key.get()), signature, data);
+    dispatchOperationInWorkQueue(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = crossThreadCopy(downcast<CryptoAlgorithmRsaPssParams>(parameters)), key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data)] {
+            return platformVerify(parameters, downcast<CryptoKeyRSA>(key.get()), signature, data);
         });
 }
 
@@ -101,11 +102,11 @@ void CryptoAlgorithmRSA_PSS::generateKey(const CryptoAlgorithmParameters& parame
     CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSA_PSS, rsaParameters.hashIdentifier, true, rsaParameters.modulusLength, rsaParameters.publicExponentVector(), extractable, usages, WTFMove(keyPairCallback), WTFMove(failureCallback), &context);
 }
 
-void CryptoAlgorithmRSA_PSS::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
+void CryptoAlgorithmRSA_PSS::importKey(CryptoKeyFormat format, KeyData&& data, const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace CryptoAlgorithmRSA_PSSInternal;
-    ASSERT(parameters);
-    const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedImportParams>(*parameters);
+
+    const auto& rsaParameters = downcast<CryptoAlgorithmRsaHashedImportParams>(parameters);
 
     RefPtr<CryptoKeyRSA> result;
     switch (format) {
@@ -164,7 +165,7 @@ void CryptoAlgorithmRSA_PSS::importKey(CryptoKeyFormat format, KeyData&& data, c
             return;
         }
         // FIXME: <webkit.org/b/165436>
-        result = CryptoKeyRSA::importPkcs8(parameters->identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        result = CryptoKeyRSA::importPkcs8(parameters.identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     }
     default:
index af572f4..6efc428 100644 (file)
@@ -44,14 +44,14 @@ private:
     CryptoAlgorithmRSA_PSS() = default;
     CryptoAlgorithmIdentifier identifier() const final;
 
-    void sign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
-    void verify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void sign(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
+    void verify(const CryptoAlgorithmParameters&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final;
-    void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
+    void importKey(CryptoKeyFormat, KeyData&&, const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
 
-    static ExceptionOr<Vector<uint8_t>> platformSign(CryptoAlgorithmRsaPssParams&, const CryptoKeyRSA&, const Vector<uint8_t>&);
-    static ExceptionOr<bool> platformVerify(CryptoAlgorithmRsaPssParams&, const CryptoKeyRSA&, const Vector<uint8_t>&, const Vector<uint8_t>&);
+    static ExceptionOr<Vector<uint8_t>> platformSign(const CryptoAlgorithmRsaPssParams&, const CryptoKeyRSA&, const Vector<uint8_t>&);
+    static ExceptionOr<bool> platformVerify(const CryptoAlgorithmRsaPssParams&, const CryptoKeyRSA&, const Vector<uint8_t>&, const Vector<uint8_t>&);
 };
 
 } // namespace WebCore
index 13c80cc..de581dc 100644 (file)
@@ -166,7 +166,7 @@ static std::optional<Vector<uint8_t>> gcryptDecrypt(const Vector<uint8_t>& key,
     return output;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformEncrypt(CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
 {
     auto output = gcryptEncrypt(key.key(), parameters.ivVector(), Vector<uint8_t>(plainText));
     if (!output)
@@ -174,7 +174,7 @@ ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformEncrypt(CryptoAlgor
     return WTFMove(*output);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformDecrypt(CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformDecrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
 {
     auto output = gcryptDecrypt(key.key(), parameters.ivVector(), cipherText);
     if (!output)
index 06908ef..a21b5f2 100644 (file)
 
 namespace WebCore {
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformEncrypt(CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformEncrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&)
 {
     return Exception { NotSupportedError };
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformDecrypt(CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformDecrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&)
 {
     return Exception { NotSupportedError };
 }
index 6792249..aa22f4e 100644 (file)
@@ -195,7 +195,7 @@ static std::optional<Vector<uint8_t>> gcryptAES_CTR(PAL::GCrypt::CipherOperation
     return output;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformEncrypt(CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformEncrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
 {
     auto output = gcryptAES_CTR(gcry_cipher_encrypt, key.key(), parameters.counterVector(), parameters.length, plainText);
     if (!output)
@@ -203,7 +203,7 @@ ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformEncrypt(CryptoAlgor
     return WTFMove(*output);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformDecrypt(CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformDecrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
 {
     auto output = gcryptAES_CTR(gcry_cipher_decrypt, key.key(), parameters.counterVector(), parameters.length, cipherText);
     if (!output)
index 8d3cd9e..47d26e8 100644 (file)
@@ -179,7 +179,7 @@ static std::optional<Vector<uint8_t>> gcryptDecrypt(const Vector<uint8_t>& key,
     return output;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformEncrypt(CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformEncrypt(const CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
 {
     auto output = gcryptEncrypt(key.key(), parameters.ivVector(), plainText, parameters.additionalDataVector(), parameters.tagLength.value_or(0) / 8);
     if (!output)
@@ -187,7 +187,7 @@ ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformEncrypt(CryptoAlgor
     return WTFMove(*output);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformDecrypt(CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformDecrypt(const CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
 {
     auto output = gcryptDecrypt(key.key(), parameters.ivVector(), cipherText, parameters.additionalDataVector(), parameters.tagLength.value_or(0) / 8);
     if (!output)
index 7926d35..7f97d28 100644 (file)
@@ -152,7 +152,7 @@ static std::optional<Vector<uint8_t>> gcryptDeriveBits(const Vector<uint8_t>& ke
     return output;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmHKDF::platformDeriveBits(CryptoAlgorithmHkdfParams& parameters, const CryptoKeyRaw& key, size_t length)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmHKDF::platformDeriveBits(const CryptoAlgorithmHkdfParams& parameters, const CryptoKeyRaw& key, size_t length)
 {
     auto output = gcryptDeriveBits(key.key(), parameters.saltVector(), parameters.infoVector(), length / 8, parameters.hashIdentifier);
     if (!output)
index 6a6f8a4..9924e0a 100644 (file)
@@ -57,7 +57,7 @@ static std::optional<Vector<uint8_t>> gcryptDeriveBits(const Vector<uint8_t>& ke
     return result;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmPBKDF2::platformDeriveBits(CryptoAlgorithmPbkdf2Params& parameters, const CryptoKeyRaw& key, size_t length)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmPBKDF2::platformDeriveBits(const CryptoAlgorithmPbkdf2Params& parameters, const CryptoKeyRaw& key, size_t length)
 {
     auto output = gcryptDeriveBits(key.key(), parameters.saltVector(), parameters.hashIdentifier, parameters.iterations, length);
     if (!output)
index 1a668f2..6ca60b6 100644 (file)
@@ -110,7 +110,7 @@ static std::optional<Vector<uint8_t>> gcryptDecrypt(CryptoAlgorithmIdentifier ha
     return mpiData(valueSexp);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& plainText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(const CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& plainText)
 {
     RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!(key.keySizeInBits() % 8));
     auto output = gcryptEncrypt(key.hashAlgorithmIdentifier(), key.platformKey(), parameters.labelVector(), plainText, key.keySizeInBits() / 8);
@@ -119,7 +119,7 @@ ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(CryptoAlgo
     return WTFMove(*output);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& cipherText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(const CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& cipherText)
 {
     auto output = gcryptDecrypt(key.hashAlgorithmIdentifier(), key.platformKey(), parameters.labelVector(), cipherText);
     if (!output)
index 922cc9b..15c3cba 100644 (file)
@@ -135,7 +135,7 @@ static std::optional<bool> gcryptVerify(gcry_sexp_t keySexp, const Vector<uint8_
     return { error == GPG_ERR_NO_ERROR };
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& data)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(const CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& data)
 {
     RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!(key.keySizeInBits() % 8));
     auto output = gcryptSign(key.platformKey(), data, key.hashAlgorithmIdentifier(), parameters.saltLength, key.keySizeInBits() / 8);
@@ -144,7 +144,7 @@ ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(CryptoAlgorith
     return WTFMove(*output);
 }
 
-ExceptionOr<bool> CryptoAlgorithmRSA_PSS::platformVerify(CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
+ExceptionOr<bool> CryptoAlgorithmRSA_PSS::platformVerify(const CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
 {
     auto output = gcryptVerify(key.platformKey(), signature, data, key.hashAlgorithmIdentifier(), parameters.saltLength);
     if (!output)
index d3c7556..479e620 100644 (file)
@@ -62,13 +62,13 @@ static ExceptionOr<Vector<uint8_t>> transformAES_CBC(CCOperation operation, cons
     return WTFMove(result);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformEncrypt(CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
 {
     ASSERT(parameters.ivVector().size() == kCCBlockSizeAES128);
     return transformAES_CBC(kCCEncrypt, parameters.ivVector(), key.key(), plainText);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformDecrypt(CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformDecrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
 {
     ASSERT(parameters.ivVector().size() == kCCBlockSizeAES128);
     return transformAES_CBC(kCCDecrypt, parameters.ivVector(), key.key(), cipherText);
index 001c0d6..3594562 100644 (file)
@@ -62,13 +62,13 @@ static ExceptionOr<Vector<uint8_t>> transformAES_CFB(CCOperation operation, cons
     return WTFMove(result);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformEncrypt(CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformEncrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
 {
     ASSERT(parameters.ivVector().size() == kCCBlockSizeAES128);
     return transformAES_CFB(kCCEncrypt, parameters.ivVector(), key.key(), plainText);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformDecrypt(CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformDecrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
 {
     ASSERT(parameters.ivVector().size() == kCCBlockSizeAES128);
     return transformAES_CFB(kCCDecrypt, parameters.ivVector(), key.key(), cipherText);
index 4fc147c..6c0b5e9 100644 (file)
@@ -138,13 +138,13 @@ static ExceptionOr<Vector<uint8_t>> transformAES_CTR(CCOperation operation, cons
     return WTFMove(head);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformEncrypt(CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformEncrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
 {
     ASSERT(parameters.counterVector().size() == kCCBlockSizeAES128);
     return transformAES_CTR(kCCEncrypt, parameters.counterVector(), parameters.length, key.key(), plainText);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformDecrypt(CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CTR::platformDecrypt(const CryptoAlgorithmAesCtrParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
 {
       ASSERT(parameters.counterVector().size() == kCCBlockSizeAES128);
     return transformAES_CTR(kCCDecrypt, parameters.counterVector(), parameters.length, key.key(), cipherText);
index 37d022e..b2bc248 100644 (file)
@@ -72,12 +72,12 @@ static ExceptionOr<Vector<uint8_t>> decyptAES_GCM(const Vector<uint8_t>& iv, con
     return WTFMove(plainText);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformEncrypt(CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformEncrypt(const CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
 {
     return encryptAES_GCM(parameters.ivVector(), key.key(), plainText, parameters.additionalDataVector(), parameters.tagLength.value_or(0) / 8);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformDecrypt(CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformDecrypt(const CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
 {
     return decyptAES_GCM(parameters.ivVector(), key.key(), cipherText, parameters.additionalDataVector(), parameters.tagLength.value_or(0) / 8);
 }
index 63c7db7..45af500 100644 (file)
@@ -34,7 +34,7 @@
 
 namespace WebCore {
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmHKDF::platformDeriveBits(CryptoAlgorithmHkdfParams& parameters, const CryptoKeyRaw& key, size_t length)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmHKDF::platformDeriveBits(const CryptoAlgorithmHkdfParams& parameters, const CryptoKeyRaw& key, size_t length)
 {
     Vector<uint8_t> result(length / 8);
     CCDigestAlgorithm digestAlgorithm;
index b671f22..45ca8ba 100644 (file)
@@ -55,7 +55,7 @@ static CCPseudoRandomAlgorithm commonCryptoHMACAlgorithm(CryptoAlgorithmIdentifi
 }
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmPBKDF2::platformDeriveBits(CryptoAlgorithmPbkdf2Params& parameters, const CryptoKeyRaw& key, size_t length)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmPBKDF2::platformDeriveBits(const CryptoAlgorithmPbkdf2Params& parameters, const CryptoKeyRaw& key, size_t length)
 {
     Vector<uint8_t> result(length / 8);
     // <rdar://problem/32439955> Currently, CCKeyDerivationPBKDF bails out when an empty password/salt is provided.
index 86a966f..9e7b10b 100644 (file)
@@ -63,12 +63,12 @@ static ExceptionOr<Vector<uint8_t>> decryptRSA_OAEP(CryptoAlgorithmIdentifier ha
     return WTFMove(plainText);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& plainText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformEncrypt(const CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& plainText)
 {
     return encryptRSA_OAEP(key.hashAlgorithmIdentifier(), parameters.labelVector(), key.platformKey(), key.keySizeInBits(), plainText);
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& cipherText)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_OAEP::platformDecrypt(const CryptoAlgorithmRsaOaepParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& cipherText)
 {
     return decryptRSA_OAEP(key.hashAlgorithmIdentifier(), parameters.labelVector(), key.platformKey(), key.keySizeInBits(), cipherText);
 }
index 1306b36..ca3f22b 100644 (file)
@@ -81,12 +81,12 @@ static ExceptionOr<bool> verifyRSA_PSS(CryptoAlgorithmIdentifier hash, const Pla
     return false;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& data)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSA_PSS::platformSign(const CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& data)
 {
     return signRSA_PSS(key.hashAlgorithmIdentifier(), key.platformKey(), key.keySizeInBits(), data, parameters.saltLength);
 }
 
-ExceptionOr<bool> CryptoAlgorithmRSA_PSS::platformVerify(CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
+ExceptionOr<bool> CryptoAlgorithmRSA_PSS::platformVerify(const CryptoAlgorithmRsaPssParams& parameters, const CryptoKeyRSA& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
 {
     return verifyRSA_PSS(key.hashAlgorithmIdentifier(), key.platformKey(), signature, data, parameters.saltLength);
 }
index ed2a979..d4117ae 100644 (file)
@@ -39,7 +39,7 @@ public:
 
     Class parametersClass() const final { return Class::AesCbcCfbParams; }
 
-    const Vector<uint8_t>& ivVector()
+    const Vector<uint8_t>& ivVector() const
     {
         if (!m_ivVector.isEmpty() || !iv.length())
             return m_ivVector;
@@ -48,8 +48,17 @@ public:
         return m_ivVector;
     }
 
+    CryptoAlgorithmAesCbcCfbParams isolatedCopy() const
+    {
+        CryptoAlgorithmAesCbcCfbParams result;
+        result.identifier = identifier;
+        result.m_ivVector = ivVector();
+
+        return result;
+    }
+
 private:
-    Vector<uint8_t> m_ivVector;
+    mutable Vector<uint8_t> m_ivVector;
 };
 
 } // namespace WebCore
index 0db1726..4e05e01 100644 (file)
@@ -40,7 +40,7 @@ public:
 
     Class parametersClass() const final { return Class::AesCtrParams; }
 
-    const Vector<uint8_t>& counterVector()
+    const Vector<uint8_t>& counterVector() const
     {
         if (!m_counterVector.isEmpty() || !counter.length())
             return m_counterVector;
@@ -49,8 +49,18 @@ public:
         return m_counterVector;
     }
 
+    CryptoAlgorithmAesCtrParams isolatedCopy() const
+    {
+        CryptoAlgorithmAesCtrParams result;
+        result.identifier = identifier;
+        result.m_counterVector = counterVector();
+        result.length = length;
+
+        return result;
+    }
+
 private:
-    Vector<uint8_t> m_counterVector;
+    mutable Vector<uint8_t> m_counterVector;
 };
 
 } // namespace WebCore
index 129c6bb..d1f8e65 100644 (file)
@@ -37,12 +37,12 @@ class CryptoAlgorithmAesGcmParams final : public CryptoAlgorithmParameters {
 public:
     BufferSource iv;
     // Use additionalDataVector() instead of additionalData. The label will be gone once additionalDataVector() is called.
-    std::optional<BufferSource::VariantType> additionalData;
-    std::optional<uint8_t> tagLength;
+    mutable std::optional<BufferSource::VariantType> additionalData;
+    mutable std::optional<uint8_t> tagLength;
 
     Class parametersClass() const final { return Class::AesGcmParams; }
 
-    const Vector<uint8_t>& ivVector()
+    const Vector<uint8_t>& ivVector() const
     {
         if (!m_ivVector.isEmpty() || !iv.length())
             return m_ivVector;
@@ -51,24 +51,34 @@ public:
         return m_ivVector;
     }
 
-    const Vector<uint8_t>& additionalDataVector()
+    const Vector<uint8_t>& additionalDataVector() const
     {
         if (!m_additionalDataVector.isEmpty() || !additionalData)
             return m_additionalDataVector;
 
-        m_additionalDataBuffer = WTFMove(*additionalData);
+        BufferSource additionalDataBuffer = WTFMove(*additionalData);
         additionalData = std::nullopt;
-        if (!m_additionalDataBuffer.length())
+        if (!additionalDataBuffer.length())
             return m_additionalDataVector;
 
-        m_additionalDataVector.append(m_additionalDataBuffer.data(), m_additionalDataBuffer.length());
+        m_additionalDataVector.append(additionalDataBuffer.data(), additionalDataBuffer.length());
         return m_additionalDataVector;
     }
-    
+
+    CryptoAlgorithmAesGcmParams isolatedCopy() const
+    {
+        CryptoAlgorithmAesGcmParams result;
+        result.identifier = identifier;
+        result.m_ivVector = ivVector();
+        result.m_additionalDataVector = additionalDataVector();
+        result.tagLength = tagLength;
+
+        return result;
+    }
+
 private:
-    Vector<uint8_t> m_ivVector;
-    Vector<uint8_t> m_additionalDataVector;
-    BufferSource m_additionalDataBuffer;
+    mutable Vector<uint8_t> m_ivVector;
+    mutable Vector<uint8_t> m_additionalDataVector;
 };
 
 } // namespace WebCore
index c4b580f..b66aac7 100644 (file)
@@ -36,6 +36,15 @@ public:
     String namedCurve;
 
     Class parametersClass() const final { return Class::EcKeyParams; }
+
+    CryptoAlgorithmEcKeyParams isolatedCopy() const
+    {
+        CryptoAlgorithmEcKeyParams result;
+        result.identifier = identifier;
+        result.namedCurve = namedCurve.isolatedCopy();
+
+        return result;
+    }
 };
 
 } // namespace WebCore
index 2223c38..700af83 100644 (file)
@@ -41,6 +41,15 @@ public:
     CryptoAlgorithmIdentifier hashIdentifier;
 
     Class parametersClass() const final { return Class::EcdsaParams; }
+
+    CryptoAlgorithmEcdsaParams isolatedCopy() const
+    {
+        CryptoAlgorithmEcdsaParams result;
+        result.identifier = identifier;
+        result.hashIdentifier = hashIdentifier;
+
+        return result;
+    }
 };
 
 } // namespace WebCore
index 648b548..85bbc13 100644 (file)
@@ -43,7 +43,7 @@ public:
     BufferSource salt;
     BufferSource info;
 
-    const Vector<uint8_t>& saltVector()
+    const Vector<uint8_t>& saltVector() const
     {
         if (!m_saltVector.isEmpty() || !salt.length())
             return m_saltVector;
@@ -52,7 +52,7 @@ public:
         return m_saltVector;
     }
 
-    const Vector<uint8_t>& infoVector()
+    const Vector<uint8_t>& infoVector() const
     {
         if (!m_infoVector.isEmpty() || !info.length())
             return m_infoVector;
@@ -63,9 +63,20 @@ public:
 
     Class parametersClass() const final { return Class::HkdfParams; }
 
+    CryptoAlgorithmHkdfParams isolatedCopy() const
+    {
+        CryptoAlgorithmHkdfParams result;
+        result.identifier = identifier;
+        result.m_saltVector = saltVector();
+        result.m_infoVector = infoVector();
+        result.hashIdentifier = hashIdentifier;
+
+        return result;
+    }
+
 private:
-    Vector<uint8_t> m_saltVector;
-    Vector<uint8_t> m_infoVector;
+    mutable Vector<uint8_t> m_saltVector;
+    mutable Vector<uint8_t> m_infoVector;
 };
 
 } // namespace WebCore
index c9f11b8..9b8c5f2 100644 (file)
@@ -42,6 +42,16 @@ public:
     std::optional<size_t> length;
 
     Class parametersClass() const final { return Class::HmacKeyParams; }
+
+    CryptoAlgorithmHmacKeyParams isolatedCopy() const
+    {
+        CryptoAlgorithmHmacKeyParams result;
+        result.identifier = identifier;
+        result.hashIdentifier = hashIdentifier;
+        result.length = length;
+
+        return result;
+    }
 };
 
 } // namespace WebCore
index b1ad498..e4eedec 100644 (file)
@@ -43,7 +43,7 @@ public:
     Variant<JSC::Strong<JSC::JSObject>, String> hash;
     CryptoAlgorithmIdentifier hashIdentifier;
 
-    const Vector<uint8_t>& saltVector()
+    const Vector<uint8_t>& saltVector() const
     {
         if (!m_saltVector.isEmpty() || !salt.length())
             return m_saltVector;
@@ -54,8 +54,19 @@ public:
 
     Class parametersClass() const final { return Class::Pbkdf2Params; }
 
+    CryptoAlgorithmPbkdf2Params isolatedCopy() const
+    {
+        CryptoAlgorithmPbkdf2Params result;
+        result.identifier = identifier;
+        result.m_saltVector = saltVector();
+        result.iterations = iterations;
+        result.hashIdentifier = hashIdentifier;
+
+        return result;
+    }
+
 private:
-    Vector<uint8_t> m_saltVector;
+    mutable Vector<uint8_t> m_saltVector;
 };
 
 } // namespace WebCore
index 49dd3a2..12019ef 100644 (file)
@@ -41,6 +41,15 @@ public:
     CryptoAlgorithmIdentifier hashIdentifier;
 
     Class parametersClass() const final { return Class::RsaHashedImportParams; }
+
+    CryptoAlgorithmRsaHashedImportParams isolatedCopy() const
+    {
+        CryptoAlgorithmRsaHashedImportParams result;
+        result.identifier = identifier;
+        result.hashIdentifier = hashIdentifier;
+
+        return result;
+    }
 };
 
 } // namespace WebCore
index c56e653..300d8e4 100644 (file)
@@ -36,27 +36,35 @@ namespace WebCore {
 class CryptoAlgorithmRsaOaepParams final : public CryptoAlgorithmParameters {
 public:
     // Use labelVector() instead of label. The label will be gone once labelVector() is called.
-    std::optional<BufferSource::VariantType> label;
+    mutable std::optional<BufferSource::VariantType> label;
 
     Class parametersClass() const final { return Class::RsaOaepParams; }
 
-    const Vector<uint8_t>& labelVector()
+    const Vector<uint8_t>& labelVector() const
     {
         if (!m_labelVector.isEmpty() || !label)
             return m_labelVector;
 
-        m_labelBuffer = WTFMove(*label);
+        BufferSource labelBuffer = WTFMove(*label);
         label = std::nullopt;
-        if (!m_labelBuffer.length())
+        if (!labelBuffer.length())
             return m_labelVector;
 
-        m_labelVector.append(m_labelBuffer.data(), m_labelBuffer.length());
+        m_labelVector.append(labelBuffer.data(), labelBuffer.length());
         return m_labelVector;
     }
 
+    CryptoAlgorithmRsaOaepParams isolatedCopy() const
+    {
+        CryptoAlgorithmRsaOaepParams result;
+        result.identifier = identifier;
+        result.m_labelVector = labelVector();
+
+        return result;
+    }
+
 private:
-    Vector<uint8_t> m_labelVector;
-    BufferSource m_labelBuffer;
+    mutable Vector<uint8_t> m_labelVector;
 };
 
 } // namespace WebCore
index 61f3a26..78f5a1b 100644 (file)
@@ -36,6 +36,15 @@ public:
     size_t saltLength;
 
     Class parametersClass() const final { return Class::RsaPssParams; }
+
+    CryptoAlgorithmRsaPssParams isolatedCopy() const
+    {
+        CryptoAlgorithmRsaPssParams result;
+        result.identifier = identifier;
+        result.saltLength = saltLength;
+
+        return result;
+    }
 };
 
 } // namespace WebCore