Changeset 209092 in webkit
- Timestamp:
- Nov 29, 2016 2:52:03 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 28 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r209091 r209092 1 2016-11-22 Jiewen Tan <jiewen_tan@apple.com> 2 3 Update SubtleCrypto::sign to match the latest spec 4 https://bugs.webkit.org/show_bug.cgi?id=164740 5 <rdar://problem/29257864> 6 7 Reviewed by Brent Fulgham. 8 9 * crypto/subtle/hmac-import-key-sign-sha1-expected.txt: Added. 10 * crypto/subtle/hmac-import-key-sign-sha1.html: Added. 11 * crypto/subtle/hmac-import-key-sign-sha224-expected.txt: Added. 12 * crypto/subtle/hmac-import-key-sign-sha224.html: Added. 13 * crypto/subtle/hmac-import-key-sign-sha256-expected.txt: Added. 14 * crypto/subtle/hmac-import-key-sign-sha256.html: Added. 15 * crypto/subtle/hmac-import-key-sign-sha384-expected.txt: Added. 16 * crypto/subtle/hmac-import-key-sign-sha384.html: Added. 17 * crypto/subtle/hmac-import-key-sign-sha512-expected.txt: Added. 18 * crypto/subtle/hmac-import-key-sign-sha512.html: Added. 19 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1-expected.txt: Added. 20 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html: Added. 21 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224-expected.txt: Added. 22 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html: Added. 23 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256-expected.txt: Added. 24 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html: Added. 25 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384-expected.txt: Added. 26 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html: Added. 27 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512-expected.txt: Added. 28 * crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html: Added. 29 * crypto/subtle/sign-malformed-parameters-expected.txt: Added. 30 * crypto/subtle/sign-malformed-parameters.html: Added. 31 * crypto/workers/subtle/hmac-import-key-sign-expected.txt: Added. 32 * crypto/workers/subtle/hmac-import-key-sign.html: Added. 33 * crypto/workers/subtle/resources/hmac-import-key-sign.js: Added. 34 * crypto/workers/subtle/resources/rsassa-pkcs1-v1_5-import-key-sign.js: Added. 35 * crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign-expected.txt: Added. 36 * crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign.html: Added. 37 1 38 2016-11-29 Chris Dumez <cdumez@apple.com> 2 39 -
trunk/LayoutTests/imported/w3c/ChangeLog
r208918 r209092 1 2016-11-22 Jiewen Tan <jiewen_tan@apple.com> 2 3 Update SubtleCrypto::sign to match the latest spec 4 https://bugs.webkit.org/show_bug.cgi?id=164740 5 <rdar://problem/29257864> 6 7 Reviewed by Brent Fulgham. 8 9 * WebCryptoAPI/idlharness-expected.txt: 10 1 11 2016-11-18 Jiewen Tan <jiewen_tan@apple.com> 2 12 -
trunk/LayoutTests/imported/w3c/WebCryptoAPI/idlharness-expected.txt
r208918 r209092 48 48 PASS SubtleCrypto interface: crypto.subtle must inherit property "decrypt" with the proper type (1) 49 49 PASS SubtleCrypto interface: calling decrypt(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError 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 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 50 PASS SubtleCrypto interface: crypto.subtle must inherit property "sign" with the proper type (2) 51 PASS SubtleCrypto interface: calling sign(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError 52 52 FAIL SubtleCrypto interface: crypto.subtle must inherit property "verify" with the proper type (3) assert_inherits: property "verify" not found in prototype chain 53 53 FAIL SubtleCrypto interface: calling verify(AlgorithmIdentifier,CryptoKey,BufferSource,BufferSource) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "verify" not found in prototype chain -
trunk/Source/WebCore/ChangeLog
r209091 r209092 1 2016-11-22 Jiewen Tan <jiewen_tan@apple.com> 2 3 Update SubtleCrypto::sign to match the latest spec 4 https://bugs.webkit.org/show_bug.cgi?id=164740 5 <rdar://problem/29257864> 6 7 Reviewed by Brent Fulgham. 8 9 This patch does following few things: 10 1. It updates the SubtleCrypto::sign method to match the latest spec: 11 https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-sign. 12 It also refers to the latest Editor's Draft to a certain degree: 13 https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-sign. 14 2. It implements sign operations of the following algorithms: HMAC, and 15 RSASSA-PKCS1-V1_5. 16 3. It also replaces promise.copyRef() with WTFMove(promise) for all the 17 capture lists of exception callbacks in promise functions. 18 19 Tests: crypto/subtle/hmac-import-key-sign-sha1.html 20 crypto/subtle/hmac-import-key-sign-sha224.html 21 crypto/subtle/hmac-import-key-sign-sha256.html 22 crypto/subtle/hmac-import-key-sign-sha384.html 23 crypto/subtle/hmac-import-key-sign-sha512.html 24 crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html 25 crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html 26 crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html 27 crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html 28 crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html 29 crypto/subtle/sign-malformed-parameters.html 30 crypto/workers/subtle/hmac-import-key-sign.html 31 crypto/workers/subtle/rsassa-pkcs1-v1_5-import-key-sign.html 32 33 * bindings/js/JSSubtleCryptoCustom.cpp: 34 (WebCore::normalizeCryptoAlgorithmParameters): 35 (WebCore::jsSubtleCryptoFunctionDecryptPromise): 36 Fix a minor bug. 37 (WebCore::jsSubtleCryptoFunctionEncryptPromise): 38 (WebCore::jsSubtleCryptoFunctionDecryptPromise): 39 (WebCore::jsSubtleCryptoFunctionSignPromise): 40 (WebCore::jsSubtleCryptoFunctionGenerateKeyPromise): 41 (WebCore::jsSubtleCryptoFunctionImportKeyPromise): 42 (WebCore::jsSubtleCryptoFunctionExportKeyPromise): 43 (WebCore::JSSubtleCrypto::sign): 44 * crypto/CryptoAlgorithm.cpp: 45 (WebCore::CryptoAlgorithm::sign): 46 * crypto/CryptoAlgorithm.h: 47 * crypto/SubtleCrypto.idl: 48 * crypto/algorithms/CryptoAlgorithmHMAC.cpp: 49 (WebCore::CryptoAlgorithmHMAC::sign): 50 * crypto/algorithms/CryptoAlgorithmHMAC.h: 51 * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp: 52 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign): 53 * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h: 54 * crypto/gcrypt/CryptoAlgorithmHMACGCrypt.cpp: 55 (WebCore::CryptoAlgorithmHMAC::platformSign): 56 * crypto/gnutls/CryptoAlgorithmHMACGnuTLS.cpp: 57 (WebCore::CryptoAlgorithmHMAC::platformSign): 58 * crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp: 59 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign): 60 * crypto/mac/CryptoAlgorithmHMACMac.cpp: 61 (WebCore::commonCryptoHMACAlgorithm): 62 (WebCore::calculateSignature): 63 Remove a null guardance since the depending bug is resolved. 64 (WebCore::CryptoAlgorithmHMAC::platformSign): 65 (WebCore::CryptoAlgorithmHMAC::platformVerify): 66 * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: 67 (WebCore::signRSASSA_PKCS1_v1_5): 68 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign): 69 1 70 2016-11-29 Chris Dumez <cdumez@apple.com> 2 71 -
trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
r209077 r209092 55 55 Encrypt, 56 56 Decrypt, 57 Sign, 57 58 Digest, 58 59 GenerateKey, … … 113 114 break; 114 115 } 116 default: 117 setDOMException(&state, NOT_SUPPORTED_ERR); 118 return nullptr; 119 } 120 break; 121 case Operations::Sign: 122 switch (*identifier) { 123 case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5: 124 case CryptoAlgorithmIdentifier::HMAC: 125 result = std::make_unique<CryptoAlgorithmParameters>(params); 126 break; 115 127 default: 116 128 setDOMException(&state, NOT_SUPPORTED_ERR); … … 453 465 return; 454 466 }; 455 auto exceptionCallback = [capturedPromise = promise.copyRef()](ExceptionCode ec) mutable {467 auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable { 456 468 rejectWithException(WTFMove(capturedPromise), ec); 457 469 }; … … 494 506 RETURN_IF_EXCEPTION(scope, void()); 495 507 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 {508 auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& plainText) mutable { 509 fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), plainText.data(), plainText.size()); 510 return; 511 }; 512 auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable { 501 513 rejectWithException(WTFMove(capturedPromise), ec); 502 514 }; … … 505 517 ASSERT(subtle); 506 518 algorithm->decrypt(WTFMove(params), key.releaseNonNull(), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue()); 519 } 520 521 static void jsSubtleCryptoFunctionSignPromise(ExecState& state, Ref<DeferredPromise>&& promise) 522 { 523 VM& vm = state.vm(); 524 auto scope = DECLARE_THROW_SCOPE(vm); 525 526 if (UNLIKELY(state.argumentCount() < 3)) { 527 promise->reject<JSValue>(createNotEnoughArgumentsError(&state)); 528 return; 529 } 530 531 auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::Sign); 532 RETURN_IF_EXCEPTION(scope, void()); 533 534 auto key = toCryptoKey(state, state.uncheckedArgument(1)); 535 RETURN_IF_EXCEPTION(scope, void()); 536 537 auto data = toVector(state, state.uncheckedArgument(2)); 538 RETURN_IF_EXCEPTION(scope, void()); 539 540 if (params->identifier != key->algorithmIdentifier()) { 541 promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't match AlgorithmIdentifier")); 542 return; 543 } 544 545 if (!key->allows(CryptoKeyUsageSign)) { 546 promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't support signing")); 547 return; 548 } 549 550 auto algorithm = createAlgorithm(state, key->algorithmIdentifier()); 551 RETURN_IF_EXCEPTION(scope, void()); 552 553 auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& signature) mutable { 554 fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), signature.data(), signature.size()); 555 return; 556 }; 557 auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable { 558 rejectWithException(WTFMove(capturedPromise), ec); 559 }; 560 561 JSSubtleCrypto* subtle = jsDynamicDowncast<JSSubtleCrypto*>(state.thisValue()); 562 ASSERT(subtle); 563 algorithm->sign(key.releaseNonNull(), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue()); 507 564 } 508 565 … … 546 603 } 547 604 }; 548 auto exceptionCallback = [capturedPromise = promise.copyRef()](ExceptionCode ec) mutable {605 auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable { 549 606 rejectWithException(WTFMove(capturedPromise), ec); 550 607 }; … … 591 648 capturedPromise->resolve(key); 592 649 }; 593 auto exceptionCallback = [capturedPromise = promise.copyRef()](ExceptionCode ec) mutable {650 auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable { 594 651 rejectWithException(WTFMove(capturedPromise), ec); 595 652 }; … … 658 715 ASSERT_NOT_REACHED(); 659 716 }; 660 auto exceptionCallback = [capturedPromise = promise.copyRef()](ExceptionCode ec) mutable {717 auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable { 661 718 rejectWithException(WTFMove(capturedPromise), ec); 662 719 }; … … 678 735 } 679 736 737 JSValue JSSubtleCrypto::sign(ExecState& state) 738 { 739 return callPromiseFunction<jsSubtleCryptoFunctionSignPromise, PromiseExecutionScope::WindowOrWorker>(state); 740 } 741 680 742 JSValue JSSubtleCrypto::generateKey(ExecState& state) 681 743 { -
trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp
r209077 r209092 39 39 40 40 void CryptoAlgorithm::decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&) 41 { 42 exceptionCallback(NOT_SUPPORTED_ERR); 43 } 44 45 void CryptoAlgorithm::sign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&) 41 46 { 42 47 exceptionCallback(NOT_SUPPORTED_ERR); -
trunk/Source/WebCore/crypto/CryptoAlgorithm.h
r209077 r209092 67 67 virtual void encrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 68 68 virtual void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 69 virtual void sign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 69 70 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&); 70 71 virtual void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&); -
trunk/Source/WebCore/crypto/SubtleCrypto.idl
r208918 r209092 34 34 [Custom] Promise<any> encrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data); 35 35 [Custom] Promise<any> decrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data); 36 [Custom] Promise<any> sign(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data); 36 37 // FIXME: Should this return a Promise<(CryptoKey or CryptoKeyPair)>? 37 38 [Custom] Promise<any> generateKey(AlgorithmIdentifier algorithm, boolean extractable, sequence<CryptoKeyUsage> keyUsages); -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
r209077 r209092 70 70 } 71 71 72 void CryptoAlgorithmHMAC::sign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 73 { 74 platformSign(WTFMove(key), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue); 75 } 76 72 77 void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&) 73 78 { -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h
r209077 r209092 45 45 CryptoAlgorithmIdentifier identifier() const final; 46 46 47 void sign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final; 47 48 void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 48 49 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; … … 56 57 57 58 bool keyAlgorithmMatches(const CryptoAlgorithmHmacParamsDeprecated& algorithmParameters, const CryptoKey&) const; 59 void platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 58 60 ExceptionOr<void> platformSign(const CryptoAlgorithmHmacParamsDeprecated&, const CryptoKeyHMAC&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback); 59 61 ExceptionOr<void> platformVerify(const CryptoAlgorithmHmacParamsDeprecated&, const CryptoKeyHMAC&, const CryptoOperationData& signature, const CryptoOperationData&, BoolCallback&&, VoidCallback&& failureCallback); -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
r209077 r209092 69 69 } 70 70 71 void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 72 { 73 if (key->type() != CryptoKeyType::Private) { 74 exceptionCallback(INVALID_ACCESS_ERR); 75 return; 76 } 77 platformSign(WTFMove(key), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue); 78 } 79 71 80 void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context) 72 81 { -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h
r209077 r209092 45 45 CryptoAlgorithmIdentifier identifier() const final; 46 46 47 void sign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final; 47 48 void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 48 49 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; … … 55 56 56 57 bool keyAlgorithmMatches(const CryptoAlgorithmRsaSsaParamsDeprecated& algorithmParameters, const CryptoKey&) const; 58 void platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 57 59 ExceptionOr<void> platformSign(const CryptoAlgorithmRsaSsaParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback); 58 60 ExceptionOr<void> platformVerify(const CryptoAlgorithmRsaSsaParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData& signature, const CryptoOperationData&, BoolCallback&&, VoidCallback&& failureCallback); -
trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmHMACGCrypt.cpp
r208985 r209092 33 33 #include "CryptoKeyHMAC.h" 34 34 #include "ExceptionCode.h" 35 #include "NotImplemented.h" 35 36 #include <gcrypt.h> 36 37 #include <wtf/CryptographicUtilities.h> … … 97 98 } 98 99 100 void CryptoAlgorithmHMAC::platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) 101 { 102 notImplemented(); 103 } 104 99 105 ExceptionOr<void> CryptoAlgorithmHMAC::platformSign(const CryptoAlgorithmHmacParamsDeprecated& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback) 100 106 { -
trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmHMACGnuTLS.cpp
r208669 r209092 32 32 #include "CryptoKeyHMAC.h" 33 33 #include "ExceptionCode.h" 34 #include "NotImplemented.h" 34 35 #include <gnutls/gnutls.h> 35 36 #include <gnutls/crypto.h> … … 69 70 } 70 71 72 void CryptoAlgorithmHMAC::platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) 73 { 74 notImplemented(); 75 } 76 71 77 ExceptionOr<void> CryptoAlgorithmHMAC::platformSign(const CryptoAlgorithmHmacParamsDeprecated& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&&) 72 78 { -
trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp
r208669 r209092 36 36 namespace WebCore { 37 37 38 void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) 39 { 40 notImplemented(); 41 } 42 38 43 ExceptionOr<void> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParamsDeprecated&, const CryptoKeyRSA&, const CryptoOperationData&, VectorCallback&&, VoidCallback&&) 39 44 { -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
r208985 r209092 32 32 #include "CryptoKeyHMAC.h" 33 33 #include "ExceptionCode.h" 34 #include "ScriptExecutionContext.h" 34 35 #include <CommonCrypto/CommonHMAC.h> 35 36 #include <wtf/CryptographicUtilities.h> … … 55 56 } 56 57 57 static Vector<uint8_t> calculateSignature(CCHmacAlgorithm algorithm, const Vector<uint8_t>& key, const CryptoOperationData& data) 58 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 59 // https://bugs.webkit.org/show_bug.cgi?id=164939 60 static Vector<uint8_t> calculateSignature(CCHmacAlgorithm algorithm, const Vector<uint8_t>& key, const uint8_t* data, size_t dataLength) 58 61 { 59 62 size_t digestLength; … … 80 83 81 84 Vector<uint8_t> result(digestLength); 82 const void* keyData = key.data() ? key.data() : reinterpret_cast<const uint8_t*>(""); // <rdar://problem/15467425> HMAC crashes when key pointer is null. 83 CCHmac(algorithm, keyData, key.size(), data.first, data.second, result.data()); 85 CCHmac(algorithm, key.data(), key.size(), data, dataLength, result.data()); 84 86 return result; 87 } 88 89 void CryptoAlgorithmHMAC::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 90 { 91 context.ref(); 92 workQueue.dispatch([key = WTFMove(key), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 93 auto& hmacKey = downcast<CryptoKeyHMAC>(key.get()); 94 auto algorithm = commonCryptoHMACAlgorithm(hmacKey.hashAlgorithmIdentifier()); 95 if (!algorithm) { 96 // We should only dereference callbacks after being back to the Document/Worker threads. 97 context.postTask([exceptionCallback = WTFMove(exceptionCallback), callback = WTFMove(callback)](ScriptExecutionContext& context) { 98 exceptionCallback(OperationError); 99 context.deref(); 100 }); 101 return; 102 } 103 auto result = calculateSignature(*algorithm, hmacKey.key(), data.data(), data.size()); 104 // We should only dereference callbacks after being back to the Document/Worker threads. 105 context.postTask([callback = WTFMove(callback), result = WTFMove(result), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) { 106 callback(result); 107 context.deref(); 108 }); 109 }); 110 85 111 } 86 112 … … 90 116 if (!algorithm) 91 117 return Exception { NOT_SUPPORTED_ERR }; 92 callback(calculateSignature(*algorithm, key.key(), data ));118 callback(calculateSignature(*algorithm, key.key(), data.first, data.second)); 93 119 return { }; 94 120 } … … 100 126 return Exception { NOT_SUPPORTED_ERR }; 101 127 102 auto signature = calculateSignature(*algorithm, key.key(), data );128 auto signature = calculateSignature(*algorithm, key.key(), data.first, data.second); 103 129 104 130 // Using a constant time comparison to prevent timing attacks. -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
r208985 r209092 34 34 #include "CryptoKeyRSA.h" 35 35 #include "ExceptionCode.h" 36 #include "ScriptExecutionContext.h" 36 37 37 38 namespace WebCore { … … 55 56 } 56 57 58 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 59 // https://bugs.webkit.org/show_bug.cgi?id=164939 60 static ExceptionOr<Vector<uint8_t>> signRSASSA_PKCS1_v1_5(CryptoAlgorithmIdentifier hash, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) 61 { 62 CCDigestAlgorithm digestAlgorithm; 63 if (!getCommonCryptoDigestAlgorithm(hash, digestAlgorithm)) 64 return Exception { OperationError }; 65 66 auto cryptoDigestAlgorithm = WebCore::cryptoDigestAlgorithm(hash); 67 if (!cryptoDigestAlgorithm) 68 return Exception { OperationError }; 69 auto digest = CryptoDigest::create(*cryptoDigestAlgorithm); 70 if (!digest) 71 return Exception { OperationError }; 72 digest->addBytes(data, dataLength); 73 auto digestData = digest->computeHash(); 74 75 Vector<uint8_t> signature(keyLength / 8); // Per https://tools.ietf.org/html/rfc3447#section-8.2.1 76 size_t signatureSize = signature.size(); 77 78 CCCryptorStatus status = CCRSACryptorSign(key, ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize); 79 if (status) 80 return Exception { OperationError }; 81 82 return WTFMove(signature); 83 } 84 85 void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 86 { 87 context.ref(); 88 workQueue.dispatch([key = WTFMove(key), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 89 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 90 auto result = signRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data.data(), data.size()); 91 if (result.hasException()) { 92 // We should only dereference callbacks after being back to the Document/Worker threads. 93 context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) { 94 exceptionCallback(ec); 95 context.deref(); 96 }); 97 return; 98 } 99 // We should only dereference callbacks after being back to the Document/Worker threads. 100 context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) { 101 callback(result); 102 context.deref(); 103 }); 104 }); 105 } 106 57 107 ExceptionOr<void> CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParamsDeprecated& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback) 58 108 { 59 CCDigestAlgorithm digestAlgorithm; 60 if (!getCommonCryptoDigestAlgorithm(parameters.hash, digestAlgorithm)) 61 return Exception { NOT_SUPPORTED_ERR }; 62 63 auto cryptoDigestAlgorithm = WebCore::cryptoDigestAlgorithm(parameters.hash); 64 if (!cryptoDigestAlgorithm) 65 return Exception { NOT_SUPPORTED_ERR }; 66 67 auto digest = CryptoDigest::create(*cryptoDigestAlgorithm); 68 if (!digest) 69 return Exception { NOT_SUPPORTED_ERR }; 70 71 digest->addBytes(data.first, data.second); 72 73 auto digestData = digest->computeHash(); 74 75 Vector<uint8_t> signature(512); 76 size_t signatureSize = signature.size(); 77 78 CCCryptorStatus status = CCRSACryptorSign(key.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize); 79 if (status) { 109 auto result = signRSASSA_PKCS1_v1_5(parameters.hash, key.platformKey(), key.keySizeInBits(), data.first, data.second); 110 if (result.hasException()) { 80 111 failureCallback(); 81 112 return { }; 82 113 } 83 84 signature.resize(signatureSize); 85 callback(signature); 114 callback(result.releaseReturnValue()); 86 115 return { }; 87 116 }
Note: See TracChangeset
for help on using the changeset viewer.