Changeset 213624 in webkit
- Timestamp:
- Mar 8, 2017 8:04:29 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 12 added
- 1 deleted
- 16 edited
- 4 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r213623 r213624 1 2017-03-08 Jiewen Tan <jiewen_tan@apple.com> 2 3 [WebCrypto] Implement ECDH DeriveBits operation 4 https://bugs.webkit.org/show_bug.cgi?id=169319 5 <rdar://problem/23789585> 6 7 Reviewed by Brent Fulgham. 8 9 * TestExpectations: 10 Refine some comments. 11 * crypto/subtle/derive-bits-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/deriveBits-malformed-parameters-expected.txt. 12 * crypto/subtle/derive-bits-malformed-parameters.html: Added. 13 * crypto/subtle/deriveBits-malformed-parameters.html: Removed. 14 * crypto/subtle/ecdh-derive-bits-malformed-parametrs-expected.txt: Added. 15 * crypto/subtle/ecdh-derive-bits-malformed-parametrs.html: Added. 16 * crypto/subtle/ecdh-generate-key-derive-bits-expected.txt: Added. 17 * crypto/subtle/ecdh-generate-key-derive-bits.html: Added. 18 * crypto/subtle/ecdh-import-key-derive-bits-custom-length-expected.txt: Added. 19 * crypto/subtle/ecdh-import-key-derive-bits-custom-length.html: Added. 20 * crypto/subtle/ecdh-import-key-derive-bits-null-length-expected.txt: Added. 21 * crypto/subtle/ecdh-import-key-derive-bits-null-length.html: Added. 22 * crypto/workers/subtle/ecdh-import-key-derive-bits-expected.txt: Added. 23 * crypto/workers/subtle/ecdh-import-key-derive-bits.html: Added. 24 * crypto/workers/subtle/resources/ecdh-import-key-derive-bits.js: Added. 25 1 26 2017-03-08 John Wilander <wilander@apple.com> 2 27 -
trunk/LayoutTests/TestExpectations
r213604 r213624 960 960 workers/bomb-with-v8.html [ Skip ] 961 961 962 # WebCryptoAPI tests that take too long to complete , need to scale down. webkit.org/b/159638962 # WebCryptoAPI tests that take too long to complete 963 963 imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/hkdf.worker.html [ Skip ] 964 964 imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/pbkdf2.worker.html [ Skip ] -
trunk/LayoutTests/crypto/subtle/derive-bits-malformed-parameters-expected.txt
r213623 r213624 7 7 PASS crypto.subtle.deriveBits(1) rejected promise with TypeError: Not enough arguments. 8 8 PASS crypto.subtle.deriveBits(1, 2) rejected promise with TypeError: Not enough arguments. 9 PASS crypto.subtle.deriveBits("ECDH", 2, 3) rejected promise with NotSupportedError (DOM Exception 9): The operation is not supported.. 9 PASS crypto.subtle.deriveBits({ name:"ECDH", public:wrongKey }, wrongKey, 128) rejected promise with InvalidAccessError (DOM Exception 15): CryptoKey doesn't match AlgorithmIdentifier. 10 PASS crypto.subtle.deriveBits({ name:"ECDH", public:wrongKey }, wrongKey, 128) rejected promise with InvalidAccessError (DOM Exception 15): CryptoKey doesn't support bits derivation. 10 11 PASS successfullyParsed is true 11 12 -
trunk/Source/WebCore/CMakeLists.txt
r213598 r213624 345 345 crypto/parameters/AesKeyGenParams.idl 346 346 crypto/parameters/EcKeyParams.idl 347 crypto/parameters/EcdhKeyDeriveParams.idl 347 348 crypto/parameters/HmacKeyParams.idl 348 349 crypto/parameters/RsaHashedImportParams.idl -
trunk/Source/WebCore/ChangeLog
r213623 r213624 1 2017-03-08 Jiewen Tan <jiewen_tan@apple.com> 2 3 [WebCrypto] Implement ECDH DeriveBits operation 4 https://bugs.webkit.org/show_bug.cgi?id=169319 5 <rdar://problem/23789585> 6 7 Reviewed by Brent Fulgham. 8 9 This patch implements DeriveBits operation of ECDH according to the spec: 10 https://www.w3.org/TR/WebCryptoAPI/#ecdh-operations. 11 12 Tests: crypto/subtle/derive-bits-malformed-parameters.html 13 crypto/subtle/ecdh-derive-bits-malformed-parametrs.html 14 crypto/subtle/ecdh-generate-key-derive-bits.html 15 crypto/subtle/ecdh-import-key-derive-bits-custom-length.html 16 crypto/subtle/ecdh-import-key-derive-bits-null-length.html 17 crypto/workers/subtle/ecdh-import-key-derive-bits.html 18 19 * CMakeLists.txt: 20 * DerivedSources.make: 21 * PlatformGTK.cmake: 22 * PlatformMac.cmake: 23 * WebCore.xcodeproj/project.pbxproj: 24 * bindings/js/JSSubtleCryptoCustom.cpp: 25 (WebCore::normalizeCryptoAlgorithmParameters): 26 (WebCore::jsSubtleCryptoFunctionDeriveKeyPromise): 27 (WebCore::jsSubtleCryptoFunctionDeriveBitsPromise): 28 (WebCore::JSSubtleCrypto::generateKey): 29 Reorder a bit of the functions. 30 * crypto/CommonCryptoUtilities.h: 31 * crypto/CryptoAlgorithm.cpp: 32 (WebCore::CryptoAlgorithm::deriveBits): 33 * crypto/CryptoAlgorithm.h: 34 * crypto/CryptoAlgorithmParameters.h: 35 * crypto/algorithms/CryptoAlgorithmECDH.cpp: 36 (WebCore::CryptoAlgorithmECDH::deriveBits): 37 * crypto/algorithms/CryptoAlgorithmECDH.h: 38 * crypto/gnutls/CryptoAlgorithmECDHGnuTLS.cpp: Added. 39 (WebCore::CryptoAlgorithmECDH::platformDeriveBits): 40 * crypto/keys/CryptoKeyEC.h: 41 * crypto/mac/CryptoAlgorithmECDHMac.cpp: Added. 42 (WebCore::CryptoAlgorithmECDH::platformDeriveBits): 43 * crypto/parameters/CryptoAlgorithmEcdhKeyDeriveParams.h: Added. 44 * crypto/parameters/EcdhKeyDeriveParams.idl: Added. 45 1 46 2017-03-08 John Wilander <wilander@apple.com> 2 47 -
trunk/Source/WebCore/DerivedSources.make
r213598 r213624 277 277 $(WebCore)/crypto/parameters/AesKeyGenParams.idl \ 278 278 $(WebCore)/crypto/parameters/EcKeyParams.idl \ 279 $(WebCore)/crypto/parameters/EcdhKeyDeriveParams.idl \ 279 280 $(WebCore)/crypto/parameters/HmacKeyParams.idl \ 280 281 $(WebCore)/crypto/parameters/RsaHashedImportParams.idl \ -
trunk/Source/WebCore/PlatformGTK.cmake
r213489 r213624 404 404 crypto/gnutls/CryptoAlgorithmAES_GCMGnuTLS.cpp 405 405 crypto/gnutls/CryptoAlgorithmAES_KWGnuTLS.cpp 406 crypto/gnutls/CryptoAlgorithmECDHGnuTLS.cpp 406 407 crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp 407 408 crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp -
trunk/Source/WebCore/PlatformMac.cmake
r213541 r213624 207 207 crypto/mac/CryptoAlgorithmAES_GCMMac.cpp 208 208 crypto/mac/CryptoAlgorithmAES_KWMac.cpp 209 crypto/mac/CryptoAlgorithmECDHMac.cpp 209 210 crypto/mac/CryptoAlgorithmHMACMac.cpp 210 211 crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r213598 r213624 2379 2379 5750A9861E6A216800705C4A /* CryptoAlgorithmECDH.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5750A9841E6A216800705C4A /* CryptoAlgorithmECDH.cpp */; }; 2380 2380 5750A9871E6A216800705C4A /* CryptoAlgorithmECDH.h in Headers */ = {isa = PBXBuildFile; fileRef = 5750A9851E6A216800705C4A /* CryptoAlgorithmECDH.h */; }; 2381 5768142A1E6F99C100E77754 /* CryptoAlgorithmEcdhKeyDeriveParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 576814291E6F99C100E77754 /* CryptoAlgorithmEcdhKeyDeriveParams.h */; }; 2382 576814351E6FE3E800E77754 /* CryptoAlgorithmECDHMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 576814341E6FE3E800E77754 /* CryptoAlgorithmECDHMac.cpp */; }; 2383 576814401E709FA100E77754 /* JSEcdhKeyDeriveParams.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5768143D1E709C3600E77754 /* JSEcdhKeyDeriveParams.cpp */; }; 2384 576814411E709FA400E77754 /* JSEcdhKeyDeriveParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 5768143E1E709C3600E77754 /* JSEcdhKeyDeriveParams.h */; }; 2381 2385 5768E4341DB7524500D0A4F7 /* JSRsaHashedKeyGenParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 5768E4331DB7524500D0A4F7 /* JSRsaHashedKeyGenParams.h */; }; 2382 2386 5768E4361DB7527400D0A4F7 /* JSRsaHashedKeyGenParams.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5768E4351DB7527300D0A4F7 /* JSRsaHashedKeyGenParams.cpp */; }; … … 9808 9812 5750A9841E6A216800705C4A /* CryptoAlgorithmECDH.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmECDH.cpp; sourceTree = "<group>"; }; 9809 9813 5750A9851E6A216800705C4A /* CryptoAlgorithmECDH.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmECDH.h; sourceTree = "<group>"; }; 9814 576814281E6F98AD00E77754 /* EcdhKeyDeriveParams.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = EcdhKeyDeriveParams.idl; sourceTree = "<group>"; }; 9815 576814291E6F99C100E77754 /* CryptoAlgorithmEcdhKeyDeriveParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmEcdhKeyDeriveParams.h; sourceTree = "<group>"; }; 9816 576814341E6FE3E800E77754 /* CryptoAlgorithmECDHMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmECDHMac.cpp; sourceTree = "<group>"; }; 9817 5768143D1E709C3600E77754 /* JSEcdhKeyDeriveParams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSEcdhKeyDeriveParams.cpp; sourceTree = "<group>"; }; 9818 5768143E1E709C3600E77754 /* JSEcdhKeyDeriveParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSEcdhKeyDeriveParams.h; sourceTree = "<group>"; }; 9810 9819 5768E4331DB7524500D0A4F7 /* JSRsaHashedKeyGenParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRsaHashedKeyGenParams.h; sourceTree = "<group>"; }; 9811 9820 5768E4351DB7527300D0A4F7 /* JSRsaHashedKeyGenParams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRsaHashedKeyGenParams.cpp; sourceTree = "<group>"; }; … … 23599 23608 57B5F80D1E5D2F2D00F34F90 /* CryptoAlgorithmAES_GCMMac.cpp */, 23600 23609 E1FE137C184D270200892F13 /* CryptoAlgorithmAES_KWMac.cpp */, 23610 576814341E6FE3E800E77754 /* CryptoAlgorithmECDHMac.cpp */, 23601 23611 E125F8371822F1EB00D84CD9 /* CryptoAlgorithmHMACMac.cpp */, 23602 23612 E1BB84AC1822CA7400525043 /* CryptoAlgorithmRegistryMac.cpp */, … … 23680 23690 E19AC3F61824E5D100349426 /* CryptoAlgorithmAesKeyGenParamsDeprecated.h */, 23681 23691 5750A97D1E6A13EF00705C4A /* CryptoAlgorithmEcKeyParams.h */, 23692 576814291E6F99C100E77754 /* CryptoAlgorithmEcdhKeyDeriveParams.h */, 23682 23693 577483181DB4491F00716EF9 /* CryptoAlgorithmHmacKeyParams.h */, 23683 23694 E19DA29B18189ADD00088BC8 /* CryptoAlgorithmHmacKeyParamsDeprecated.h */, … … 23692 23703 E1BD331B182D8EE900C05D9F /* CryptoAlgorithmRsaSsaParamsDeprecated.h */, 23693 23704 5750A97C1E6A12B400705C4A /* EcKeyParams.idl */, 23705 576814281E6F98AD00E77754 /* EcdhKeyDeriveParams.idl */, 23694 23706 577483171DB1FE8900716EF9 /* HmacKeyParams.idl */, 23695 23707 57E2336C1DCD437000F28D01 /* RsaHashedImportParams.idl */, … … 23868 23880 5750A97F1E6A150800705C4A /* JSEcKeyParams.cpp */, 23869 23881 5750A9801E6A150800705C4A /* JSEcKeyParams.h */, 23882 5768143D1E709C3600E77754 /* JSEcdhKeyDeriveParams.cpp */, 23883 5768143E1E709C3600E77754 /* JSEcdhKeyDeriveParams.h */, 23870 23884 57E233681DCAB24300F28D01 /* JSHmacKeyParams.cpp */, 23871 23885 57E233661DCAB21C00F28D01 /* JSHmacKeyParams.h */, … … 26742 26756 7C6579F41E00856600E3A27A /* JSApplePayShippingMethod.h in Headers */, 26743 26757 1AE96A931D1A0DDD00B86768 /* JSApplePayShippingMethodSelectedEvent.h in Headers */, 26758 576814411E709FA400E77754 /* JSEcdhKeyDeriveParams.h in Headers */, 26744 26759 65DF31DB09D1C123000BE325 /* JSAttr.h in Headers */, 26745 26760 FDA15E9E12B03EE1003A583A /* JSAudioBuffer.h in Headers */, … … 28470 28485 BC5EB5E50E81BF6D00B25965 /* StyleSurroundData.h in Headers */, 28471 28486 BC5EB8100E81F2CE00B25965 /* StyleTransformData.h in Headers */, 28487 5768142A1E6F99C100E77754 /* CryptoAlgorithmEcdhKeyDeriveParams.h in Headers */, 28472 28488 E4DEAA1817A93DC3000E0430 /* StyleTreeResolver.h in Headers */, 28473 28489 E42E76DC1C7AF77600E3614D /* StyleUpdate.h in Headers */, … … 30407 30423 D66817FA166FE6D700FA07B4 /* HTMLTemplateElement.cpp in Sources */, 30408 30424 A81369D7097374F600D74463 /* HTMLTextAreaElement.cpp in Sources */, 30425 576814401E709FA100E77754 /* JSEcdhKeyDeriveParams.cpp in Sources */, 30409 30426 9BC6C21C13CCC97B008E0337 /* HTMLTextFormControlElement.cpp in Sources */, 30410 30427 830519951BB0F11000F3772E /* HTMLTimeElement.cpp in Sources */, … … 30608 30625 BC124EFF0C26447A009E2349 /* JSBarProp.cpp in Sources */, 30609 30626 BC946346107A934B00857193 /* JSBeforeLoadEvent.cpp in Sources */, 30627 576814351E6FE3E800E77754 /* CryptoAlgorithmECDHMac.cpp in Sources */, 30610 30628 70F546E8B8B5D7DC54EE144E /* JSBeforeUnloadEvent.cpp in Sources */, 30611 30629 FDF09DC81399B62200688E5B /* JSBiquadFilterNode.cpp in Sources */, -
trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
r213560 r213624 40 40 #include "JSDOMWrapper.h" 41 41 #include "JSEcKeyParams.h" 42 #include "JSEcdhKeyDeriveParams.h" 42 43 #include "JSHmacKeyParams.h" 43 44 #include "JSJsonWebKey.h" … … 161 162 break; 162 163 case Operations::DeriveKey: 163 case Operations::DeriveBits:164 164 throwNotSupportedError(state, scope); 165 165 return nullptr; 166 case Operations::DeriveBits: 167 switch (*identifier) { 168 case CryptoAlgorithmIdentifier::ECDH: { 169 // Remove this hack once https://bugs.webkit.org/show_bug.cgi?id=169333 is fixed. 170 JSValue nameValue = value.getObject()->get(&state, Identifier::fromString(&state, "name")); 171 JSValue publicValue = value.getObject()->get(&state, Identifier::fromString(&state, "public")); 172 JSObject* newValue = constructEmptyObject(&state); 173 newValue->putDirect(vm, Identifier::fromString(&vm, "name"), nameValue); 174 newValue->putDirect(vm, Identifier::fromString(&vm, "publicKey"), publicValue); 175 176 auto params = convertDictionary<CryptoAlgorithmEcdhKeyDeriveParams>(state, newValue); 177 RETURN_IF_EXCEPTION(scope, nullptr); 178 result = std::make_unique<CryptoAlgorithmEcdhKeyDeriveParams>(params); 179 break; 180 } 181 default: 182 throwNotSupportedError(state, scope); 183 return nullptr; 184 } 185 break; 166 186 case Operations::GenerateKey: 167 187 switch (*identifier) { … … 661 681 } 662 682 663 static void jsSubtleCryptoFunctionDeriveKeyPromise(ExecState& state, Ref<DeferredPromise>&& promise)664 {665 VM& vm = state.vm();666 auto scope = DECLARE_THROW_SCOPE(vm);667 668 if (UNLIKELY(state.argumentCount() < 5)) {669 promise->reject<IDLAny>(createNotEnoughArgumentsError(&state));670 return;671 }672 673 auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::DeriveKey);674 RETURN_IF_EXCEPTION(scope, void());675 676 // We should always return a NOT_SUPPORTED_ERR since we currently don't support any algorithms that has deriveKey operation.677 ASSERT_NOT_REACHED();678 }679 680 static void jsSubtleCryptoFunctionDeriveBitsPromise(ExecState& state, Ref<DeferredPromise>&& promise)681 {682 VM& vm = state.vm();683 auto scope = DECLARE_THROW_SCOPE(vm);684 685 if (UNLIKELY(state.argumentCount() < 3)) {686 promise->reject<IDLAny>(createNotEnoughArgumentsError(&state));687 return;688 }689 690 auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::DeriveBits);691 RETURN_IF_EXCEPTION(scope, void());692 693 // We should always return a NOT_SUPPORTED_ERR since we currently don't support any algorithms that has deriveBits operation.694 ASSERT_NOT_REACHED();695 }696 697 683 static void jsSubtleCryptoFunctionGenerateKeyPromise(ExecState& state, Ref<DeferredPromise>&& promise) 698 684 { … … 748 734 } 749 735 736 static void jsSubtleCryptoFunctionDeriveKeyPromise(ExecState& state, Ref<DeferredPromise>&& promise) 737 { 738 VM& vm = state.vm(); 739 auto scope = DECLARE_THROW_SCOPE(vm); 740 741 if (UNLIKELY(state.argumentCount() < 5)) { 742 promise->reject<IDLAny>(createNotEnoughArgumentsError(&state)); 743 return; 744 } 745 746 auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::DeriveKey); 747 RETURN_IF_EXCEPTION(scope, void()); 748 749 // We should always return a NOT_SUPPORTED_ERR since we currently don't support any algorithms that has deriveKey operation. 750 ASSERT_NOT_REACHED(); 751 } 752 753 static void jsSubtleCryptoFunctionDeriveBitsPromise(ExecState& state, Ref<DeferredPromise>&& promise) 754 { 755 VM& vm = state.vm(); 756 auto scope = DECLARE_THROW_SCOPE(vm); 757 758 if (UNLIKELY(state.argumentCount() < 3)) { 759 promise->reject<IDLAny>(createNotEnoughArgumentsError(&state)); 760 return; 761 } 762 763 auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::DeriveBits); 764 RETURN_IF_EXCEPTION(scope, void()); 765 766 auto baseKey = toCryptoKey(state, state.uncheckedArgument(1)); 767 RETURN_IF_EXCEPTION(scope, void()); 768 769 auto length = convert<IDLUnsignedLong>(state, state.uncheckedArgument(2), IntegerConversionConfiguration::Normal); 770 RETURN_IF_EXCEPTION(scope, void()); 771 772 if (params->identifier != baseKey->algorithmIdentifier()) { 773 promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't match AlgorithmIdentifier")); 774 return; 775 } 776 777 if (!baseKey->allows(CryptoKeyUsageDeriveBits)) { 778 promise->reject(INVALID_ACCESS_ERR, ASCIILiteral("CryptoKey doesn't support bits derivation")); 779 return; 780 } 781 782 auto algorithm = CryptoAlgorithmRegistry::singleton().create(params->identifier); 783 if (UNLIKELY(!algorithm)) { 784 throwNotSupportedError(state, scope); 785 return; 786 } 787 788 auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& derivedKey) mutable { 789 fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), derivedKey.data(), derivedKey.size()); 790 return; 791 }; 792 auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable { 793 rejectWithException(WTFMove(capturedPromise), ec); 794 }; 795 796 auto subtle = jsDynamicDowncast<JSSubtleCrypto*>(vm, state.thisValue()); 797 ASSERT(subtle); 798 algorithm->deriveBits(WTFMove(params), baseKey.releaseNonNull(), length, WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue()); 799 } 800 750 801 static void jsSubtleCryptoFunctionImportKeyPromise(ExecState& state, Ref<DeferredPromise>&& promise) 751 802 { … … 1099 1150 } 1100 1151 1152 1153 JSValue JSSubtleCrypto::generateKey(ExecState& state) 1154 { 1155 return callPromiseFunction<jsSubtleCryptoFunctionGenerateKeyPromise, PromiseExecutionScope::WindowOrWorker>(state); 1156 } 1157 1101 1158 JSValue JSSubtleCrypto::deriveKey(ExecState& state) 1102 1159 { … … 1109 1166 } 1110 1167 1111 JSValue JSSubtleCrypto::generateKey(ExecState& state)1112 {1113 return callPromiseFunction<jsSubtleCryptoFunctionGenerateKeyPromise, PromiseExecutionScope::WindowOrWorker>(state);1114 }1115 1116 1168 JSValue JSSubtleCrypto::importKey(ExecState& state) 1117 1169 { -
trunk/Source/WebCore/crypto/CommonCryptoUtilities.h
r213560 r213624 108 108 extern "C" CCCryptorStatus CCECCryptorCreateFromData(size_t keySize, uint8_t *qX, size_t qXLength, uint8_t *qY, size_t qYLength, CCECCryptorRef *ref); 109 109 extern "C" CCCryptorStatus CCECCryptorGetKeyComponents(CCECCryptorRef ecKey, size_t *keySize, uint8_t *qX, size_t *qXLength, uint8_t *qY, size_t *qYLength, uint8_t *d, size_t *dLength); 110 110 extern "C" CCCryptorStatus CCECCryptorComputeSharedSecret(CCECCryptorRef privateKey, CCECCryptorRef publicKey, void *out, size_t *outLen); 111 111 112 112 #if !USE(APPLE_INTERNAL_SDK) -
trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp
r209200 r213624 59 59 60 60 void CryptoAlgorithm::generateKey(const CryptoAlgorithmParameters&, bool, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&) 61 { 62 exceptionCallback(NOT_SUPPORTED_ERR); 63 } 64 65 void CryptoAlgorithm::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, unsigned long, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&) 61 66 { 62 67 exceptionCallback(NOT_SUPPORTED_ERR); -
trunk/Source/WebCore/crypto/CryptoAlgorithm.h
r213560 r213624 73 73 virtual void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 74 74 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&); 75 virtual void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, unsigned long length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&); 75 76 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=169262 76 77 virtual void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&); -
trunk/Source/WebCore/crypto/CryptoAlgorithmParameters.h
r213489 r213624 42 42 AesKeyGenParams, 43 43 EcKeyParams, 44 EcdhKeyDeriveParams, 44 45 HmacKeyParams, 45 46 RsaHashedKeyGenParams, -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp
r213560 r213624 30 30 31 31 #include "CryptoAlgorithmEcKeyParams.h" 32 #include "CryptoAlgorithmEcdhKeyDeriveParams.h" 32 33 #include "CryptoKeyEC.h" 33 34 #include "ExceptionCode.h" … … 64 65 pair.privateKey->setUsagesBitmap(pair.privateKey->usagesBitmap() & (CryptoKeyUsageDeriveKey | CryptoKeyUsageDeriveBits)); 65 66 callback(WTFMove(pair)); 67 } 68 69 void CryptoAlgorithmECDH::deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& baseKey, unsigned long length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 70 { 71 // We only accept length that is a multiple of 8. 72 if (length % 8) { 73 exceptionCallback(OperationError); 74 return; 75 } 76 77 ASSERT(parameters); 78 auto& ecParameters = downcast<CryptoAlgorithmEcdhKeyDeriveParams>(*parameters); 79 80 if (baseKey->type() != CryptoKey::Type::Private) { 81 exceptionCallback(INVALID_ACCESS_ERR); 82 return; 83 } 84 ASSERT(ecParameters.publicKey); 85 if (ecParameters.publicKey->type() != CryptoKey::Type::Public) { 86 exceptionCallback(INVALID_ACCESS_ERR); 87 return; 88 } 89 if (baseKey->algorithmIdentifier() != ecParameters.publicKey->algorithmIdentifier()) { 90 exceptionCallback(INVALID_ACCESS_ERR); 91 return; 92 } 93 auto& ecBaseKey = downcast<CryptoKeyEC>(baseKey.get()); 94 auto& ecPublicKey = downcast<CryptoKeyEC>(*(ecParameters.publicKey.get())); 95 if (ecBaseKey.namedCurve() != ecPublicKey.namedCurve()) { 96 exceptionCallback(INVALID_ACCESS_ERR); 97 return; 98 } 99 100 auto unifiedCallback = [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](std::optional<Vector<uint8_t>>&& derivedKey, unsigned long length) mutable { 101 if (!derivedKey) { 102 exceptionCallback(OperationError); 103 return; 104 } 105 if (!length) { 106 callback(WTFMove(*derivedKey)); 107 return; 108 } 109 if (length / 8 > (*derivedKey).size()) { 110 exceptionCallback(OperationError); 111 return; 112 } 113 (*derivedKey).shrink(length / 8); 114 callback(WTFMove(*derivedKey)); 115 }; 116 platformDeriveBits(WTFMove(baseKey), ecParameters.publicKey.releaseNonNull(), length, WTFMove(unifiedCallback), context, workQueue); 66 117 } 67 118 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.h
r213560 r213624 43 43 44 44 void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 45 void deriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, unsigned long length, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final; 45 46 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; 46 47 void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final; 48 49 using Callback = Function<void(std::optional<Vector<uint8_t>>&&, unsigned long)>; 50 void platformDeriveBits(Ref<CryptoKey>&& baseKey, Ref<CryptoKey>&& publicKey, unsigned long length, Callback&&, ScriptExecutionContext&, WorkQueue&); 47 51 }; 48 52 -
trunk/Source/WebCore/crypto/gnutls/CryptoAlgorithmECDHGnuTLS.cpp
r213623 r213624 24 24 */ 25 25 26 #pragma once 27 28 #include "CryptoAlgorithm.h" 26 #include "config.h" 27 #include "CryptoAlgorithmECDH.h" 29 28 30 29 #if ENABLE(SUBTLE_CRYPTO) 31 30 31 #include "NotImplemented.h" 32 32 33 namespace WebCore { 33 34 34 class CryptoAlgorithmECDH final : public CryptoAlgorithm { 35 public: 36 static constexpr const char* s_name = "ECDH"; 37 static constexpr CryptoAlgorithmIdentifier s_identifier = CryptoAlgorithmIdentifier::ECDH; 38 static Ref<CryptoAlgorithm> create(); 39 40 private: 41 CryptoAlgorithmECDH() = default; 42 CryptoAlgorithmIdentifier identifier() const final; 43 44 void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 45 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; 46 void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final; 47 }; 35 void CryptoAlgorithmECDH::platformDeriveBits(Ref<CryptoKey>&&, Ref<CryptoKey>&&, unsigned long, Callback&&, ScriptExecutionContext&, WorkQueue&) 36 { 37 notImplemented(); 38 } 48 39 49 40 } // namespace WebCore -
trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h
r213560 r213624 85 85 86 86 size_t keySizeInBits() const; 87 NamedCurve namedCurve() const { return m_curve; } 88 PlatformECKey platformKey() { return m_platformKey; } 87 89 88 90 private: -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmECDHMac.cpp
r213623 r213624 24 24 */ 25 25 26 #pragma once 27 28 #include "CryptoAlgorithm.h" 26 #include "config.h" 27 #include "CryptoAlgorithmECDH.h" 29 28 30 29 #if ENABLE(SUBTLE_CRYPTO) 31 30 31 #include "CommonCryptoUtilities.h" 32 #include "CryptoKeyEC.h" 33 #include "ScriptExecutionContext.h" 34 32 35 namespace WebCore { 33 36 34 class CryptoAlgorithmECDH final : public CryptoAlgorithm { 35 public: 36 static constexpr const char* s_name = "ECDH"; 37 static constexpr CryptoAlgorithmIdentifier s_identifier = CryptoAlgorithmIdentifier::ECDH; 38 static Ref<CryptoAlgorithm> create(); 37 void CryptoAlgorithmECDH::platformDeriveBits(Ref<CryptoKey>&& baseKey, Ref<CryptoKey>&& publicKey, unsigned long length, Callback&& callback, ScriptExecutionContext& context, WorkQueue& workQueue) 38 { 39 context.ref(); 40 workQueue.dispatch([baseKey = WTFMove(baseKey), publicKey = WTFMove(publicKey), length, callback = WTFMove(callback), &context]() mutable { 41 auto& ecBaseKey = downcast<CryptoKeyEC>(baseKey.get()); 42 auto& ecPublicKey = downcast<CryptoKeyEC>(publicKey.get()); 39 43 40 private: 41 CryptoAlgorithmECDH() = default; 42 CryptoAlgorithmIdentifier identifier() const final; 44 std::optional<Vector<uint8_t>> result = std::nullopt; 45 Vector<uint8_t> derivedKey(ecBaseKey.keySizeInBits() / 8); // Per https://tools.ietf.org/html/rfc6090#section-4. 46 size_t size = derivedKey.size(); 47 if (!CCECCryptorComputeSharedSecret(ecBaseKey.platformKey(), ecPublicKey.platformKey(), derivedKey.data(), &size)) 48 result = WTFMove(derivedKey); 43 49 44 void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 45 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; 46 void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final; 47 }; 50 context.postTask([result = WTFMove(result), length, callback = WTFMove(callback)](ScriptExecutionContext& context) mutable { 51 callback(WTFMove(result), length); 52 context.deref(); 53 }); 54 }); 55 } 48 56 49 } // namespace WebCore57 } 50 58 51 59 #endif // ENABLE(SUBTLE_CRYPTO) -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmEcdhKeyDeriveParams.h
r213623 r213624 26 26 #pragma once 27 27 28 #include "CryptoAlgorithm.h" 28 #include "CryptoAlgorithmParameters.h" 29 #include <wtf/RefCounted.h> 29 30 30 31 #if ENABLE(SUBTLE_CRYPTO) … … 32 33 namespace WebCore { 33 34 34 class CryptoAlgorithmECDH final : public CryptoAlgorithm { 35 class CryptoKey; 36 37 class CryptoAlgorithmEcdhKeyDeriveParams final : public CryptoAlgorithmParameters { 35 38 public: 36 static constexpr const char* s_name = "ECDH"; 37 static constexpr CryptoAlgorithmIdentifier s_identifier = CryptoAlgorithmIdentifier::ECDH; 38 static Ref<CryptoAlgorithm> create(); 39 RefPtr<CryptoKey> publicKey; 39 40 40 private: 41 CryptoAlgorithmECDH() = default; 42 CryptoAlgorithmIdentifier identifier() const final; 43 44 void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 45 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; 46 void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final; 41 Class parametersClass() const final { return Class::EcdhKeyDeriveParams; } 47 42 }; 48 43 49 44 } // namespace WebCore 50 45 46 SPECIALIZE_TYPE_TRAITS_CRYPTO_ALGORITHM_PARAMETERS(EcdhKeyDeriveParams) 47 51 48 #endif // ENABLE(SUBTLE_CRYPTO) -
trunk/Source/WebCore/crypto/parameters/EcdhKeyDeriveParams.idl
r213623 r213624 24 24 */ 25 25 26 #pragma once 27 28 #include "CryptoAlgorithm.h" 29 30 #if ENABLE(SUBTLE_CRYPTO) 31 32 namespace WebCore { 33 34 class CryptoAlgorithmECDH final : public CryptoAlgorithm { 35 public: 36 static constexpr const char* s_name = "ECDH"; 37 static constexpr CryptoAlgorithmIdentifier s_identifier = CryptoAlgorithmIdentifier::ECDH; 38 static Ref<CryptoAlgorithm> create(); 39 40 private: 41 CryptoAlgorithmECDH() = default; 42 CryptoAlgorithmIdentifier identifier() const final; 43 44 void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&) final; 45 void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final; 46 void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final; 26 [ 27 Conditional=SUBTLE_CRYPTO, 28 ImplementedAs=CryptoAlgorithmEcdhKeyDeriveParams, 29 ] dictionary EcdhKeyDeriveParams : CryptoAlgorithmParameters { 30 // We should rename this to public once https://bugs.webkit.org/show_bug.cgi?id=169333 is fixed. 31 // The peer's EC public key. 32 required CryptoKey publicKey; 47 33 }; 48 49 } // namespace WebCore50 51 #endif // ENABLE(SUBTLE_CRYPTO)
Note: See TracChangeset
for help on using the changeset viewer.