Changeset 160455 in webkit
- Timestamp:
- Dec 11, 2013, 2:13:55 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 9 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r160451 r160455 1 2013-12-11 Alexey Proskuryakov <ap@apple.com> 2 3 WebCrypto keys should support structured clone 4 https://bugs.webkit.org/show_bug.cgi?id=125590 5 6 Reviewed by Oliver Hunt. 7 8 * crypto/subtle/aes-postMessage-expected.txt: Added. 9 * crypto/subtle/aes-postMessage.html: Added. 10 * crypto/subtle/hmac-postMessage-expected.txt: Added. 11 * crypto/subtle/hmac-postMessage.html: Added. 12 * crypto/subtle/postMessage-worker-expected.txt: Added. 13 * crypto/subtle/postMessage-worker.html: Added. 14 * crypto/subtle/rsa-postMessage-expected.txt: Added. 15 * crypto/subtle/rsa-postMessage.html: Added. 16 * crypto/subtle/resources/postMessage-worker.js: Added. 17 1 18 2013-12-11 Bear Travis <betravis@adobe.com> 2 19 -
trunk/Source/WebCore/CMakeLists.txt
r160336 r160455 25 25 "${WEBCORE_DIR}/bridge/c" 26 26 "${WEBCORE_DIR}/crypto" 27 "${WEBCORE_DIR}/crypto/keys" 27 28 "${WEBCORE_DIR}/css" 28 29 "${WEBCORE_DIR}/dom" -
trunk/Source/WebCore/ChangeLog
r160451 r160455 1 2013-12-11 Alexey Proskuryakov <ap@apple.com> 2 3 WebCrypto keys should support structured clone 4 https://bugs.webkit.org/show_bug.cgi?id=125590 5 6 Reviewed by Oliver Hunt. 7 8 Tests: crypto/subtle/aes-postMessage.html 9 crypto/subtle/hmac-postMessage.html 10 crypto/subtle/postMessage-worker.html 11 crypto/subtle/rsa-postMessage.html 12 13 * crypto/CryptoAlgorithmIdentifier.h: 14 (WebCore::CryptoAlgorithmIdentifier): 15 * bindings/js/JSCryptoAlgorithmDictionary.cpp: 16 (WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt): 17 (WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt): 18 (WebCore::JSCryptoAlgorithmDictionary::createParametersForSign): 19 (WebCore::JSCryptoAlgorithmDictionary::createParametersForVerify): 20 (WebCore::JSCryptoAlgorithmDictionary::createParametersForDigest): 21 (WebCore::JSCryptoAlgorithmDictionary::createParametersForGenerateKey): 22 (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveKey): 23 (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveBits): 24 (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): 25 (WebCore::JSCryptoAlgorithmDictionary::createParametersForExportKey): 26 AES_KW was added to WebCrypto spec editor's draft yesterday night. Now that we're 27 adding a matching enum for structired clone serialization, it's as good a time as 28 any to update the order of values to match. 29 30 * bindings/js/SerializedScriptValue.cpp: 31 (WebCore::countUsages): 32 (WebCore::CloneSerializer::dumpIfTerminal): 33 (WebCore::CloneSerializer::write): 34 (WebCore::CloneDeserializer::read): 35 (WebCore::CloneDeserializer::readHMACKey): 36 (WebCore::CloneDeserializer::readAESKey): 37 (WebCore::CloneDeserializer::readRSAKey): 38 (WebCore::CloneDeserializer::readCryptoKey): 39 (WebCore::CloneDeserializer::readTerminal): 40 Added serialization/deserialization for CryptoKey. This doesn't update version 41 number, because we don't currently store structured clones in persistent storage - 42 and even if we did, we wouldn't want to invalidate everything users already stored. 43 44 * crypto/CryptoAlgorithmRegistry.cpp: 45 (WebCore::CryptoAlgorithmRegistry::shared): 46 (WebCore::registryMutex): 47 (WebCore::CryptoAlgorithmRegistry::getIdentifierForName): 48 (WebCore::CryptoAlgorithmRegistry::nameForIdentifier): 49 (WebCore::CryptoAlgorithmRegistry::create): 50 (WebCore::CryptoAlgorithmRegistry::registerAlgorithm): 51 * crypto/CryptoKey.idl: 52 With structured clone, it is now possible to send a Key to a web worker. That's 53 of no practical use because the crypto API is not exposed in workers, but we 54 shouldn't crash anyway. 55 56 * crypto/keys/CryptoKeyAES.cpp: 57 (WebCore::CryptoKeyAES::CryptoKeyAES): 58 (WebCore::CryptoKeyAES::isValidAESAlgorithm): 59 * crypto/keys/CryptoKeyAES.h: 60 Exposed isValidAESAlgorithm, so that a caller could know whether the constructor 61 will assert. 62 63 * CMakeLists.txt: 64 * GNUmakefile.am: 65 * WebCore.vcxproj/WebCore.vcxproj.filters: 66 * WebCore.vcxproj/WebCoreCommon.props: 67 Added crypto/keys to search paths to avoid build breakage. 68 1 69 2013-12-11 Bear Travis <betravis@adobe.com> 2 70 -
trunk/Source/WebCore/GNUmakefile.am
r159827 r160455 34 34 -I$(srcdir)/Source/WebCore/bridge/jsc \ 35 35 -I$(srcdir)/Source/WebCore/crypto \ 36 -I$(srcdir)/Source/WebCore/crypto/keys \ 36 37 -I$(srcdir)/Source/WebCore/css \ 37 38 -I$(srcdir)/Source/WebCore/dom \ -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
r160338 r160455 176 176 <UniqueIdentifier>{02334427-19d6-44c8-a5d1-e1a67a9c4997}</UniqueIdentifier> 177 177 </Filter> 178 <Filter Include="crypto\keys"> 179 <UniqueIdentifier>{edd0faa6-bb8c-4c0e-b28a-064bde7e1eba}</UniqueIdentifier> 180 </Filter> 178 181 <Filter Include="css"> 179 182 <UniqueIdentifier>{353b76ca-c49a-41da-88da-33dc422325ef}</UniqueIdentifier> -
trunk/Source/WebCore/WebCore.vcxproj/WebCoreCommon.props
r159827 r160455 8 8 <ItemDefinitionGroup> 9 9 <ClCompile> 10 <AdditionalIncludeDirectories>$(ProjectDir)..;$(ProjectDir)..\Modules\mediacontrols;$(ProjectDir)..\Modules\mediastream;$(ProjectDir)..\Modules\filesystem;$(ProjectDir)..\Modules\geolocation;$(ProjectDir)..\Modules\indexeddb;$(ProjectDir)..\Modules\mediasource;$(ProjectDir)..\Modules\navigatorcontentutils;$(ProjectDir)..\Modules\plugins;$(ProjectDir)..\Modules\speech;$(ProjectDir)..\Modules\proximity;$(ProjectDir)..\Modules\quota;$(ProjectDir)..\Modules\notifications;$(ProjectDir)..\Modules\webdatabase;$(ProjectDir)..\Modules\websockets;$(ProjectDir)..\accessibility;$(ProjectDir)..\accessibility\win;$(ProjectDir)..\bridge;$(ProjectDir)..\bridge\c;$(ProjectDir)..\bridge\jsc;$(ProjectDir)..\css;$(ProjectDir)..\editing;$(ProjectDir)..\fileapi;$(ProjectDir)..\rendering;$(ProjectDir)..\rendering\line;$(ProjectDir)..\rendering\mathml;$(ProjectDir)..\rendering\shapes;$(ProjectDir)..\rendering\style;$(ProjectDir)..\rendering\svg;$(ProjectDir)..\bindings;$(ProjectDir)..\bindings\generic;$(ProjectDir)..\bindings\js;$(ProjectDir)..\bindings\js\specialization;$(ProjectDir)..\dom;$(ProjectDir)..\dom\default;$(ProjectDir)..\history;$(ProjectDir)..\html;$(ProjectDir)..\html\canvas;$(ProjectDir)..\html\forms;$(ProjectDir)..\html\parser;$(ProjectDir)..\html\shadow;$(ProjectDir)..\html\track;$(ProjectDir)..\inspector;$(ProjectDir)..\loader;$(ProjectDir)..\loader\appcache;$(ProjectDir)..\loader\archive;$(ProjectDir)..\loader\archive\cf;$(ProjectDir)..\loader\cache;$(ProjectDir)..\loader\icon;$(ProjectDir)..\mathml;$(ProjectDir)..\page;$(ProjectDir)..\page\animation;$(ProjectDir)..\page\scrolling;$(ProjectDir)..\page\win;$(ProjectDir)..\platform;$(ProjectDir)..\platform\animation;$(ProjectDir)..\platform\mock;$(ProjectDir)..\platform\sql;$(ProjectDir)..\platform\win;$(ProjectDir)..\platform\network;$(ProjectDir)..\platform\network\win;$(ProjectDir)..\platform\cf;$(ProjectDir)..\platform\graphics;$(ProjectDir)..\platform\graphics\ca;$(ProjectDir)..\platform\graphics\cpu\arm\filters;$(ProjectDir)..\platform\graphics\filters;$(ProjectDir)..\platform\graphics\filters\arm;$(ProjectDir)..\platform\graphics\opentype;$(ProjectDir)..\platform\graphics\transforms;$(ProjectDir)..\platform\text;$(ProjectDir)..\platform\text\transcoder;$(ProjectDir)..\platform\graphics\win;$(ProjectDir)..\xml;$(ProjectDir)..\xml\parser;$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources;$(ProjectDir)..\plugins;$(ProjectDir)..\plugins\win;$(ProjectDir)..\svg\animation;$(ProjectDir)..\svg\graphics;$(ProjectDir)..\svg\properties;$(ProjectDir)..\svg\graphics\filters;$(ProjectDir)..\svg;$(ProjectDir)..\testing;$(ProjectDir)..\crypto;$(ProjectDir)..\ wml;$(ProjectDir)..\storage;$(ProjectDir)..\style;$(ProjectDir)..\websockets;$(ProjectDir)..\workers;$(ConfigurationBuildDir)\include;$(ConfigurationBuildDir)\include\private;$(ConfigurationBuildDir)\include\JavaScriptCore;$(ConfigurationBuildDir)\include\private\JavaScriptCore;$(ProjectDir)..\ForwardingHeaders;$(ProjectDir)..\platform\graphics\gpu;$(ProjectDir)..\platform\graphics\egl;$(ProjectDir)..\platform\graphics\surfaces;$(ProjectDir)..\platform\graphics\surfaces\egl;$(ProjectDir)..\platform\graphics\opengl;$(WebKit_Libraries)\include;$(WebKit_Libraries)\include\private;$(WebKit_Libraries)\include\private\JavaScriptCore;$(WebKit_Libraries)\include\sqlite;$(WebKit_Libraries)\include\JavaScriptCore;$(WebKit_Libraries)\include\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>10 <AdditionalIncludeDirectories>$(ProjectDir)..;$(ProjectDir)..\Modules\mediacontrols;$(ProjectDir)..\Modules\mediastream;$(ProjectDir)..\Modules\filesystem;$(ProjectDir)..\Modules\geolocation;$(ProjectDir)..\Modules\indexeddb;$(ProjectDir)..\Modules\mediasource;$(ProjectDir)..\Modules\navigatorcontentutils;$(ProjectDir)..\Modules\plugins;$(ProjectDir)..\Modules\speech;$(ProjectDir)..\Modules\proximity;$(ProjectDir)..\Modules\quota;$(ProjectDir)..\Modules\notifications;$(ProjectDir)..\Modules\webdatabase;$(ProjectDir)..\Modules\websockets;$(ProjectDir)..\accessibility;$(ProjectDir)..\accessibility\win;$(ProjectDir)..\bridge;$(ProjectDir)..\bridge\c;$(ProjectDir)..\bridge\jsc;$(ProjectDir)..\css;$(ProjectDir)..\editing;$(ProjectDir)..\fileapi;$(ProjectDir)..\rendering;$(ProjectDir)..\rendering\line;$(ProjectDir)..\rendering\mathml;$(ProjectDir)..\rendering\shapes;$(ProjectDir)..\rendering\style;$(ProjectDir)..\rendering\svg;$(ProjectDir)..\bindings;$(ProjectDir)..\bindings\generic;$(ProjectDir)..\bindings\js;$(ProjectDir)..\bindings\js\specialization;$(ProjectDir)..\dom;$(ProjectDir)..\dom\default;$(ProjectDir)..\history;$(ProjectDir)..\html;$(ProjectDir)..\html\canvas;$(ProjectDir)..\html\forms;$(ProjectDir)..\html\parser;$(ProjectDir)..\html\shadow;$(ProjectDir)..\html\track;$(ProjectDir)..\inspector;$(ProjectDir)..\loader;$(ProjectDir)..\loader\appcache;$(ProjectDir)..\loader\archive;$(ProjectDir)..\loader\archive\cf;$(ProjectDir)..\loader\cache;$(ProjectDir)..\loader\icon;$(ProjectDir)..\mathml;$(ProjectDir)..\page;$(ProjectDir)..\page\animation;$(ProjectDir)..\page\scrolling;$(ProjectDir)..\page\win;$(ProjectDir)..\platform;$(ProjectDir)..\platform\animation;$(ProjectDir)..\platform\mock;$(ProjectDir)..\platform\sql;$(ProjectDir)..\platform\win;$(ProjectDir)..\platform\network;$(ProjectDir)..\platform\network\win;$(ProjectDir)..\platform\cf;$(ProjectDir)..\platform\graphics;$(ProjectDir)..\platform\graphics\ca;$(ProjectDir)..\platform\graphics\cpu\arm\filters;$(ProjectDir)..\platform\graphics\filters;$(ProjectDir)..\platform\graphics\filters\arm;$(ProjectDir)..\platform\graphics\opentype;$(ProjectDir)..\platform\graphics\transforms;$(ProjectDir)..\platform\text;$(ProjectDir)..\platform\text\transcoder;$(ProjectDir)..\platform\graphics\win;$(ProjectDir)..\xml;$(ProjectDir)..\xml\parser;$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources;$(ProjectDir)..\plugins;$(ProjectDir)..\plugins\win;$(ProjectDir)..\svg\animation;$(ProjectDir)..\svg\graphics;$(ProjectDir)..\svg\properties;$(ProjectDir)..\svg\graphics\filters;$(ProjectDir)..\svg;$(ProjectDir)..\testing;$(ProjectDir)..\crypto;$(ProjectDir)..\crypto\keys;$(ProjectDir)..\wml;$(ProjectDir)..\storage;$(ProjectDir)..\style;$(ProjectDir)..\websockets;$(ProjectDir)..\workers;$(ConfigurationBuildDir)\include;$(ConfigurationBuildDir)\include\private;$(ConfigurationBuildDir)\include\JavaScriptCore;$(ConfigurationBuildDir)\include\private\JavaScriptCore;$(ProjectDir)..\ForwardingHeaders;$(ProjectDir)..\platform\graphics\gpu;$(ProjectDir)..\platform\graphics\egl;$(ProjectDir)..\platform\graphics\surfaces;$(ProjectDir)..\platform\graphics\surfaces\egl;$(ProjectDir)..\platform\graphics\opengl;$(WebKit_Libraries)\include;$(WebKit_Libraries)\include\private;$(WebKit_Libraries)\include\private\JavaScriptCore;$(WebKit_Libraries)\include\sqlite;$(WebKit_Libraries)\include\JavaScriptCore;$(WebKit_Libraries)\include\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 11 11 <PreprocessorDefinitions>DISABLE_3D_RENDERING;WEBCORE_CONTEXT_MENUS;%(PreprocessorDefinitions)</PreprocessorDefinitions> 12 12 <PrecompiledHeader>Use</PrecompiledHeader> -
trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp
r159966 r160455 318 318 case CryptoAlgorithmIdentifier::AES_GCM: 319 319 case CryptoAlgorithmIdentifier::AES_CFB: 320 case CryptoAlgorithmIdentifier::HMAC: 321 case CryptoAlgorithmIdentifier::DH: 322 case CryptoAlgorithmIdentifier::SHA_1: 323 case CryptoAlgorithmIdentifier::SHA_224: 324 case CryptoAlgorithmIdentifier::SHA_256: 325 case CryptoAlgorithmIdentifier::SHA_384: 326 case CryptoAlgorithmIdentifier::SHA_512: 327 case CryptoAlgorithmIdentifier::CONCAT: 328 case CryptoAlgorithmIdentifier::HKDF_CTR: 329 case CryptoAlgorithmIdentifier::PBKDF2: 330 setDOMException(exec, NOT_SUPPORTED_ERR); 331 return nullptr; 332 case CryptoAlgorithmIdentifier::AES_KW: 333 return std::make_unique<CryptoAlgorithmParameters>(); 320 setDOMException(exec, NOT_SUPPORTED_ERR); 321 return nullptr; 322 case CryptoAlgorithmIdentifier::AES_KW: 323 return std::make_unique<CryptoAlgorithmParameters>(); 324 case CryptoAlgorithmIdentifier::HMAC: 325 case CryptoAlgorithmIdentifier::DH: 326 case CryptoAlgorithmIdentifier::SHA_1: 327 case CryptoAlgorithmIdentifier::SHA_224: 328 case CryptoAlgorithmIdentifier::SHA_256: 329 case CryptoAlgorithmIdentifier::SHA_384: 330 case CryptoAlgorithmIdentifier::SHA_512: 331 case CryptoAlgorithmIdentifier::CONCAT: 332 case CryptoAlgorithmIdentifier::HKDF_CTR: 333 case CryptoAlgorithmIdentifier::PBKDF2: 334 setDOMException(exec, NOT_SUPPORTED_ERR); 335 return nullptr; 334 336 } 335 337 } … … 355 357 case CryptoAlgorithmIdentifier::AES_GCM: 356 358 case CryptoAlgorithmIdentifier::AES_CFB: 357 case CryptoAlgorithmIdentifier::HMAC: 358 case CryptoAlgorithmIdentifier::DH: 359 case CryptoAlgorithmIdentifier::SHA_1: 360 case CryptoAlgorithmIdentifier::SHA_224: 361 case CryptoAlgorithmIdentifier::SHA_256: 362 case CryptoAlgorithmIdentifier::SHA_384: 363 case CryptoAlgorithmIdentifier::SHA_512: 364 case CryptoAlgorithmIdentifier::CONCAT: 365 case CryptoAlgorithmIdentifier::HKDF_CTR: 366 case CryptoAlgorithmIdentifier::PBKDF2: 367 setDOMException(exec, NOT_SUPPORTED_ERR); 368 return nullptr; 369 case CryptoAlgorithmIdentifier::AES_KW: 370 return std::make_unique<CryptoAlgorithmParameters>(); 359 setDOMException(exec, NOT_SUPPORTED_ERR); 360 return nullptr; 361 case CryptoAlgorithmIdentifier::AES_KW: 362 return std::make_unique<CryptoAlgorithmParameters>(); 363 case CryptoAlgorithmIdentifier::HMAC: 364 case CryptoAlgorithmIdentifier::DH: 365 case CryptoAlgorithmIdentifier::SHA_1: 366 case CryptoAlgorithmIdentifier::SHA_224: 367 case CryptoAlgorithmIdentifier::SHA_256: 368 case CryptoAlgorithmIdentifier::SHA_384: 369 case CryptoAlgorithmIdentifier::SHA_512: 370 case CryptoAlgorithmIdentifier::CONCAT: 371 case CryptoAlgorithmIdentifier::HKDF_CTR: 372 case CryptoAlgorithmIdentifier::PBKDF2: 373 setDOMException(exec, NOT_SUPPORTED_ERR); 374 return nullptr; 371 375 } 372 376 } … … 389 393 case CryptoAlgorithmIdentifier::AES_GCM: 390 394 case CryptoAlgorithmIdentifier::AES_CFB: 395 case CryptoAlgorithmIdentifier::AES_KW: 391 396 setDOMException(exec, NOT_SUPPORTED_ERR); 392 397 return nullptr; … … 402 407 case CryptoAlgorithmIdentifier::HKDF_CTR: 403 408 case CryptoAlgorithmIdentifier::PBKDF2: 404 case CryptoAlgorithmIdentifier::AES_KW:405 409 setDOMException(exec, NOT_SUPPORTED_ERR); 406 410 return nullptr; … … 425 429 case CryptoAlgorithmIdentifier::AES_GCM: 426 430 case CryptoAlgorithmIdentifier::AES_CFB: 431 case CryptoAlgorithmIdentifier::AES_KW: 427 432 setDOMException(exec, NOT_SUPPORTED_ERR); 428 433 return nullptr; … … 438 443 case CryptoAlgorithmIdentifier::HKDF_CTR: 439 444 case CryptoAlgorithmIdentifier::PBKDF2: 440 case CryptoAlgorithmIdentifier::AES_KW:441 445 setDOMException(exec, NOT_SUPPORTED_ERR); 442 446 return nullptr; … … 458 462 case CryptoAlgorithmIdentifier::AES_GCM: 459 463 case CryptoAlgorithmIdentifier::AES_CFB: 460 case CryptoAlgorithmIdentifier:: HMAC:461 case CryptoAlgorithmIdentifier:: DH:462 setDOMException(exec, NOT_SUPPORTED_ERR);463 return nullptr;464 case CryptoAlgorithmIdentifier::SHA_1:465 case CryptoAlgorithmIdentifier::SHA_ 224:466 case CryptoAlgorithmIdentifier::SHA_2 56:467 case CryptoAlgorithmIdentifier::SHA_ 384:468 case CryptoAlgorithmIdentifier::SHA_ 512:469 return std::make_unique<CryptoAlgorithmParameters>();470 case CryptoAlgorithmIdentifier::CONCAT:471 case CryptoAlgorithmIdentifier:: HKDF_CTR:472 case CryptoAlgorithmIdentifier:: PBKDF2:473 case CryptoAlgorithmIdentifier:: AES_KW:464 case CryptoAlgorithmIdentifier::AES_KW: 465 case CryptoAlgorithmIdentifier::HMAC: 466 case CryptoAlgorithmIdentifier::DH: 467 setDOMException(exec, NOT_SUPPORTED_ERR); 468 return nullptr; 469 case CryptoAlgorithmIdentifier::SHA_1: 470 case CryptoAlgorithmIdentifier::SHA_224: 471 case CryptoAlgorithmIdentifier::SHA_256: 472 case CryptoAlgorithmIdentifier::SHA_384: 473 case CryptoAlgorithmIdentifier::SHA_512: 474 return std::make_unique<CryptoAlgorithmParameters>(); 475 case CryptoAlgorithmIdentifier::CONCAT: 476 case CryptoAlgorithmIdentifier::HKDF_CTR: 477 case CryptoAlgorithmIdentifier::PBKDF2: 474 478 setDOMException(exec, NOT_SUPPORTED_ERR); 475 479 return nullptr; … … 494 498 case CryptoAlgorithmIdentifier::AES_GCM: 495 499 case CryptoAlgorithmIdentifier::AES_CFB: 500 case CryptoAlgorithmIdentifier::AES_KW: 496 501 return createAesKeyGenParams(exec, value); 497 502 case CryptoAlgorithmIdentifier::HMAC: … … 508 513 setDOMException(exec, NOT_SUPPORTED_ERR); 509 514 return nullptr; 510 case CryptoAlgorithmIdentifier::AES_KW:511 return createAesKeyGenParams(exec, value);512 515 } 513 516 } … … 527 530 case CryptoAlgorithmIdentifier::AES_GCM: 528 531 case CryptoAlgorithmIdentifier::AES_CFB: 529 case CryptoAlgorithmIdentifier:: HMAC:530 case CryptoAlgorithmIdentifier:: DH:531 case CryptoAlgorithmIdentifier:: SHA_1:532 case CryptoAlgorithmIdentifier::SHA_ 224:533 case CryptoAlgorithmIdentifier::SHA_2 56:534 case CryptoAlgorithmIdentifier::SHA_ 384:535 case CryptoAlgorithmIdentifier::SHA_ 512:536 case CryptoAlgorithmIdentifier:: CONCAT:537 case CryptoAlgorithmIdentifier:: HKDF_CTR:538 case CryptoAlgorithmIdentifier:: PBKDF2:539 case CryptoAlgorithmIdentifier:: AES_KW:532 case CryptoAlgorithmIdentifier::AES_KW: 533 case CryptoAlgorithmIdentifier::HMAC: 534 case CryptoAlgorithmIdentifier::DH: 535 case CryptoAlgorithmIdentifier::SHA_1: 536 case CryptoAlgorithmIdentifier::SHA_224: 537 case CryptoAlgorithmIdentifier::SHA_256: 538 case CryptoAlgorithmIdentifier::SHA_384: 539 case CryptoAlgorithmIdentifier::SHA_512: 540 case CryptoAlgorithmIdentifier::CONCAT: 541 case CryptoAlgorithmIdentifier::HKDF_CTR: 542 case CryptoAlgorithmIdentifier::PBKDF2: 540 543 setDOMException(exec, NOT_SUPPORTED_ERR); 541 544 return nullptr; … … 557 560 case CryptoAlgorithmIdentifier::AES_GCM: 558 561 case CryptoAlgorithmIdentifier::AES_CFB: 559 case CryptoAlgorithmIdentifier:: HMAC:560 case CryptoAlgorithmIdentifier:: DH:561 case CryptoAlgorithmIdentifier:: SHA_1:562 case CryptoAlgorithmIdentifier::SHA_ 224:563 case CryptoAlgorithmIdentifier::SHA_2 56:564 case CryptoAlgorithmIdentifier::SHA_ 384:565 case CryptoAlgorithmIdentifier::SHA_ 512:566 case CryptoAlgorithmIdentifier:: CONCAT:567 case CryptoAlgorithmIdentifier:: HKDF_CTR:568 case CryptoAlgorithmIdentifier:: PBKDF2:569 case CryptoAlgorithmIdentifier:: AES_KW:562 case CryptoAlgorithmIdentifier::AES_KW: 563 case CryptoAlgorithmIdentifier::HMAC: 564 case CryptoAlgorithmIdentifier::DH: 565 case CryptoAlgorithmIdentifier::SHA_1: 566 case CryptoAlgorithmIdentifier::SHA_224: 567 case CryptoAlgorithmIdentifier::SHA_256: 568 case CryptoAlgorithmIdentifier::SHA_384: 569 case CryptoAlgorithmIdentifier::SHA_512: 570 case CryptoAlgorithmIdentifier::CONCAT: 571 case CryptoAlgorithmIdentifier::HKDF_CTR: 572 case CryptoAlgorithmIdentifier::PBKDF2: 570 573 setDOMException(exec, NOT_SUPPORTED_ERR); 571 574 return nullptr; … … 591 594 case CryptoAlgorithmIdentifier::AES_GCM: 592 595 case CryptoAlgorithmIdentifier::AES_CFB: 596 case CryptoAlgorithmIdentifier::AES_KW: 593 597 return std::make_unique<CryptoAlgorithmParameters>(); 594 598 case CryptoAlgorithmIdentifier::HMAC: … … 606 610 setDOMException(exec, NOT_SUPPORTED_ERR); 607 611 return nullptr; 608 case CryptoAlgorithmIdentifier::AES_KW:609 return std::make_unique<CryptoAlgorithmParameters>();610 612 } 611 613 } … … 625 627 case CryptoAlgorithmIdentifier::AES_GCM: 626 628 case CryptoAlgorithmIdentifier::AES_CFB: 627 case CryptoAlgorithmIdentifier::HMAC: 628 case CryptoAlgorithmIdentifier::DH: 629 return std::make_unique<CryptoAlgorithmParameters>(); 630 case CryptoAlgorithmIdentifier::SHA_1: 631 case CryptoAlgorithmIdentifier::SHA_224: 632 case CryptoAlgorithmIdentifier::SHA_256: 633 case CryptoAlgorithmIdentifier::SHA_384: 634 case CryptoAlgorithmIdentifier::SHA_512: 635 case CryptoAlgorithmIdentifier::CONCAT: 636 case CryptoAlgorithmIdentifier::HKDF_CTR: 637 case CryptoAlgorithmIdentifier::PBKDF2: 638 setDOMException(exec, NOT_SUPPORTED_ERR); 639 return nullptr; 640 case CryptoAlgorithmIdentifier::AES_KW: 641 return std::make_unique<CryptoAlgorithmParameters>(); 629 case CryptoAlgorithmIdentifier::AES_KW: 630 case CryptoAlgorithmIdentifier::HMAC: 631 case CryptoAlgorithmIdentifier::DH: 632 return std::make_unique<CryptoAlgorithmParameters>(); 633 case CryptoAlgorithmIdentifier::SHA_1: 634 case CryptoAlgorithmIdentifier::SHA_224: 635 case CryptoAlgorithmIdentifier::SHA_256: 636 case CryptoAlgorithmIdentifier::SHA_384: 637 case CryptoAlgorithmIdentifier::SHA_512: 638 case CryptoAlgorithmIdentifier::CONCAT: 639 case CryptoAlgorithmIdentifier::HKDF_CTR: 640 case CryptoAlgorithmIdentifier::PBKDF2: 641 setDOMException(exec, NOT_SUPPORTED_ERR); 642 return nullptr; 642 643 } 643 644 } -
trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp
r160250 r160455 29 29 30 30 #include "Blob.h" 31 #include "CryptoKeyAES.h" 32 #include "CryptoKeyDataOctetSequence.h" 33 #include "CryptoKeyDataRSAComponents.h" 34 #include "CryptoKeyHMAC.h" 35 #include "CryptoKeyRSA.h" 31 36 #include "ExceptionCode.h" 32 37 #include "File.h" … … 34 39 #include "ImageData.h" 35 40 #include "JSBlob.h" 41 #include "JSCryptoKey.h" 36 42 #include "JSDOMGlobalObject.h" 37 43 #include "JSFile.h" … … 118 124 MapObjectTag = 30, 119 125 NonMapPropertiesTag = 31, 126 #if ENABLE(SUBTLE_CRYPTO) 127 CryptoKeyTag = 32, 128 #endif 120 129 ErrorTag = 255 121 130 }; … … 156 165 157 166 } 167 168 #if ENABLE(SUBTLE_CRYPTO) 169 170 ENUM_CLASS(CryptoKeyClassSubtag) { 171 HMAC = 0, 172 AES = 1, 173 RSA = 2 174 }; 175 const uint8_t cryptoKeyClassSubtagMaximumValue = 2; 176 177 ENUM_CLASS(CryptoKeyAsymmetricTypeSubtag) { 178 Public = 0, 179 Private = 1 180 }; 181 const uint8_t cryptoKeyAsymmetricTypeSubtagMaximumValue = 1; 182 183 ENUM_CLASS(CryptoKeyUsageTag) { 184 Encrypt = 0, 185 Decrypt = 1, 186 Sign = 2, 187 Verify = 3, 188 DeriveKey = 4, 189 DeriveBits = 5, 190 WrapKey = 6, 191 UnwrapKey = 7 192 }; 193 const uint8_t cryptoKeyUsageTagMaximumValue = 7; 194 195 ENUM_CLASS(CryptoAlgorithmIdentifierTag) { 196 RSAES_PKCS1_v1_5 = 0, 197 RSASSA_PKCS1_v1_5 = 1, 198 RSA_PSS = 2, 199 RSA_OAEP = 3, 200 ECDSA = 4, 201 ECDH = 5, 202 AES_CTR = 6, 203 AES_CBC = 7, 204 AES_CMAC = 8, 205 AES_GCM = 9, 206 AES_CFB = 10, 207 AES_KW = 11, 208 HMAC = 12, 209 DH = 13, 210 SHA_1 = 14, 211 SHA_224 = 15, 212 SHA_256 = 16, 213 SHA_384 = 17, 214 SHA_512 = 18, 215 CONCAT = 19, 216 HKDF_CTR = 20, 217 PBKDF2 = 21, 218 }; 219 const uint8_t cryptoAlgorithmIdentifierTagMaximumValue = 21; 220 221 static unsigned countUsages(CryptoKeyUsage usages) 222 { 223 // Fast bit count algorithm for sparse bit maps. 224 unsigned count = 0; 225 while (usages) { 226 usages = usages & (usages - 1); 227 ++count; 228 } 229 return count; 230 } 231 232 #endif 158 233 159 234 /* CurrentVersion tracks the serialization version so that persistent stores … … 218 293 * | MessagePortReferenceTag <value:uint32_t> 219 294 * | ArrayBuffer 220 * | ArrayBufferViewTag ArrayBufferViewSubtag <byteOffset:uint32_t> <byteLeng ht:uint32_t> (ArrayBuffer | ObjectReference)295 * | ArrayBufferViewTag ArrayBufferViewSubtag <byteOffset:uint32_t> <byteLength:uint32_t> (ArrayBuffer | ObjectReference) 221 296 * | ArrayBufferTransferTag <value:uint32_t> 297 * | CryptoKeyTag <extractable:int32_t> <usagesCount:uint32_t> <usages:byte{usagesCount}> CryptoKeyClassSubtag (CryptoKeyHMAC | CryptoKeyAES | CryptoKeyRSA) 222 298 * 223 299 * String :- … … 256 332 * ArrayBuffer :- 257 333 * ArrayBufferTag <length:uint32_t> <contents:byte{length}> 334 * 335 * CryptoKeyHMAC :- 336 * <keySize:uint32_t> <keyData:byte{keySize}> CryptoAlgorithmIdentifierTag // Algorithm tag inner hash function. 337 * 338 * CryptoKeyAES :- 339 * CryptoAlgorithmIdentifierTag <keySize:uint32_t> <keyData:byte{keySize}> 340 * 341 * CryptoKeyRSA :- 342 * CryptoAlgorithmIdentifierTag <isRestrictedToHash:int32_t> CryptoAlgorithmIdentifierTag? CryptoKeyAsymmetricTypeSubtag CryptoKeyRSAPublicComponents CryptoKeyRSAPrivateComponents? 343 * 344 * CryptoKeyRSAPublicComponents :- 345 * <modulusSize:uint32_t> <modulus:byte{modulusSize}> <exponentSize:uint32_t> <exponent:byte{exponentSize}> 346 * 347 * CryptoKeyRSAPrivateComponents :- 348 * <privateExponentSize:uint32_t> <privateExponent:byte{privateExponentSize}> <primeCount:uint32_t> FirstPrimeInfo? PrimeInfo{primeCount - 1} 349 * 350 * // CRT data could be computed from prime factors. It is only serialized to reuse a code path that's needed for JWK. 351 * FirstPrimeInfo :- 352 * <factorSize:uint32_t> <factor:byte{factorSize}> <crtExponentSize:uint32_t> <crtExponent:byte{crtExponentSize}> 353 * 354 * PrimeInfo :- 355 * <factorSize:uint32_t> <factor:byte{factorSize}> <crtExponentSize:uint32_t> <crtExponent:byte{crtExponentSize}> <crtCoefficientSize:uint32_t> <crtCoefficient:byte{crtCoefficientSize}> 258 356 */ 259 357 … … 725 823 return success; 726 824 } 825 #if ENABLE(SUBTLE_CRYPTO) 826 if (CryptoKey* key = toCryptoKey(obj)) { 827 write(CryptoKeyTag); 828 write(key); 829 return true; 830 } 831 #endif 727 832 728 833 return false; … … 742 847 writeLittleEndian<uint8_t>(m_buffer, static_cast<uint8_t>(tag)); 743 848 } 849 850 #if ENABLE(SUBTLE_CRYPTO) 851 void write(CryptoKeyClassSubtag tag) 852 { 853 writeLittleEndian<uint8_t>(m_buffer, static_cast<uint8_t>(tag)); 854 } 855 856 void write(CryptoKeyAsymmetricTypeSubtag tag) 857 { 858 writeLittleEndian<uint8_t>(m_buffer, static_cast<uint8_t>(tag)); 859 } 860 861 void write(CryptoKeyUsageTag tag) 862 { 863 writeLittleEndian<uint8_t>(m_buffer, static_cast<uint8_t>(tag)); 864 } 865 866 void write(CryptoAlgorithmIdentifierTag tag) 867 { 868 writeLittleEndian<uint8_t>(m_buffer, static_cast<uint8_t>(tag)); 869 } 870 #endif 744 871 745 872 void write(uint8_t c) … … 835 962 } 836 963 964 void write(const Vector<uint8_t>& vector) 965 { 966 uint32_t size = vector.size(); 967 write(size); 968 writeLittleEndian(m_buffer, vector.data(), size); 969 } 970 837 971 void write(const File* file) 838 972 { … … 842 976 write(file->type()); 843 977 } 978 979 #if ENABLE(SUBTLE_CRYPTO) 980 void write(CryptoAlgorithmIdentifier algorithm) 981 { 982 switch (algorithm) { 983 case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5: 984 write(CryptoAlgorithmIdentifierTag::RSAES_PKCS1_v1_5); 985 break; 986 case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5: 987 write(CryptoAlgorithmIdentifierTag::RSASSA_PKCS1_v1_5); 988 break; 989 case CryptoAlgorithmIdentifier::RSA_PSS: 990 write(CryptoAlgorithmIdentifierTag::RSA_PSS); 991 break; 992 case CryptoAlgorithmIdentifier::RSA_OAEP: 993 write(CryptoAlgorithmIdentifierTag::RSA_OAEP); 994 break; 995 case CryptoAlgorithmIdentifier::ECDSA: 996 write(CryptoAlgorithmIdentifierTag::ECDSA); 997 break; 998 case CryptoAlgorithmIdentifier::ECDH: 999 write(CryptoAlgorithmIdentifierTag::ECDH); 1000 break; 1001 case CryptoAlgorithmIdentifier::AES_CTR: 1002 write(CryptoAlgorithmIdentifierTag::AES_CTR); 1003 break; 1004 case CryptoAlgorithmIdentifier::AES_CBC: 1005 write(CryptoAlgorithmIdentifierTag::AES_CBC); 1006 break; 1007 case CryptoAlgorithmIdentifier::AES_CMAC: 1008 write(CryptoAlgorithmIdentifierTag::AES_CMAC); 1009 break; 1010 case CryptoAlgorithmIdentifier::AES_GCM: 1011 write(CryptoAlgorithmIdentifierTag::AES_GCM); 1012 break; 1013 case CryptoAlgorithmIdentifier::AES_CFB: 1014 write(CryptoAlgorithmIdentifierTag::AES_CFB); 1015 break; 1016 case CryptoAlgorithmIdentifier::AES_KW: 1017 write(CryptoAlgorithmIdentifierTag::AES_KW); 1018 break; 1019 case CryptoAlgorithmIdentifier::HMAC: 1020 write(CryptoAlgorithmIdentifierTag::HMAC); 1021 break; 1022 case CryptoAlgorithmIdentifier::DH: 1023 write(CryptoAlgorithmIdentifierTag::DH); 1024 break; 1025 case CryptoAlgorithmIdentifier::SHA_1: 1026 write(CryptoAlgorithmIdentifierTag::SHA_1); 1027 break; 1028 case CryptoAlgorithmIdentifier::SHA_224: 1029 write(CryptoAlgorithmIdentifierTag::SHA_224); 1030 break; 1031 case CryptoAlgorithmIdentifier::SHA_256: 1032 write(CryptoAlgorithmIdentifierTag::SHA_256); 1033 break; 1034 case CryptoAlgorithmIdentifier::SHA_384: 1035 write(CryptoAlgorithmIdentifierTag::SHA_384); 1036 break; 1037 case CryptoAlgorithmIdentifier::SHA_512: 1038 write(CryptoAlgorithmIdentifierTag::SHA_512); 1039 break; 1040 case CryptoAlgorithmIdentifier::CONCAT: 1041 write(CryptoAlgorithmIdentifierTag::CONCAT); 1042 break; 1043 case CryptoAlgorithmIdentifier::HKDF_CTR: 1044 write(CryptoAlgorithmIdentifierTag::HKDF_CTR); 1045 break; 1046 case CryptoAlgorithmIdentifier::PBKDF2: 1047 write(CryptoAlgorithmIdentifierTag::PBKDF2); 1048 break; 1049 } 1050 } 1051 1052 void write(CryptoKeyDataRSAComponents::Type type) 1053 { 1054 switch (type) { 1055 case CryptoKeyDataRSAComponents::Type::Public: 1056 write(CryptoKeyAsymmetricTypeSubtag::Public); 1057 return; 1058 case CryptoKeyDataRSAComponents::Type::Private: 1059 write(CryptoKeyAsymmetricTypeSubtag::Private); 1060 return; 1061 } 1062 } 1063 1064 void write(const CryptoKeyDataRSAComponents& key) 1065 { 1066 write(key.type()); 1067 write(key.modulus()); 1068 write(key.exponent()); 1069 if (key.type() == CryptoKeyDataRSAComponents::Type::Public) 1070 return; 1071 1072 write(key.privateExponent()); 1073 1074 unsigned primeCount = key.hasAdditionalPrivateKeyParameters() ? key.otherPrimeInfos().size() + 2 : 0; 1075 write(primeCount); 1076 if (!primeCount) 1077 return; 1078 1079 write(key.firstPrimeInfo().primeFactor); 1080 write(key.firstPrimeInfo().factorCRTExponent); 1081 write(key.secondPrimeInfo().primeFactor); 1082 write(key.secondPrimeInfo().factorCRTExponent); 1083 write(key.secondPrimeInfo().factorCRTCoefficient); 1084 for (unsigned i = 2; i < primeCount; ++i) { 1085 write(key.otherPrimeInfos()[i].primeFactor); 1086 write(key.otherPrimeInfos()[i].factorCRTExponent); 1087 write(key.otherPrimeInfos()[i].factorCRTCoefficient); 1088 } 1089 } 1090 1091 void write(const CryptoKey* key) 1092 { 1093 write(key->extractable()); 1094 1095 CryptoKeyUsage usages = key->usagesBitmap(); 1096 write(countUsages(usages)); 1097 if (usages & CryptoKeyUsageEncrypt) 1098 write(CryptoKeyUsageTag::Encrypt); 1099 if (usages & CryptoKeyUsageDecrypt) 1100 write(CryptoKeyUsageTag::Decrypt); 1101 if (usages & CryptoKeyUsageSign) 1102 write(CryptoKeyUsageTag::Sign); 1103 if (usages & CryptoKeyUsageVerify) 1104 write(CryptoKeyUsageTag::Verify); 1105 if (usages & CryptoKeyUsageDeriveKey) 1106 write(CryptoKeyUsageTag::DeriveKey); 1107 if (usages & CryptoKeyUsageDeriveBits) 1108 write(CryptoKeyUsageTag::DeriveBits); 1109 if (usages & CryptoKeyUsageWrapKey) 1110 write(CryptoKeyUsageTag::WrapKey); 1111 if (usages & CryptoKeyUsageUnwrapKey) 1112 write(CryptoKeyUsageTag::UnwrapKey); 1113 1114 switch (key->keyClass()) { 1115 case CryptoKeyClass::HMAC: 1116 write(CryptoKeyClassSubtag::HMAC); 1117 write(toCryptoKeyHMAC(key)->key()); 1118 write(toCryptoKeyHMAC(key)->hashAlgorithmIdentifier()); 1119 break; 1120 case CryptoKeyClass::AES: 1121 write(CryptoKeyClassSubtag::AES); 1122 write(key->algorithmIdentifier()); 1123 write(toCryptoKeyAES(key)->key()); 1124 break; 1125 case CryptoKeyClass::RSA: 1126 write(CryptoKeyClassSubtag::RSA); 1127 write(key->algorithmIdentifier()); 1128 CryptoAlgorithmIdentifier hash; 1129 bool isRestrictedToHash = toCryptoKeyRSA(key)->isRestrictedToHash(hash); 1130 write(isRestrictedToHash); 1131 if (isRestrictedToHash) 1132 write(hash); 1133 write(toCryptoKeyDataRSAComponents(*key->exportData())); 1134 break; 1135 } 1136 } 1137 #endif 844 1138 845 1139 void write(const uint8_t* data, unsigned length) … … 1454 1748 } 1455 1749 1750 bool read(Vector<uint8_t>& result) 1751 { 1752 ASSERT(result.isEmpty()); 1753 uint32_t size; 1754 if (!read(size)) 1755 return false; 1756 if (m_ptr + size > m_end) 1757 return false; 1758 result.append(m_ptr, size); 1759 m_ptr += size; 1760 return true; 1761 } 1762 1763 #if ENABLE(SUBTLE_CRYPTO) 1764 bool read(CryptoAlgorithmIdentifier& result) 1765 { 1766 uint8_t algorithmTag; 1767 if (!read(algorithmTag)) 1768 return false; 1769 if (algorithmTag > cryptoAlgorithmIdentifierTagMaximumValue) 1770 return false; 1771 switch (static_cast<CryptoAlgorithmIdentifierTag>(algorithmTag)) { 1772 case CryptoAlgorithmIdentifierTag::RSAES_PKCS1_v1_5: 1773 result = CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5; 1774 break; 1775 case CryptoAlgorithmIdentifierTag::RSASSA_PKCS1_v1_5: 1776 result = CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5; 1777 break; 1778 case CryptoAlgorithmIdentifierTag::RSA_PSS: 1779 result = CryptoAlgorithmIdentifier::RSA_PSS; 1780 break; 1781 case CryptoAlgorithmIdentifierTag::RSA_OAEP: 1782 result = CryptoAlgorithmIdentifier::RSA_OAEP; 1783 break; 1784 case CryptoAlgorithmIdentifierTag::ECDSA: 1785 result = CryptoAlgorithmIdentifier::ECDSA; 1786 break; 1787 case CryptoAlgorithmIdentifierTag::ECDH: 1788 result = CryptoAlgorithmIdentifier::ECDH; 1789 break; 1790 case CryptoAlgorithmIdentifierTag::AES_CTR: 1791 result = CryptoAlgorithmIdentifier::AES_CTR; 1792 break; 1793 case CryptoAlgorithmIdentifierTag::AES_CBC: 1794 result = CryptoAlgorithmIdentifier::AES_CBC; 1795 break; 1796 case CryptoAlgorithmIdentifierTag::AES_CMAC: 1797 result = CryptoAlgorithmIdentifier::AES_CMAC; 1798 break; 1799 case CryptoAlgorithmIdentifierTag::AES_GCM: 1800 result = CryptoAlgorithmIdentifier::AES_GCM; 1801 break; 1802 case CryptoAlgorithmIdentifierTag::AES_CFB: 1803 result = CryptoAlgorithmIdentifier::AES_CFB; 1804 break; 1805 case CryptoAlgorithmIdentifierTag::AES_KW: 1806 result = CryptoAlgorithmIdentifier::AES_KW; 1807 break; 1808 case CryptoAlgorithmIdentifierTag::HMAC: 1809 result = CryptoAlgorithmIdentifier::HMAC; 1810 break; 1811 case CryptoAlgorithmIdentifierTag::DH: 1812 result = CryptoAlgorithmIdentifier::DH; 1813 break; 1814 case CryptoAlgorithmIdentifierTag::SHA_1: 1815 result = CryptoAlgorithmIdentifier::SHA_1; 1816 break; 1817 case CryptoAlgorithmIdentifierTag::SHA_224: 1818 result = CryptoAlgorithmIdentifier::SHA_224; 1819 break; 1820 case CryptoAlgorithmIdentifierTag::SHA_256: 1821 result = CryptoAlgorithmIdentifier::SHA_256; 1822 break; 1823 case CryptoAlgorithmIdentifierTag::SHA_384: 1824 result = CryptoAlgorithmIdentifier::SHA_384; 1825 break; 1826 case CryptoAlgorithmIdentifierTag::SHA_512: 1827 result = CryptoAlgorithmIdentifier::SHA_512; 1828 break; 1829 case CryptoAlgorithmIdentifierTag::CONCAT: 1830 result = CryptoAlgorithmIdentifier::CONCAT; 1831 break; 1832 case CryptoAlgorithmIdentifierTag::HKDF_CTR: 1833 result = CryptoAlgorithmIdentifier::HKDF_CTR; 1834 break; 1835 case CryptoAlgorithmIdentifierTag::PBKDF2: 1836 result = CryptoAlgorithmIdentifier::PBKDF2; 1837 break; 1838 } 1839 return true; 1840 } 1841 1842 bool read(CryptoKeyClassSubtag& result) 1843 { 1844 uint8_t tag; 1845 if (!read(tag)) 1846 return false; 1847 if (tag > cryptoKeyClassSubtagMaximumValue) 1848 return false; 1849 result = static_cast<CryptoKeyClassSubtag>(tag); 1850 return true; 1851 } 1852 1853 bool read(CryptoKeyUsageTag& result) 1854 { 1855 uint8_t tag; 1856 if (!read(tag)) 1857 return false; 1858 if (tag > cryptoKeyUsageTagMaximumValue) 1859 return false; 1860 result = static_cast<CryptoKeyUsageTag>(tag); 1861 return true; 1862 } 1863 1864 bool read(CryptoKeyAsymmetricTypeSubtag& result) 1865 { 1866 uint8_t tag; 1867 if (!read(tag)) 1868 return false; 1869 if (tag > cryptoKeyAsymmetricTypeSubtagMaximumValue) 1870 return false; 1871 result = static_cast<CryptoKeyAsymmetricTypeSubtag>(tag); 1872 return true; 1873 } 1874 1875 bool readHMACKey(bool extractable, CryptoKeyUsage usages, RefPtr<CryptoKey>& result) 1876 { 1877 Vector<uint8_t> keyData; 1878 if (!read(keyData)) 1879 return false; 1880 CryptoAlgorithmIdentifier hash; 1881 if (!read(hash)) 1882 return false; 1883 result = CryptoKeyHMAC::create(keyData, hash, extractable, usages); 1884 return true; 1885 } 1886 1887 bool readAESKey(bool extractable, CryptoKeyUsage usages, RefPtr<CryptoKey>& result) 1888 { 1889 CryptoAlgorithmIdentifier algorithm; 1890 if (!read(algorithm)) 1891 return false; 1892 if (!CryptoKeyAES::isValidAESAlgorithm(algorithm)) 1893 return false; 1894 Vector<uint8_t> keyData; 1895 if (!read(keyData)) 1896 return false; 1897 result = CryptoKeyAES::create(algorithm, keyData, extractable, usages); 1898 return true; 1899 } 1900 1901 bool readRSAKey(bool extractable, CryptoKeyUsage usages, RefPtr<CryptoKey>& result) 1902 { 1903 CryptoAlgorithmIdentifier algorithm; 1904 if (!read(algorithm)) 1905 return false; 1906 1907 int32_t isRestrictedToHash; 1908 CryptoAlgorithmIdentifier hash; 1909 if (!read(isRestrictedToHash)) 1910 return false; 1911 if (isRestrictedToHash && !read(hash)) 1912 return false; 1913 1914 CryptoKeyAsymmetricTypeSubtag type; 1915 if (!read(type)) 1916 return false; 1917 1918 Vector<uint8_t> modulus; 1919 if (!read(modulus)) 1920 return false; 1921 Vector<uint8_t> exponent; 1922 if (!read(exponent)) 1923 return false; 1924 1925 if (type == CryptoKeyAsymmetricTypeSubtag::Public) { 1926 auto keyData = CryptoKeyDataRSAComponents::createPublic(modulus, exponent); 1927 auto key = CryptoKeyRSA::create(algorithm, *keyData, extractable, usages); 1928 if (isRestrictedToHash) 1929 key->restrictToHash(hash); 1930 result = std::move(key); 1931 return true; 1932 } 1933 1934 Vector<uint8_t> privateExponent; 1935 if (!read(privateExponent)) 1936 return false; 1937 1938 uint32_t primeCount; 1939 if (!read(primeCount)) 1940 return false; 1941 1942 if (!primeCount) { 1943 auto keyData = CryptoKeyDataRSAComponents::createPrivate(modulus, exponent, privateExponent); 1944 auto key = CryptoKeyRSA::create(algorithm, *keyData, extractable, usages); 1945 if (isRestrictedToHash) 1946 key->restrictToHash(hash); 1947 result = std::move(key); 1948 return true; 1949 } 1950 1951 if (primeCount < 2) 1952 return false; 1953 1954 CryptoKeyDataRSAComponents::PrimeInfo firstPrimeInfo; 1955 CryptoKeyDataRSAComponents::PrimeInfo secondPrimeInfo; 1956 Vector<CryptoKeyDataRSAComponents::PrimeInfo> otherPrimeInfos(primeCount - 2); 1957 1958 if (!read(firstPrimeInfo.primeFactor)) 1959 return false; 1960 if (!read(firstPrimeInfo.factorCRTExponent)) 1961 return false; 1962 if (!read(secondPrimeInfo.primeFactor)) 1963 return false; 1964 if (!read(secondPrimeInfo.factorCRTExponent)) 1965 return false; 1966 if (!read(secondPrimeInfo.factorCRTCoefficient)) 1967 return false; 1968 for (unsigned i = 2; i < primeCount; ++i) { 1969 if (!read(otherPrimeInfos[i].primeFactor)) 1970 return false; 1971 if (!read(otherPrimeInfos[i].factorCRTExponent)) 1972 return false; 1973 if (!read(otherPrimeInfos[i].factorCRTCoefficient)) 1974 return false; 1975 } 1976 1977 auto keyData = CryptoKeyDataRSAComponents::createPrivateWithAdditionalData(modulus, exponent, privateExponent, firstPrimeInfo, secondPrimeInfo, otherPrimeInfos); 1978 auto key = CryptoKeyRSA::create(algorithm, *keyData, extractable, usages); 1979 if (isRestrictedToHash) 1980 key->restrictToHash(hash); 1981 result = std::move(key); 1982 return true; 1983 } 1984 1985 bool readCryptoKey(JSValue& cryptoKey) 1986 { 1987 int32_t extractable; 1988 if (!read(extractable)) 1989 return false; 1990 1991 uint32_t usagesCount; 1992 if (!read(usagesCount)) 1993 return false; 1994 1995 CryptoKeyUsage usages = 0; 1996 for (uint32_t i = 0; i < usagesCount; ++i) { 1997 CryptoKeyUsageTag usage; 1998 if (!read(usage)) 1999 return false; 2000 switch (usage) { 2001 case CryptoKeyUsageTag::Encrypt: 2002 usages |= CryptoKeyUsageEncrypt; 2003 break; 2004 case CryptoKeyUsageTag::Decrypt: 2005 usages |= CryptoKeyUsageDecrypt; 2006 break; 2007 case CryptoKeyUsageTag::Sign: 2008 usages |= CryptoKeyUsageSign; 2009 break; 2010 case CryptoKeyUsageTag::Verify: 2011 usages |= CryptoKeyUsageVerify; 2012 break; 2013 case CryptoKeyUsageTag::DeriveKey: 2014 usages |= CryptoKeyUsageDeriveKey; 2015 break; 2016 case CryptoKeyUsageTag::DeriveBits: 2017 usages |= CryptoKeyUsageDeriveBits; 2018 break; 2019 case CryptoKeyUsageTag::WrapKey: 2020 usages |= CryptoKeyUsageWrapKey; 2021 break; 2022 case CryptoKeyUsageTag::UnwrapKey: 2023 usages |= CryptoKeyUsageUnwrapKey; 2024 break; 2025 } 2026 } 2027 2028 CryptoKeyClassSubtag cryptoKeyClass; 2029 if (!read(cryptoKeyClass)) 2030 return false; 2031 RefPtr<CryptoKey> result; 2032 switch (cryptoKeyClass) { 2033 case CryptoKeyClassSubtag::HMAC: 2034 if (!readHMACKey(extractable, usages, result)) 2035 return false; 2036 break; 2037 case CryptoKeyClassSubtag::AES: 2038 if (!readAESKey(extractable, usages, result)) 2039 return false; 2040 break; 2041 case CryptoKeyClassSubtag::RSA: 2042 if (!readRSAKey(extractable, usages, result)) 2043 return false; 2044 break; 2045 } 2046 cryptoKey = getJSValue(result.get()); 2047 return true; 2048 } 2049 #endif 2050 1456 2051 template<class T> 1457 2052 JSValue getJSValue(T* nativeObj) … … 1659 2254 return arrayBufferView; 1660 2255 } 2256 #if ENABLE(SUBTLE_CRYPTO) 2257 case CryptoKeyTag: { 2258 JSValue cryptoKey; 2259 if (!readCryptoKey(cryptoKey)) { 2260 fail(); 2261 return JSValue(); 2262 } 2263 m_gcBuffer.append(cryptoKey); 2264 return cryptoKey; 2265 } 2266 #endif 1661 2267 default: 1662 2268 m_ptr--; // Push the tag back -
trunk/Source/WebCore/crypto/CryptoAlgorithmIdentifier.h
r159966 r160455 43 43 AES_GCM, 44 44 AES_CFB, 45 AES_KW, 45 46 HMAC, 46 47 DH, … … 52 53 CONCAT, 53 54 HKDF_CTR, 54 PBKDF2, 55 AES_KW // Not yet standardized. 55 PBKDF2 56 56 }; 57 57 -
trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.cpp
r158396 r160455 36 36 CryptoAlgorithmRegistry& CryptoAlgorithmRegistry::shared() 37 37 { 38 ASSERT(isMainThread());39 38 DEFINE_STATIC_LOCAL(CryptoAlgorithmRegistry, registry, ()); 40 39 return registry; 40 } 41 42 static Mutex& registryMutex() 43 { 44 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); 45 return mutex; 41 46 } 42 47 … … 51 56 return false; 52 57 53 auto iter = m_nameToIdentifierMap.find(name.lower()); 58 MutexLocker lock(registryMutex()); 59 60 auto iter = m_nameToIdentifierMap.find(name.isolatedCopy().lower()); 54 61 if (iter == m_nameToIdentifierMap.end()) 55 62 return false; … … 61 68 String CryptoAlgorithmRegistry::nameForIdentifier(CryptoAlgorithmIdentifier identifier) 62 69 { 63 return m_identifierToNameMap.get(static_cast<unsigned>(identifier)); 70 MutexLocker lock(registryMutex()); 71 72 return m_identifierToNameMap.get(static_cast<unsigned>(identifier)).isolatedCopy(); 64 73 } 65 74 66 75 std::unique_ptr<CryptoAlgorithm> CryptoAlgorithmRegistry::create(CryptoAlgorithmIdentifier identifier) 67 76 { 77 MutexLocker lock(registryMutex()); 78 68 79 auto iter = m_identifierToConstructorMap.find(static_cast<unsigned>(identifier)); 69 80 if (iter == m_identifierToConstructorMap.end()) … … 76 87 { 77 88 ASSERT(name == name.lower()); 89 90 MutexLocker lock(registryMutex()); 78 91 79 92 bool added = m_nameToIdentifierMap.add(name, identifier).isNewEntry; -
trunk/Source/WebCore/crypto/CryptoKey.idl
r159068 r160455 45 45 GenerateIsReachable=Impl, 46 46 InterfaceName=Key, 47 JSNoStaticTables, 47 48 NoInterfaceObject, 48 49 SkipVTableValidation -
trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp
r159966 r160455 40 40 , m_key(key) 41 41 { 42 ASSERT(algorithm == CryptoAlgorithmIdentifier::AES_CTR 42 ASSERT(isValidAESAlgorithm(algorithm)); 43 } 44 45 CryptoKeyAES::~CryptoKeyAES() 46 { 47 } 48 49 bool CryptoKeyAES::isValidAESAlgorithm(CryptoAlgorithmIdentifier algorithm) 50 { 51 return algorithm == CryptoAlgorithmIdentifier::AES_CTR 43 52 || algorithm == CryptoAlgorithmIdentifier::AES_CBC 44 53 || algorithm == CryptoAlgorithmIdentifier::AES_CMAC 45 54 || algorithm == CryptoAlgorithmIdentifier::AES_GCM 46 55 || algorithm == CryptoAlgorithmIdentifier::AES_CFB 47 || algorithm == CryptoAlgorithmIdentifier::AES_KW); 48 } 49 50 CryptoKeyAES::~CryptoKeyAES() 51 { 56 || algorithm == CryptoAlgorithmIdentifier::AES_KW; 52 57 } 53 58 -
trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h
r159390 r160455 43 43 virtual ~CryptoKeyAES(); 44 44 45 static bool isValidAESAlgorithm(CryptoAlgorithmIdentifier); 46 45 47 static PassRefPtr<CryptoKeyAES> generate(CryptoAlgorithmIdentifier, size_t lengthBits, bool extractable, CryptoKeyUsage); 46 48
Note:
See TracChangeset
for help on using the changeset viewer.