WebCrypto keys should support structured clone
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Dec 2013 22:13:55 +0000 (22:13 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Dec 2013 22:13:55 +0000 (22:13 +0000)
commitfb3bde04520ad6f695bbe9295b692ba90ddc22cc
tree969965c0c4a9be19b1e3ba87e620724d78ccd767
parenta95b07eccfdd81ce65621be8cd001dbb500bceec
WebCrypto keys should support structured clone
https://bugs.webkit.org/show_bug.cgi?id=125590

Reviewed by Oliver Hunt.

Source/WebCore:

Tests: crypto/subtle/aes-postMessage.html
       crypto/subtle/hmac-postMessage.html
       crypto/subtle/postMessage-worker.html
       crypto/subtle/rsa-postMessage.html

* crypto/CryptoAlgorithmIdentifier.h:
(WebCore::CryptoAlgorithmIdentifier):
* bindings/js/JSCryptoAlgorithmDictionary.cpp:
(WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForSign):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForVerify):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForDigest):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForGenerateKey):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveKey):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveBits):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForExportKey):
AES_KW was added to WebCrypto spec editor's draft yesterday night. Now that we're
adding a matching enum for structired clone serialization, it's as good a time as
any to update the order of values to match.

* bindings/js/SerializedScriptValue.cpp:
(WebCore::countUsages):
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneSerializer::write):
(WebCore::CloneDeserializer::read):
(WebCore::CloneDeserializer::readHMACKey):
(WebCore::CloneDeserializer::readAESKey):
(WebCore::CloneDeserializer::readRSAKey):
(WebCore::CloneDeserializer::readCryptoKey):
(WebCore::CloneDeserializer::readTerminal):
Added serialization/deserialization for CryptoKey. This doesn't update version
number, because we don't currently store structured clones in persistent storage -
and even if we did, we wouldn't want to invalidate everything users already stored.

* crypto/CryptoAlgorithmRegistry.cpp:
(WebCore::CryptoAlgorithmRegistry::shared):
(WebCore::registryMutex):
(WebCore::CryptoAlgorithmRegistry::getIdentifierForName):
(WebCore::CryptoAlgorithmRegistry::nameForIdentifier):
(WebCore::CryptoAlgorithmRegistry::create):
(WebCore::CryptoAlgorithmRegistry::registerAlgorithm):
* crypto/CryptoKey.idl:
With structured clone, it is now possible to send a Key to a web worker. That's
of no practical use because the crypto API is not exposed in workers, but we
shouldn't crash anyway.

* crypto/keys/CryptoKeyAES.cpp:
(WebCore::CryptoKeyAES::CryptoKeyAES):
(WebCore::CryptoKeyAES::isValidAESAlgorithm):
* crypto/keys/CryptoKeyAES.h:
Exposed isValidAESAlgorithm, so that a caller could know whether the constructor
will assert.

* CMakeLists.txt:
* GNUmakefile.am:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.vcxproj/WebCoreCommon.props:
Added crypto/keys to search paths to avoid build breakage.

LayoutTests:

* crypto/subtle/aes-postMessage-expected.txt: Added.
* crypto/subtle/aes-postMessage.html: Added.
* crypto/subtle/hmac-postMessage-expected.txt: Added.
* crypto/subtle/hmac-postMessage.html: Added.
* crypto/subtle/postMessage-worker-expected.txt: Added.
* crypto/subtle/postMessage-worker.html: Added.
* crypto/subtle/rsa-postMessage-expected.txt: Added.
* crypto/subtle/rsa-postMessage.html: Added.
* crypto/subtle/resources/postMessage-worker.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160455 268f45cc-cd09-0410-ab3c-d52691b4dbfc
22 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/aes-postMessage-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-postMessage.html [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-postMessage-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-postMessage.html [new file with mode: 0644]
LayoutTests/crypto/subtle/postMessage-worker-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/postMessage-worker.html [new file with mode: 0644]
LayoutTests/crypto/subtle/resources/postMessage-worker.js [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-postMessage-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-postMessage.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.am
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.vcxproj/WebCoreCommon.props
Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/crypto/CryptoAlgorithmIdentifier.h
Source/WebCore/crypto/CryptoAlgorithmRegistry.cpp
Source/WebCore/crypto/CryptoKey.idl
Source/WebCore/crypto/keys/CryptoKeyAES.cpp
Source/WebCore/crypto/keys/CryptoKeyAES.h