Changeset 208918 in webkit
- Timestamp:
- Nov 18, 2016 8:38:59 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 31 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r208917 r208918 1 2016-11-18 Jiewen Tan <jiewen_tan@apple.com> 2 3 Update SubtleCrypto::decrypt to match the latest spec 4 https://bugs.webkit.org/show_bug.cgi?id=164739 5 <rdar://problem/29257848> 6 7 Reviewed by Brent Fulgham. 8 9 * crypto/subtle/aes-cbc-decrypt-malformed-parameters-expected.txt: Added. 10 * crypto/subtle/aes-cbc-decrypt-malformed-parameters.html: Added. 11 * crypto/subtle/aes-cbc-generate-key-encrypt-decrypt-expected.txt: Added. 12 * crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html: Added. 13 * crypto/subtle/aes-cbc-import-key-decrypt-expected.txt: Added. 14 * crypto/subtle/aes-cbc-import-key-decrypt.html: Added. 15 * crypto/subtle/decrypt-malformed-parameters-expected.txt: Added. 16 * crypto/subtle/decrypt-malformed-parameters.html: Added. 17 * crypto/subtle/rsa-oaep-decrypt-malformed-parameters-expected.txt: Added. 18 * crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html: Added. 19 * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-expected.txt: Added. 20 * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label-expected.txt: Added. 21 * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html: Added. 22 * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html: Added. 23 * crypto/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added. 24 * crypto/subtle/rsa-oaep-import-key-decrypt-label-expected.txt: Added. 25 * crypto/subtle/rsa-oaep-import-key-decrypt-label.html: Added. 26 * crypto/subtle/rsa-oaep-import-key-decrypt.html: Added. 27 * crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt-expected.txt: Added. 28 * crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html: Added. 29 * crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added. 30 * crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added. 31 * crypto/workers/subtle/aes-cbc-import-key-decrypt-expected.txt: Added. 32 * crypto/workers/subtle/aes-cbc-import-key-decrypt.html: Added. 33 * crypto/workers/subtle/resources/aes-cbc-import-key-decrypt.js: Added. 34 * crypto/workers/subtle/resources/rsa-oaep-import-key-decrypt.js: Added. 35 * crypto/workers/subtle/resources/rsaes-pkcs1-v1_5-import-key-decrypt.js: Added. 36 * crypto/workers/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added. 37 * crypto/workers/subtle/rsa-oaep-import-key-decrypt.html: Added. 38 * crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added. 39 * crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added. 40 1 41 2016-11-18 Chris Dumez <cdumez@apple.com> 2 42 -
trunk/LayoutTests/imported/w3c/ChangeLog
r208909 r208918 1 2016-11-18 Jiewen Tan <jiewen_tan@apple.com> 2 3 Update SubtleCrypto::decrypt to match the latest spec 4 https://bugs.webkit.org/show_bug.cgi?id=164739 5 <rdar://problem/29257848> 6 7 Reviewed by Brent Fulgham. 8 9 * WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt: 10 * WebCryptoAPI/idlharness-expected.txt: 11 1 12 2016-11-18 Alex Christensen <achristensen@webkit.org> 2 13 -
trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt
r208891 r208918 8 8 PASS AES-CBC 192-bit key with altered plaintext 9 9 PASS AES-CBC 256-bit key with altered plaintext 10 FAIL AES-CBC 128-bit key decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 11 FAIL AES-CBC 192-bit key decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 12 FAIL AES-CBC 256-bit key decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 13 FAIL AES-CBC 128-bit key decryption with altered ciphertext subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, ciphertext)', 'subtle.decrypt' is undefined) 14 FAIL AES-CBC 192-bit key decryption with altered ciphertext subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, ciphertext)', 'subtle.decrypt' is undefined) 15 FAIL AES-CBC 256-bit key decryption with altered ciphertext subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, ciphertext)', 'subtle.decrypt' is undefined) 10 PASS AES-CBC 128-bit key decryption 11 PASS AES-CBC 192-bit key decryption 12 PASS AES-CBC 256-bit key decryption 13 PASS AES-CBC 128-bit key decryption with altered ciphertext 14 PASS AES-CBC 192-bit key decryption with altered ciphertext 15 PASS AES-CBC 256-bit key decryption with altered ciphertext 16 16 PASS AES-CBC 128-bit key without encrypt usage 17 17 PASS AES-CBC 192-bit key without encrypt usage … … 20 20 FAIL AES-CBC 192-bit key with mismatched key and algorithm assert_equals: Mismatch should cause InvalidAccessError instead of The operation is not supported. expected "InvalidAccessError" but got "NotSupportedError" 21 21 FAIL AES-CBC 256-bit key with mismatched key and algorithm assert_equals: Mismatch should cause InvalidAccessError instead of The operation is not supported. expected "InvalidAccessError" but got "NotSupportedError" 22 FAIL AES-CBC 128-bit key without decrypt usage subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 23 FAIL AES-CBC 192-bit key without decrypt usage subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 24 FAIL AES-CBC 256-bit key without decrypt usage subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 22 PASS AES-CBC 128-bit key without decrypt usage 23 PASS AES-CBC 192-bit key without decrypt usage 24 PASS AES-CBC 256-bit key without decrypt usage 25 25 PASS AES-CBC 128-bit key, 64-bit IV 26 26 PASS AES-CBC 128-bit key, 192-bit IV … … 29 29 PASS AES-CBC 256-bit key, 64-bit IV 30 30 PASS AES-CBC 256-bit key, 192-bit IV 31 FAIL AES-CBC 128-bit key, 64-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 32 FAIL AES-CBC 128-bit key, 192-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 33 FAIL AES-CBC 192-bit key, 64-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 34 FAIL AES-CBC 192-bit key, 192-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 35 FAIL AES-CBC 256-bit key, 64-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 36 FAIL AES-CBC 256-bit key, 192-bit IV decryption subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined) 37 FAIL AES-CBC 128-bit key, zeroPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)38 FAIL AES-CBC 128-bit key, bigPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)39 FAIL AES-CBC 128-bit key, inconsistentPadChars subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)40 FAIL AES-CBC 192-bit key, zeroPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)41 FAIL AES-CBC 192-bit key, bigPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)42 FAIL AES-CBC 192-bit key, inconsistentPadChars subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)43 FAIL AES-CBC 256-bit key, zeroPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)44 FAIL AES-CBC 256-bit key, bigPadChar subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)45 FAIL AES-CBC 256-bit key, inconsistentPadChars subtle.decrypt is not a function. (In 'subtle.decrypt(vector.algorithm, vector.key, vector.result)', 'subtle.decrypt' is undefined)31 PASS AES-CBC 128-bit key, 64-bit IV decryption 32 PASS AES-CBC 128-bit key, 192-bit IV decryption 33 PASS AES-CBC 192-bit key, 64-bit IV decryption 34 PASS AES-CBC 192-bit key, 192-bit IV decryption 35 PASS AES-CBC 256-bit key, 64-bit IV decryption 36 PASS AES-CBC 256-bit key, 192-bit IV decryption 37 FAIL AES-CBC 128-bit key, zeroPadChar assert_unreached: should have thrown exception for test AES-CBC 128-bit key, zeroPadChar Reached unreachable code 38 FAIL AES-CBC 128-bit key, bigPadChar assert_unreached: should have thrown exception for test AES-CBC 128-bit key, bigPadChar Reached unreachable code 39 FAIL AES-CBC 128-bit key, inconsistentPadChars assert_unreached: should have thrown exception for test AES-CBC 128-bit key, inconsistentPadChars Reached unreachable code 40 FAIL AES-CBC 192-bit key, zeroPadChar assert_unreached: should have thrown exception for test AES-CBC 192-bit key, zeroPadChar Reached unreachable code 41 FAIL AES-CBC 192-bit key, bigPadChar assert_unreached: should have thrown exception for test AES-CBC 192-bit key, bigPadChar Reached unreachable code 42 FAIL AES-CBC 192-bit key, inconsistentPadChars assert_unreached: should have thrown exception for test AES-CBC 192-bit key, inconsistentPadChars Reached unreachable code 43 FAIL AES-CBC 256-bit key, zeroPadChar assert_unreached: should have thrown exception for test AES-CBC 256-bit key, zeroPadChar Reached unreachable code 44 FAIL AES-CBC 256-bit key, bigPadChar assert_unreached: should have thrown exception for test AES-CBC 256-bit key, bigPadChar Reached unreachable code 45 FAIL AES-CBC 256-bit key, inconsistentPadChars assert_unreached: should have thrown exception for test AES-CBC 256-bit key, inconsistentPadChars Reached unreachable code 46 46 -
trunk/LayoutTests/imported/w3c/WebCryptoAPI/idlharness-expected.txt
r208891 r208918 46 46 PASS SubtleCrypto interface: crypto.subtle must inherit property "encrypt" with the proper type (0) 47 47 PASS SubtleCrypto interface: calling encrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError 48 FAIL SubtleCrypto interface: crypto.subtle must inherit property "decrypt" with the proper type (1) assert_inherits: property "decrypt" not found in prototype chain 49 FAIL SubtleCrypto interface: calling decrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "decrypt" not found in prototype chain 48 PASS SubtleCrypto interface: crypto.subtle must inherit property "decrypt" with the proper type (1) 49 PASS SubtleCrypto interface: calling decrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError 50 50 FAIL SubtleCrypto interface: crypto.subtle must inherit property "sign" with the proper type (2) assert_inherits: property "sign" not found in prototype chain 51 51 FAIL SubtleCrypto interface: calling sign(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "sign" not found in prototype chain -
trunk/Source/WebCore/ChangeLog
r208917 r208918 1 2016-11-18 Jiewen Tan <jiewen_tan@apple.com> 2 3 Update SubtleCrypto::decrypt to match the latest spec 4 https://bugs.webkit.org/show_bug.cgi?id=164739 5 <rdar://problem/29257848> 6 7 Reviewed by Brent Fulgham. 8 9 This patch does following few things: 10 1. It updates the SubtleCrypto::decrypt method to match the latest spec: 11 https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-decrypt. 12 It also refers to the latest Editor's Draft to a certain degree: 13 https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-decrypt. 14 2. It implements decrypt operations of the following algorithms: AES-CBC, 15 RSAES-PKCS1-V1_5, and RSA-OAEP. 16 17 Tests: crypto/subtle/aes-cbc-decrypt-malformed-parameters.html 18 crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html 19 crypto/subtle/aes-cbc-import-key-decrypt.html 20 crypto/subtle/decrypt-malformed-parameters.html 21 crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html 22 crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html 23 crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html 24 crypto/subtle/rsa-oaep-import-key-decrypt-label.html 25 crypto/subtle/rsa-oaep-import-key-decrypt.html 26 crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html 27 crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html 28 crypto/workers/subtle/aes-cbc-import-key-decrypt.html 29 crypto/workers/subtle/rsa-oaep-import-key-decrypt.html 30 crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html 31 32 * bindings/js/JSSubtleCryptoCustom.cpp: 33 (WebCore::normalizeCryptoAlgorithmParameters): 34 (WebCore::toCryptoKey): 35 (WebCore::toVector): 36 (WebCore::jsSubtleCryptoFunctionEncryptPromise): 37 (WebCore::jsSubtleCryptoFunctionDecryptPromise): 38 (WebCore::jsSubtleCryptoFunctionExportKeyPromise): 39 (WebCore::JSSubtleCrypto::decrypt): 40 * crypto/CryptoAlgorithm.cpp: 41 (WebCore::CryptoAlgorithm::decrypt): 42 * crypto/CryptoAlgorithm.h: 43 * crypto/SubtleCrypto.idl: 44 * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: 45 (WebCore::CryptoAlgorithmAES_CBC::decrypt): 46 * crypto/algorithms/CryptoAlgorithmAES_CBC.h: 47 * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp: 48 (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt): 49 * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h: 50 * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp: 51 (WebCore::CryptoAlgorithmRSA_OAEP::decrypt): 52 * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h: 53 * crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp: 54 (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt): 55 * crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp: 56 (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt): 57 * crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp: 58 (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt): 59 * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp: 60 (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt): 61 * crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp: 62 (WebCore::decryptRSAES_PKCS1_v1_5): 63 (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt): 64 * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp: 65 (WebCore::decryptRSA_OAEP): 66 (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt): 67 1 68 2016-11-18 Chris Dumez <cdumez@apple.com> 2 69 -
trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
r208891 r208918 54 54 enum class Operations { 55 55 Encrypt, 56 Decrypt, 56 57 Digest, 57 58 GenerateKey, … … 95 96 switch (operation) { 96 97 case Operations::Encrypt: 98 case Operations::Decrypt: 97 99 switch (*identifier) { 98 100 case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5: … … 389 391 } 390 392 393 static RefPtr<CryptoKey> toCryptoKey(ExecState& state, JSValue value) 394 { 395 VM& vm = state.vm(); 396 auto scope = DECLARE_THROW_SCOPE(vm); 397 398 RefPtr<CryptoKey> result = JSCryptoKey::toWrapped(value); 399 if (!result) { 400 throwTypeError(&state, scope, ASCIILiteral("Invalid CryptoKey")); 401 return nullptr; 402 } 403 return result; 404 } 405 406 static Vector<uint8_t> toVector(ExecState& state, JSValue value) 407 { 408 VM& vm = state.vm(); 409 auto scope = DECLARE_THROW_SCOPE(vm); 410 411 BufferSource data = convert<IDLBufferSource>(state, value); 412 RETURN_IF_EXCEPTION(scope, { }); 413 Vector<uint8_t> dataVector; 414 dataVector.append(data.data(), data.length()); 415 416 return dataVector; 417 } 418 391 419 static void jsSubtleCryptoFunctionEncryptPromise(ExecState& state, Ref<DeferredPromise>&& promise) 392 420 { … … 402 430 RETURN_IF_EXCEPTION(scope, void()); 403 431 404 RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1)); 405 if (!key) { 406 promise->reject(TypeError, ASCIILiteral("Invalid CryptoKey")); 407 return; 408 } 409 410 BufferSource data = convert<IDLBufferSource>(state, state.uncheckedArgument(2)); 411 RETURN_IF_EXCEPTION(scope, void()); 412 Vector<uint8_t> dataVector; 413 dataVector.append(data.data(), data.length()); 432 auto key = toCryptoKey(state, state.uncheckedArgument(1)); 433 RETURN_IF_EXCEPTION(scope, void()); 434 435 auto data = toVector(state, state.uncheckedArgument(2)); 436 RETURN_IF_EXCEPTION(scope, void()); 414 437 415 438 if (params->identifier != key->algorithmIdentifier()) { … … 436 459 JSSubtleCrypto* subtle = jsDynamicDowncast<JSSubtleCrypto*>(state.thisValue()); 437 460 ASSERT(subtle); 438 algorithm->encrypt(WTFMove(params), key.releaseNonNull(), WTFMove(dataVector), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue()); 461 algorithm->encrypt(WTFMove(params), key.releaseNonNull(), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue()); 462 } 463 464 static void jsSubtleCryptoFunctionDecryptPromise(ExecState& state, Ref<DeferredPromise>&& promise) 465 { 466 VM& vm = state.vm(); 467 auto scope = DECLARE_THROW_SCOPE(vm); 468 469 if (UNLIKELY(state.argumentCount() < 3)) { 470 promise->reject<JSValue>(createNotEnoughArgumentsError(&state)); 471 return; 472 } 473 474 auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::Decrypt); 475 RETURN_IF_EXCEPTION(scope, void()); 476 477 auto key = toCryptoKey(state, state.uncheckedArgument(1)); 478 RETURN_IF_EXCEPTION(scope, void()); 479 480 auto data = toVector(state, state.uncheckedArgument(2)); 481 RETURN_IF_EXCEPTION(scope, void()); 482 483 if (params->identifier != key->algorithmIdentifier()) { 484 promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't match AlgorithmIdentifier")); 485 return; 486 } 487 488 if (!key->allows(CryptoKeyUsageDecrypt)) { 489 promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't support decryption")); 490 return; 491 } 492 493 auto algorithm = createAlgorithm(state, key->algorithmIdentifier()); 494 RETURN_IF_EXCEPTION(scope, void()); 495 496 auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& cipherText) mutable { 497 fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), cipherText.data(), cipherText.size()); 498 return; 499 }; 500 auto exceptionCallback = [capturedPromise = promise.copyRef()](ExceptionCode ec) mutable { 501 rejectWithException(WTFMove(capturedPromise), ec); 502 }; 503 504 JSSubtleCrypto* subtle = jsDynamicDowncast<JSSubtleCrypto*>(state.thisValue()); 505 ASSERT(subtle); 506 algorithm->decrypt(WTFMove(params), key.releaseNonNull(), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue()); 439 507 } 440 508 … … 546 614 RETURN_IF_EXCEPTION(scope, void()); 547 615 548 RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1)); 549 if (!key) { 550 promise->reject(TypeError, ASCIILiteral("Invalid CryptoKey")); 551 return; 552 } 616 auto key = toCryptoKey(state, state.uncheckedArgument(1)); 617 RETURN_IF_EXCEPTION(scope, void()); 553 618 554 619 switch (key->algorithmIdentifier()) { … … 608 673 } 609 674 675 JSValue JSSubtleCrypto::decrypt(ExecState& state) 676 { 677 return callPromiseFunction<jsSubtleCryptoFunctionDecryptPromise, PromiseExecutionScope::WindowOrWorker>(state); 678 } 679 610 680 JSValue JSSubtleCrypto::generateKey(ExecState& state) 611 681 { -
trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp
r208891 r208918 34 34 35 35 void CryptoAlgorithm::encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&) 36 { 37 exceptionCallback(NOT_SUPPORTED_ERR); 38 } 39 40 void CryptoAlgorithm::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&) 36 41 { 37 42 exceptionCallback(NOT_SUPPORTED_ERR); -
trunk/Source/WebCore/crypto/CryptoAlgorithm.h
r208891 r208918 66 66 67 67 virtual void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 68 virtual void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 68 69 virtual void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&); 69 70 virtual void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&); -
trunk/Source/WebCore/crypto/SubtleCrypto.idl
r208891 r208918 33 33 ] interface SubtleCrypto { 34 34 [Custom] Promise<any> encrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data); 35 [Custom] Promise<any> decrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data); 35 36 // FIXME: Should this return a Promise<(CryptoKey or CryptoKeyPair)>? 36 37 [Custom] Promise<any> generateKey(AlgorithmIdentifier algorithm, boolean extractable, sequence<CryptoKeyUsage> keyUsages); -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp
r208891 r208918 78 78 } 79 79 80 void CryptoAlgorithmAES_CBC::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 81 { 82 ASSERT(parameters); 83 auto& aesParameters = downcast<CryptoAlgorithmAesCbcParams>(*parameters); 84 if (aesParameters.ivVector().size() != IVSIZE) { 85 exceptionCallback(OperationError); 86 return; 87 } 88 platformDecrypt(WTFMove(parameters), WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue); 89 } 90 80 91 void CryptoAlgorithmAES_CBC::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&) 81 92 { -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h
r208891 r208918 46 46 47 47 void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final; 48 void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final; 48 49 void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 49 50 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; … … 57 58 bool keyAlgorithmMatches(const CryptoAlgorithmAesCbcParamsDeprecated& algorithmParameters, const CryptoKey&) const; 58 59 void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 60 void platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 59 61 ExceptionOr<void> platformEncrypt(const CryptoAlgorithmAesCbcParamsDeprecated&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback); 60 62 ExceptionOr<void> platformDecrypt(const CryptoAlgorithmAesCbcParamsDeprecated&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback); -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp
r208891 r208918 69 69 } 70 70 71 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) 72 { 73 if (key->type() != CryptoKeyType::Private) { 74 exceptionCallback(INVALID_ACCESS_ERR); 75 return; 76 } 77 platformDecrypt(WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue); 78 } 79 71 80 void CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context) 72 81 { -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h
r208891 r208918 46 46 47 47 void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final; 48 void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final; 48 49 void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 49 50 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; … … 57 58 bool keyAlgorithmMatches(const CryptoKey&) const; 58 59 void platformEncrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 60 void platformDecrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 59 61 ExceptionOr<void> platformEncrypt(const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback); 60 62 ExceptionOr<void> platformDecrypt(const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback); -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp
r208891 r208918 79 79 } 80 80 81 void CryptoAlgorithmRSA_OAEP::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 82 { 83 ASSERT(parameters); 84 if (key->type() != CryptoKeyType::Private) { 85 exceptionCallback(INVALID_ACCESS_ERR); 86 return; 87 } 88 platformDecrypt(WTFMove(parameters), WTFMove(key), WTFMove(cipherText), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue); 89 } 81 90 82 91 void CryptoAlgorithmRSA_OAEP::generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context) -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.h
r208891 r208918 46 46 47 47 void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final; 48 void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final; 48 49 void generateKey(const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 49 50 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; … … 57 58 bool keyAlgorithmMatches(const CryptoAlgorithmRsaOaepParamsDeprecated& algorithmParameters, const CryptoKey&) const; 58 59 void platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 60 void platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 59 61 ExceptionOr<void> platformEncrypt(const CryptoAlgorithmRsaOaepParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback); 60 62 ExceptionOr<void> platformDecrypt(const CryptoAlgorithmRsaOaepParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback); -
trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp
r208891 r208918 39 39 } 40 40 41 void CryptoAlgorithmAES_CBC::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) 42 { 43 notImplemented(); 44 } 45 41 46 ExceptionOr<void> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcParamsDeprecated&, const CryptoKeyAES&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&) 42 47 { -
trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp
r208891 r208918 40 40 } 41 41 42 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) 43 { 44 notImplemented(); 45 } 46 42 47 ExceptionOr<void> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&) 43 48 { -
trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp
r208891 r208918 39 39 } 40 40 41 void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) 42 { 43 notImplemented(); 44 } 45 41 46 ExceptionOr<void> CryptoAlgorithmRSA_OAEP::platformEncrypt(const CryptoAlgorithmRsaOaepParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&) 42 47 { -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
r208891 r208918 96 96 } 97 97 98 void CryptoAlgorithmAES_CBC::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 99 { 100 context.ref(); 101 workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 102 auto& aesParameters = downcast<CryptoAlgorithmAesCbcParams>(*parameters); 103 auto& aesKey = downcast<CryptoKeyAES>(key.get()); 104 assert(aesParameters.ivVector().size() == kCCBlockSizeAES128); 105 auto result = transformAES_CBC(kCCDecrypt, aesParameters.ivVector().data(), aesKey.key(), cipherText.data(), cipherText.size()); 106 if (result.hasException()) { 107 context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) { 108 exceptionCallback(ec); 109 context.deref(); 110 }); 111 return; 112 } 113 context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) { 114 callback(result); 115 context.deref(); 116 }); 117 }); 118 } 119 98 120 ExceptionOr<void> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcParamsDeprecated& parameters, const CryptoKeyAES& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback) 99 121 { -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp
r208891 r208918 48 48 } 49 49 50 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 51 // https://bugs.webkit.org/show_bug.cgi?id=164939 52 static ExceptionOr<Vector<uint8_t>> decryptRSAES_PKCS1_v1_5(const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) 53 { 54 Vector<uint8_t> plainText(keyLength / 8); // Per Step 1 of https://tools.ietf.org/html/rfc3447#section-7.2.1 55 size_t plainTextLength = plainText.size(); 56 if (CCRSACryptorDecrypt(key, ccPKCS1Padding, data, dataLength, plainText.data(), &plainTextLength, 0, 0, kCCDigestNone)) 57 return Exception { OperationError }; 58 59 plainText.resize(plainTextLength); 60 return WTFMove(plainText); 61 } 62 50 63 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 51 64 { … … 54 67 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 55 68 auto result = encryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText.data(), plainText.size()); 69 if (result.hasException()) { 70 context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) { 71 exceptionCallback(ec); 72 context.deref(); 73 }); 74 return; 75 } 76 context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) { 77 callback(result); 78 context.deref(); 79 }); 80 }); 81 } 82 83 void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 84 { 85 context.ref(); 86 workQueue.dispatch([key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 87 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 88 auto result = decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText.data(), cipherText.size()); 56 89 if (result.hasException()) { 57 90 context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) { … … 79 112 } 80 113 81 // FIXME: We should get rid of the magic number 1024. It only makes sense when key length < 8192 bits82 114 ExceptionOr<void> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback) 83 115 { 84 Vector<uint8_t> plainText(1024); 85 size_t plainTextLength = plainText.size(); 86 CCCryptorStatus status = CCRSACryptorDecrypt(key.platformKey(), ccPKCS1Padding, data.first, data.second, plainText.data(), &plainTextLength, 0, 0, kCCDigestNone); 87 if (status) { 116 auto result = decryptRSAES_PKCS1_v1_5(key.platformKey(), key.keySizeInBits(), data.first, data.second); 117 if (result.hasException()) { 88 118 failureCallback(); 89 119 return { }; 90 120 } 91 92 plainText.resize(plainTextLength); 93 callback(plainText); 121 callback(result.releaseReturnValue()); 94 122 return { }; 95 123 } -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp
r208891 r208918 54 54 } 55 55 56 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 57 // https://bugs.webkit.org/show_bug.cgi?id=164939 58 static ExceptionOr<Vector<uint8_t>> decryptRSA_OAEP(CryptoAlgorithmIdentifier hash, const Vector<uint8_t>& label, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) 59 { 60 CCDigestAlgorithm digestAlgorithm; 61 if (!getCommonCryptoDigestAlgorithm(hash, digestAlgorithm)) 62 return Exception { OperationError }; 63 64 Vector<uint8_t> plainText(keyLength / 8); // Per Step 1.b of https://tools.ietf.org/html/rfc3447#section-7.1.1 65 size_t plainTextLength = plainText.size(); 66 if (CCRSACryptorDecrypt(key, ccOAEPPadding, data, dataLength, plainText.data(), &plainTextLength, label.data(), label.size(), digestAlgorithm)) 67 return Exception { OperationError }; 68 69 plainText.resize(plainTextLength); 70 return WTFMove(plainText); 71 } 72 56 73 void CryptoAlgorithmRSA_OAEP::platformEncrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& plainText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 57 74 { … … 61 78 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 62 79 auto result = encryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText.data(), plainText.size()); 80 if (result.hasException()) { 81 context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) { 82 exceptionCallback(ec); 83 context.deref(); 84 }); 85 return; 86 } 87 context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) { 88 callback(result); 89 context.deref(); 90 }); 91 }); 92 } 93 94 void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 95 { 96 context.ref(); 97 workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 98 auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters); 99 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 100 auto result = decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText.data(), cipherText.size()); 63 101 if (result.hasException()) { 64 102 context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) { … … 87 125 } 88 126 89 // FIXME: We should get rid of the magic number 1024. It only makes sense when key length < 8192 bits90 127 ExceptionOr<void> CryptoAlgorithmRSA_OAEP::platformDecrypt(const CryptoAlgorithmRsaOaepParamsDeprecated& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback) 91 128 { 92 CCDigestAlgorithm digestAlgorithm; 93 if (!getCommonCryptoDigestAlgorithm(parameters.hash, digestAlgorithm)) 94 return Exception { NOT_SUPPORTED_ERR }; 95 96 Vector<uint8_t> plainText(1024); 97 size_t plainTextLength = plainText.size(); 98 CCCryptorStatus status = CCRSACryptorDecrypt(key.platformKey(), ccOAEPPadding, data.first, data.second, plainText.data(), &plainTextLength, parameters.label.data(), parameters.label.size(), digestAlgorithm); 99 if (status) { 129 ASSERT(parameters.hasLabel || parameters.label.isEmpty()); 130 auto result = decryptRSA_OAEP(parameters.hash, parameters.label, key.platformKey(), key.keySizeInBits(), data.first, data.second); 131 if (result.hasException()) { 100 132 failureCallback(); 101 133 return { }; 102 134 } 103 104 plainText.resize(plainTextLength); 105 callback(plainText); 135 callback(result.releaseReturnValue()); 106 136 return { }; 107 137 }
Note: See TracChangeset
for help on using the changeset viewer.