Support exporting symmetric keys as JWK
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Nov 2013 07:10:31 +0000 (07:10 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Nov 2013 07:10:31 +0000 (07:10 +0000)
commitf8cf44284ef86102c57cf224d642f6d83ba61d93
tree8bbd8599f77ef1ea40e78633997e3b34e114b503
parentda6b7d23498d5bad22c90a870eae4bc34411969c
Support exporting symmetric keys as JWK
https://bugs.webkit.org/show_bug.cgi?id=124442

Reviewed by Sam Weinig.

Source/JavaScriptCore:

* runtime/JSONObject.h: Export JSONStringify.

Source/WebCore:

Error handling is not consistent yet - some errors cause exceptions, and others
result in rejected promises. This part of spec is incomplete, so I basically did
what was most straightforward in each case.

* bindings/js/JSCryptoKeySerializationJWK.h:
* bindings/js/JSCryptoKeySerializationJWK.cpp:
(WebCore::JSCryptoKeySerializationJWK::reconcileUsages): Updated a comment with a better link.
(WebCore::JSCryptoKeySerializationJWK::buildJSONForOctetSequence): A helper to building JWK.
(WebCore::JSCryptoKeySerializationJWK::addToJSON): Ditto.
(WebCore::JSCryptoKeySerializationJWK::addBoolToJSON): Ditto.
(WebCore::JSCryptoKeySerializationJWK::addJWKAlgorithmToJSON): Ditto. The code for
mapping is my best guess, this all needs to be specified.
(WebCore::JSCryptoKeySerializationJWK::addJWKUseToJSON): A helper to building JWK.
(WebCore::JSCryptoKeySerializationJWK::serialize): Build a JSON string for the key.

* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::JSSubtleCrypto::importKey): Updated a comment.
(WebCore::JSSubtleCrypto::exportKey): Use CryptoKeySerialization (also for raw keys,
for consistency).

* crypto/CryptoKey.h:
(WebCore::CryptoKey::algorithmIdentifier):
(WebCore::CryptoKey::usagesBitmap):
Exposed data needed for building JWK (it used to be only exposed in a form suitable
for DOM accessors).

* crypto/keys/CryptoKeyHMAC.h: Ditto, added an accessor for JWK.

* crypto/keys/CryptoKeySerializationRaw.cpp: (WebCore::CryptoKeySerializationRaw::serialize):
* crypto/keys/CryptoKeySerializationRaw.h:
Moved from JSSubtleCryptoCustom.cpp for consistency.

Source/WTF:

Base64URL encoding doesn't use '=' padding, and doesn't need any other options.
Added this mode for encode, and removed policy arguments from exposed functions.

* wtf/text/Base64.cpp:
(WTF::base64EncodeInternal):
(WTF::base64URLEncode):
(WTF::base64URLDecode):
* wtf/text/Base64.h:
(WTF::base64URLEncode):

LayoutTests:

* crypto/subtle/aes-export-key-expected.txt:
* crypto/subtle/aes-export-key.html:
* crypto/subtle/hmac-export-key-expected.txt:
* crypto/subtle/hmac-export-key.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@159377 268f45cc-cd09-0410-ab3c-d52691b4dbfc
18 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/aes-export-key-expected.txt
LayoutTests/crypto/subtle/aes-export-key.html
LayoutTests/crypto/subtle/hmac-export-key-expected.txt
LayoutTests/crypto/subtle/hmac-export-key.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSONObject.h
Source/WTF/ChangeLog
Source/WTF/wtf/text/Base64.cpp
Source/WTF/wtf/text/Base64.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp
Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.h
Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
Source/WebCore/crypto/CryptoKey.h
Source/WebCore/crypto/keys/CryptoKeyHMAC.h
Source/WebCore/crypto/keys/CryptoKeySerializationRaw.cpp
Source/WebCore/crypto/keys/CryptoKeySerializationRaw.h