Diff
Modified: trunk/LayoutTests/ChangeLog (205940 => 205941)
--- trunk/LayoutTests/ChangeLog 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/LayoutTests/ChangeLog 2016-09-15 00:19:12 UTC (rev 205941)
@@ -1,3 +1,18 @@
+2016-09-14 Jiewen Tan <[email protected]>
+
+ WebCrypto algorithms should be exposed via KeyAlgorithm dictionary
+ https://bugs.webkit.org/show_bug.cgi?id=128748
+ <rdar://problem/27359438>
+
+ Reviewed by Brent Fulgham and Chris Dumez.
+
+ * crypto/subtle/crypto-key-algorithm-gc-expected.txt: Added.
+ * crypto/subtle/crypto-key-algorithm-gc.html: Added.
+ * crypto/subtle/crypto-key-usages-gc-expected.txt: Added.
+ * crypto/subtle/crypto-key-usages-gc.html: Added.
+ * crypto/subtle/hmac-generate-key-expected.txt:
+ * crypto/subtle/hmac-generate-key.html:
+
2016-09-14 Chris Dumez <[email protected]>
REGRESSION (r205670): ASSERTION FAILED: methodTable(vm)->toThis(this, exec, NotStrictMode) == this
Added: trunk/LayoutTests/crypto/subtle/crypto-key-algorithm-gc-expected.txt (0 => 205941)
--- trunk/LayoutTests/crypto/subtle/crypto-key-algorithm-gc-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/crypto-key-algorithm-gc-expected.txt 2016-09-15 00:19:12 UTC (rev 205941)
@@ -0,0 +1,13 @@
+Test that CryptoKey.algorithm preserves custom properties.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Generating a HMAC key with default length...
+PASS key.algorithm === key.algorithm is true
+PASS key.algorithm.foo is "bar"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/crypto-key-algorithm-gc.html (0 => 205941)
--- trunk/LayoutTests/crypto/subtle/crypto-key-algorithm-gc.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/crypto-key-algorithm-gc.html 2016-09-15 00:19:12 UTC (rev 205941)
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+
+description("Test that CryptoKey.algorithm preserves custom properties.");
+jsTestIsAsync = true;
+
+debug("\nGenerating a HMAC key with default length...");
+crypto.subtle.generateKey({name: "hmac", hash: "sha-1"}, true, ["sign", "verify"]).then(function(result) {
+ key = result;
+ startTest();
+});
+
+function startTest()
+{
+ shouldBeTrue("key.algorithm === key.algorithm");
+ key.algorithm.foo = "bar";
+ gc();
+ setTimeout(continueTest, 10);
+}
+
+function continueTest()
+{
+ gc();
+ setTimeout(finishTest, 10);
+}
+
+function finishTest()
+{
+ gc();
+ shouldBeEqualToString('key.algorithm.foo', 'bar');
+ finishJSTest();
+}
+
+</script>
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/crypto/subtle/crypto-key-usages-gc-expected.txt (0 => 205941)
--- trunk/LayoutTests/crypto/subtle/crypto-key-usages-gc-expected.txt (rev 0)
+++ trunk/LayoutTests/crypto/subtle/crypto-key-usages-gc-expected.txt 2016-09-15 00:19:12 UTC (rev 205941)
@@ -0,0 +1,13 @@
+Test that CryptoKey.usages preserves custom properties.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Generating a HMAC key with default length...
+PASS key.usages === key.usages is true
+PASS key.usages.foo is "bar"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/crypto/subtle/crypto-key-usages-gc.html (0 => 205941)
--- trunk/LayoutTests/crypto/subtle/crypto-key-usages-gc.html (rev 0)
+++ trunk/LayoutTests/crypto/subtle/crypto-key-usages-gc.html 2016-09-15 00:19:12 UTC (rev 205941)
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+
+description("Test that CryptoKey.usages preserves custom properties.");
+jsTestIsAsync = true;
+
+debug("\nGenerating a HMAC key with default length...");
+crypto.subtle.generateKey({name: "hmac", hash: "sha-1"}, true, ["sign", "verify"]).then(function(result) {
+ key = result;
+ startTest();
+});
+
+function startTest()
+{
+ shouldBeTrue("key.usages === key.usages");
+ key.usages.foo = "bar";
+ gc();
+ setTimeout(continueTest, 10);
+}
+
+function continueTest()
+{
+ gc();
+ setTimeout(finishTest, 10);
+}
+
+function finishTest()
+{
+ gc();
+ shouldBeEqualToString('key.usages.foo', 'bar');
+ finishJSTest();
+}
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/crypto/subtle/hmac-generate-key-expected.txt (205940 => 205941)
--- trunk/LayoutTests/crypto/subtle/hmac-generate-key-expected.txt 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/LayoutTests/crypto/subtle/hmac-generate-key-expected.txt 2016-09-15 00:19:12 UTC (rev 205941)
@@ -13,6 +13,7 @@
PASS key.extractable is true
PASS key.algorithm.name is 'HMAC'
PASS key.algorithm.length is 64
+PASS key.algorithm.hash.name is 'SHA-1'
PASS key.usages is ["sign", "verify"]
Generating a key with custom length...
@@ -20,6 +21,7 @@
PASS key.extractable is true
PASS key.algorithm.name is 'HMAC'
PASS key.algorithm.length is 5
+PASS key.algorithm.hash.name is 'SHA-1'
PASS key.usages is ["sign"]
PASS successfullyParsed is true
Modified: trunk/LayoutTests/crypto/subtle/hmac-generate-key.html (205940 => 205941)
--- trunk/LayoutTests/crypto/subtle/hmac-generate-key.html 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/LayoutTests/crypto/subtle/hmac-generate-key.html 2016-09-15 00:19:12 UTC (rev 205941)
@@ -28,6 +28,7 @@
shouldBe("key.extractable", "true");
shouldBe("key.algorithm.name", "'HMAC'");
shouldBe("key.algorithm.length", "64");
+ shouldBe("key.algorithm.hash.name", "'SHA-1'");
shouldBe("key.usages", '["sign", "verify"]');
debug("\nGenerating a key with custom length...");
@@ -39,6 +40,7 @@
shouldBe("key.extractable", "true");
shouldBe("key.algorithm.name", "'HMAC'");
shouldBe("key.algorithm.length", "5");
+ shouldBe("key.algorithm.hash.name", "'SHA-1'");
shouldBe("key.usages", '["sign"]');
finishJSTest();
});
Modified: trunk/Source/WebCore/ChangeLog (205940 => 205941)
--- trunk/Source/WebCore/ChangeLog 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/ChangeLog 2016-09-15 00:19:12 UTC (rev 205941)
@@ -1,3 +1,68 @@
+2016-09-14 Jiewen Tan <[email protected]>
+
+ WebCrypto algorithms should be exposed via KeyAlgorithm dictionary
+ https://bugs.webkit.org/show_bug.cgi?id=128748
+ <rdar://problem/27359438>
+
+ Reviewed by Brent Fulgham and Chris Dumez.
+
+ Replace custom CryptoAlgorithmBuilder/buildAlgorithmDescription with KeyAlgorithm dictionary which is
+ defined by the spec: https://www.w3.org/TR/WebCryptoAPI/#key-algorithm-dictionary. Moreover, mark
+ CryptoKey.usages as CachedAttribute.
+
+ Tests: crypto/subtle/crypto-key-algorithm-gc.html
+ crypto/subtle/crypto-key-usages-gc.html
+
+ * PlatformEfl.cmake:
+ * PlatformGTK.cmake:
+ * PlatformMac.cmake:
+ Remove CryptoAlgorithmDescriptionBuilder.cpp.
+ * WebCore.xcodeproj/project.pbxproj:
+ * bindings/js/JSCryptoAlgorithmBuilder.cpp:
+ (WebCore::JSCryptoAlgorithmBuilder::add):
+ (WebCore::JSCryptoAlgorithmBuilder::createEmptyClone): Deleted.
+ * bindings/js/JSCryptoAlgorithmBuilder.h:
+ * bindings/js/JSCryptoKeyCustom.cpp:
+ (WebCore::JSCryptoKey::algorithm):
+ Get rid of dependency on CryptoAlgorithmDescriptionBuilder.
+ * crypto/CryptoAlgorithmDescriptionBuilder.cpp: Removed.
+ * crypto/CryptoAlgorithmDescriptionBuilder.h: Removed.
+ Replace it with KeyAlgorithm.
+ * crypto/CryptoKey.cpp:
+ (WebCore::CryptoKey::CryptoKey):
+ (WebCore::CryptoKey::buildAlgorithmDescription): Deleted.
+ * crypto/CryptoKey.h:
+ (WebCore::KeyAlgorithm::KeyAlgorithm):
+ (WebCore::KeyAlgorithm::~KeyAlgorithm):
+ (WebCore::CryptoKey::algorithmIdentifier):
+ * crypto/CryptoKey.idl:
+ Add KeyAlgorithm dictionary which is returned via CryptoKey.buildAlgorithm() method,
+ and rename m_algorithm to m_algorithmIdentifier to distingush it with newly
+ added KeyAlgorithm dictionary.
+ * crypto/gnutls/CryptoKeyRSAGnuTLS.cpp:
+ (WebCore::buildAlgorithm):
+ (WebCore::CryptoKeyRSA::buildAlgorithmDescription): Deleted.
+ * crypto/keys/CryptoKeyAES.cpp:
+ (WebCore::CryptoKeyAES::buildAlgorithm):
+ (WebCore::CryptoKeyAES::buildAlgorithmDescription): Deleted.
+ * crypto/keys/CryptoKeyAES.h:
+ (WebCore::AesKeyAlgorithm::AesKeyAlgorithm):
+ (WebCore::AesKeyAlgorithm::~AesKeyAlgorithm):
+ * crypto/keys/CryptoKeyHMAC.cpp:
+ (WebCore::CryptoKeyHMAC::buildAlgorithm):
+ (WebCore::CryptoKeyHMAC::buildAlgorithmDescription): Deleted.
+ * crypto/keys/CryptoKeyHMAC.h:
+ (WebCore::HmacKeyAlgorithm::HmacKeyAlgorithm):
+ (WebCore::HmacKeyAlgorithm::~HmacKeyAlgorithm):
+ * crypto/keys/CryptoKeyRSA.h:
+ (WebCore::RsaKeyAlgorithm::RsaKeyAlgorithm):
+ (WebCore::RsaKeyAlgorithm::~RsaKeyAlgorithm):
+ (WebCore::RsaHashedKeyAlgorithm::RsaHashedKeyAlgorithm):
+ (WebCore::RsaHashedKeyAlgorithm::~RsaHashedKeyAlgorithm):
+ * crypto/mac/CryptoKeyRSAMac.cpp:
+ (WebCore::CryptoKeyRSA::buildAlgorithm):
+ (WebCore::CryptoKeyRSA::buildAlgorithmDescription): Deleted.
+
2016-09-14 Chris Dumez <[email protected]>
REGRESSION (r205670): ASSERTION FAILED: methodTable(vm)->toThis(this, exec, NotStrictMode) == this
Modified: trunk/Source/WebCore/PlatformEfl.cmake (205940 => 205941)
--- trunk/Source/WebCore/PlatformEfl.cmake 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/PlatformEfl.cmake 2016-09-15 00:19:12 UTC (rev 205941)
@@ -403,7 +403,6 @@
if (ENABLE_SUBTLE_CRYPTO)
list(APPEND WebCore_SOURCES
crypto/CryptoAlgorithm.cpp
- crypto/CryptoAlgorithmDescriptionBuilder.cpp
crypto/CryptoAlgorithmRegistry.cpp
crypto/CryptoKey.cpp
crypto/CryptoKeyPair.cpp
Modified: trunk/Source/WebCore/PlatformGTK.cmake (205940 => 205941)
--- trunk/Source/WebCore/PlatformGTK.cmake 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/PlatformGTK.cmake 2016-09-15 00:19:12 UTC (rev 205941)
@@ -397,7 +397,6 @@
if (ENABLE_SUBTLE_CRYPTO)
list(APPEND WebCore_SOURCES
crypto/CryptoAlgorithm.cpp
- crypto/CryptoAlgorithmDescriptionBuilder.cpp
crypto/CryptoAlgorithmRegistry.cpp
crypto/CryptoKey.cpp
crypto/CryptoKeyPair.cpp
Modified: trunk/Source/WebCore/PlatformMac.cmake (205940 => 205941)
--- trunk/Source/WebCore/PlatformMac.cmake 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/PlatformMac.cmake 2016-09-15 00:19:12 UTC (rev 205941)
@@ -176,7 +176,6 @@
crypto/CommonCryptoUtilities.cpp
crypto/CryptoAlgorithm.cpp
- crypto/CryptoAlgorithmDescriptionBuilder.cpp
crypto/CryptoAlgorithmRegistry.cpp
crypto/CryptoKey.cpp
crypto/CryptoKeyPair.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (205940 => 205941)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-09-15 00:19:12 UTC (rev 205941)
@@ -5976,8 +5976,6 @@
E157A8E418173A3A009F821D /* CryptoKey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E157A8E218173A3A009F821D /* CryptoKey.cpp */; };
E157A8E518173A3A009F821D /* CryptoKey.h in Headers */ = {isa = PBXBuildFile; fileRef = E157A8E318173A3A009F821D /* CryptoKey.h */; };
E157A8E818184C67009F821D /* JSCryptoKeyCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E157A8E618184C67009F821D /* JSCryptoKeyCustom.cpp */; };
- E157A8EC181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E157A8EA181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp */; };
- E157A8ED181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = E157A8EB181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h */; };
E157A8F018185425009F821D /* JSCryptoAlgorithmBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E157A8EE18185425009F821D /* JSCryptoAlgorithmBuilder.cpp */; };
E157A8F118185425009F821D /* JSCryptoAlgorithmBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = E157A8EF18185425009F821D /* JSCryptoAlgorithmBuilder.h */; };
E15A36D71104572000B7B639 /* XMLNSNames.h in Headers */ = {isa = PBXBuildFile; fileRef = E15A36D61104572000B7B639 /* XMLNSNames.h */; };
@@ -13559,8 +13557,6 @@
E157A8E218173A3A009F821D /* CryptoKey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoKey.cpp; sourceTree = "<group>"; };
E157A8E318173A3A009F821D /* CryptoKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKey.h; sourceTree = "<group>"; };
E157A8E618184C67009F821D /* JSCryptoKeyCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCryptoKeyCustom.cpp; sourceTree = "<group>"; };
- E157A8EA181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmDescriptionBuilder.cpp; sourceTree = "<group>"; };
- E157A8EB181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmDescriptionBuilder.h; sourceTree = "<group>"; };
E157A8EE18185425009F821D /* JSCryptoAlgorithmBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCryptoAlgorithmBuilder.cpp; sourceTree = "<group>"; };
E157A8EF18185425009F821D /* JSCryptoAlgorithmBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCryptoAlgorithmBuilder.h; sourceTree = "<group>"; };
E15A36D61104572000B7B639 /* XMLNSNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLNSNames.h; sourceTree = "<group>"; };
@@ -22196,8 +22192,6 @@
E1FE137318402A6700892F13 /* CommonCryptoUtilities.h */,
E172AF6B180F24C600FBADB9 /* CryptoAlgorithm.cpp */,
E172AF6C180F24C600FBADB9 /* CryptoAlgorithm.h */,
- E157A8EA181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp */,
- E157A8EB181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h */,
E1C657241816E69D00256CDD /* CryptoAlgorithmIdentifier.h */,
E1C657261816F9FE00256CDD /* CryptoAlgorithmParameters.h */,
E1FF8F6A180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp */,
@@ -24094,7 +24088,6 @@
E1FE137B184D21BB00892F13 /* CryptoAlgorithmAES_KW.h in Headers */,
E125F83A1824104800D84CD9 /* CryptoAlgorithmAesCbcParams.h in Headers */,
E19AC3F71824E5D100349426 /* CryptoAlgorithmAesKeyGenParams.h in Headers */,
- E157A8ED181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h in Headers */,
E125F8321822F11B00D84CD9 /* CryptoAlgorithmHMAC.h in Headers */,
E19DA29C18189ADD00088BC8 /* CryptoAlgorithmHmacKeyParams.h in Headers */,
E1C6571F1816E50300256CDD /* CryptoAlgorithmHmacParams.h in Headers */,
@@ -27808,7 +27801,6 @@
E125F845182425C900D84CD9 /* CryptoAlgorithmAES_CBCMac.cpp in Sources */,
E1FE137A184D21BB00892F13 /* CryptoAlgorithmAES_KW.cpp in Sources */,
E1FE137E184D270200892F13 /* CryptoAlgorithmAES_KWMac.cpp in Sources */,
- E157A8EC181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp in Sources */,
E125F8311822F11B00D84CD9 /* CryptoAlgorithmHMAC.cpp in Sources */,
E125F8381822F1EB00D84CD9 /* CryptoAlgorithmHMACMac.cpp in Sources */,
E1FF8F6C180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp in Sources */,
Modified: trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.cpp (205940 => 205941)
--- trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.cpp 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.cpp 2016-09-15 00:19:12 UTC (rev 205941)
@@ -48,11 +48,6 @@
{
}
-std::unique_ptr<CryptoAlgorithmDescriptionBuilder> JSCryptoAlgorithmBuilder::createEmptyClone() const
-{
- return std::make_unique<JSCryptoAlgorithmBuilder>(m_exec);
-}
-
void JSCryptoAlgorithmBuilder::add(const char* key, unsigned value)
{
VM& vm = m_exec->vm();
@@ -75,12 +70,11 @@
m_dictionary->putDirect(vm, identifier, arrayView->wrap(m_exec, vm.entryScope->globalObject()));
}
-void JSCryptoAlgorithmBuilder::add(const char* key, const CryptoAlgorithmDescriptionBuilder& nestedBuilder)
+void JSCryptoAlgorithmBuilder::add(const char* key, const JSCryptoAlgorithmBuilder& nestedBuilder)
{
VM& vm = m_exec->vm();
Identifier identifier = Identifier::fromString(&vm, key);
- const JSCryptoAlgorithmBuilder& jsBuilder = static_cast<const JSCryptoAlgorithmBuilder&>(nestedBuilder);
- m_dictionary->putDirect(vm, identifier, jsBuilder.result());
+ m_dictionary->putDirect(vm, identifier, nestedBuilder.result());
}
} // namespace WebCore
Modified: trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.h (205940 => 205941)
--- trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.h 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.h 2016-09-15 00:19:12 UTC (rev 205941)
@@ -26,7 +26,10 @@
#ifndef JSCryptoAlgorithmBuilder_h
#define JSCryptoAlgorithmBuilder_h
-#include "CryptoAlgorithmDescriptionBuilder.h"
+#include <wtf/Forward.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
#if ENABLE(SUBTLE_CRYPTO)
@@ -37,7 +40,8 @@
namespace WebCore {
-class JSCryptoAlgorithmBuilder final : public CryptoAlgorithmDescriptionBuilder {
+class JSCryptoAlgorithmBuilder {
+ WTF_MAKE_NONCOPYABLE(JSCryptoAlgorithmBuilder);
public:
JSCryptoAlgorithmBuilder(JSC::ExecState*);
virtual ~JSCryptoAlgorithmBuilder();
@@ -44,13 +48,11 @@
JSC::JSObject* result() const { return m_dictionary; }
- std::unique_ptr<CryptoAlgorithmDescriptionBuilder> createEmptyClone() const override;
+ void add(const char*, unsigned);
+ void add(const char*, const String&);
+ void add(const char*, const Vector<uint8_t>&);
+ void add(const char*, const JSCryptoAlgorithmBuilder&);
- void add(const char*, unsigned) override;
- void add(const char*, const String&) override;
- void add(const char*, const Vector<uint8_t>&) override;
- void add(const char*, const CryptoAlgorithmDescriptionBuilder&) override;
-
private:
JSC::ExecState* m_exec;
JSC::JSObject* m_dictionary;
Modified: trunk/Source/WebCore/bindings/js/JSCryptoKeyCustom.cpp (205940 => 205941)
--- trunk/Source/WebCore/bindings/js/JSCryptoKeyCustom.cpp 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/bindings/js/JSCryptoKeyCustom.cpp 2016-09-15 00:19:12 UTC (rev 205941)
@@ -28,7 +28,11 @@
#if ENABLE(SUBTLE_CRYPTO)
+#include "CryptoKeyAES.h"
+#include "CryptoKeyHMAC.h"
+#include "CryptoKeyRSA.h"
#include "JSCryptoAlgorithmBuilder.h"
+#include <heap/HeapInlines.h>
#include <runtime/JSCJSValueInlines.h>
using namespace JSC;
@@ -37,12 +41,51 @@
JSValue JSCryptoKey::algorithm(JSC::ExecState& state) const
{
+ if (m_algorithm)
+ return m_algorithm.get();
+
JSCryptoAlgorithmBuilder builder(&state);
- wrapped().buildAlgorithmDescription(builder);
- return builder.result();
+
+ std::unique_ptr<KeyAlgorithm> algorithm = wrapped().buildAlgorithm();
+ switch (algorithm->keyAlgorithmClass()) {
+ case KeyAlgorithmClass::AES: {
+ auto& aesAlgorithm = downcast<AesKeyAlgorithm>(*algorithm);
+ builder.add("name", aesAlgorithm.name());
+ builder.add("length", aesAlgorithm.length());
+ break;
+ }
+ case KeyAlgorithmClass::HMAC: {
+ auto& hmacAlgorithm = downcast<HmacKeyAlgorithm>(*algorithm);
+ builder.add("name", hmacAlgorithm.name());
+ JSCryptoAlgorithmBuilder hmacHash(&state);
+ hmacHash.add("name", hmacAlgorithm.hash());
+ builder.add("hash", hmacHash);
+ builder.add("length", hmacAlgorithm.length());
+ break;
+ }
+ case KeyAlgorithmClass::HRSA: {
+ auto& rsaAlgorithm = downcast<RsaHashedKeyAlgorithm>(*algorithm);
+ builder.add("name", rsaAlgorithm.name());
+ builder.add("modulusLength", rsaAlgorithm.modulusLength());
+ builder.add("publicExponent", rsaAlgorithm.publicExponent());
+ JSCryptoAlgorithmBuilder rsaHash(&state);
+ rsaHash.add("name", rsaAlgorithm.hash());
+ builder.add("hash", rsaHash);
+ break;
+ }
+ case KeyAlgorithmClass::RSA: {
+ auto& rsaAlgorithm = downcast<RsaKeyAlgorithm>(*algorithm);
+ builder.add("name", rsaAlgorithm.name());
+ builder.add("modulusLength", rsaAlgorithm.modulusLength());
+ builder.add("publicExponent", rsaAlgorithm.publicExponent());
+ break;
+ }
+ }
+
+ m_algorithm.set(state.vm(), this, builder.result());
+ return m_algorithm.get();
}
-
} // namespace WebCore
#endif // ENABLE(SUBTLE_CRYPTO)
Deleted: trunk/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.cpp (205940 => 205941)
--- trunk/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.cpp 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.cpp 2016-09-15 00:19:12 UTC (rev 205941)
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "CryptoAlgorithmDescriptionBuilder.h"
-
-#if ENABLE(SUBTLE_CRYPTO)
-
-namespace WebCore {
-
-CryptoAlgorithmDescriptionBuilder::CryptoAlgorithmDescriptionBuilder()
-{
-}
-
-CryptoAlgorithmDescriptionBuilder::~CryptoAlgorithmDescriptionBuilder()
-{
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(SUBTLE_CRYPTO)
Deleted: trunk/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.h (205940 => 205941)
--- trunk/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.h 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.h 2016-09-15 00:19:12 UTC (rev 205941)
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef CryptoAlgorithmDescriptionBuilder_h
-#define CryptoAlgorithmDescriptionBuilder_h
-
-#include <wtf/Forward.h>
-#include <wtf/Noncopyable.h>
-#include <wtf/Vector.h>
-
-#if ENABLE(SUBTLE_CRYPTO)
-
-namespace WebCore {
-
-class CryptoAlgorithmDescriptionBuilder {
- WTF_MAKE_NONCOPYABLE(CryptoAlgorithmDescriptionBuilder);
-public:
- CryptoAlgorithmDescriptionBuilder();
- virtual ~CryptoAlgorithmDescriptionBuilder();
-
- virtual std::unique_ptr<CryptoAlgorithmDescriptionBuilder> createEmptyClone() const = 0;
-
- virtual void add(const char*, unsigned) = 0;
- virtual void add(const char*, const String&) = 0;
- virtual void add(const char*, const Vector<uint8_t>&) = 0;
- virtual void add(const char*, const CryptoAlgorithmDescriptionBuilder&) = 0;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(SUBTLE_CRYPTO)
-#endif // CryptoAlgorithmDescriptionBuilder_h
Modified: trunk/Source/WebCore/crypto/CryptoKey.cpp (205940 => 205941)
--- trunk/Source/WebCore/crypto/CryptoKey.cpp 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/CryptoKey.cpp 2016-09-15 00:19:12 UTC (rev 205941)
@@ -28,15 +28,13 @@
#if ENABLE(SUBTLE_CRYPTO)
-#include "CryptoAlgorithmDescriptionBuilder.h"
#include "CryptoAlgorithmRegistry.h"
#include <wtf/CryptographicallyRandomNumber.h>
-#include <wtf/text/WTFString.h>
namespace WebCore {
-CryptoKey::CryptoKey(CryptoAlgorithmIdentifier algorithm, Type type, bool extractable, CryptoKeyUsage usages)
- : m_algorithm(algorithm)
+CryptoKey::CryptoKey(CryptoAlgorithmIdentifier algorithmIdentifier, Type type, bool extractable, CryptoKeyUsage usages)
+ : m_algorithmIdentifier(algorithmIdentifier)
, m_type(type)
, m_extractable(extractable)
, m_usages(usages)
@@ -47,12 +45,6 @@
{
}
-void CryptoKey::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
-{
- builder.add("name", CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_algorithm));
- // Subclasses will add other keys.
-}
-
auto CryptoKey::usages() const -> Vector<Usage>
{
// The result is ordered alphabetically.
Modified: trunk/Source/WebCore/crypto/CryptoKey.h (205940 => 205941)
--- trunk/Source/WebCore/crypto/CryptoKey.h 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/CryptoKey.h 2016-09-15 00:19:12 UTC (rev 205941)
@@ -35,6 +35,7 @@
#include <wtf/RefCounted.h>
#include <wtf/TypeCasts.h>
#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -42,11 +43,38 @@
class CryptoKeyData;
enum class CryptoKeyClass {
+ AES,
HMAC,
- AES,
RSA
};
+enum class KeyAlgorithmClass {
+ AES,
+ HMAC,
+ HRSA,
+ RSA,
+};
+
+class KeyAlgorithm {
+public:
+ virtual ~KeyAlgorithm()
+ {
+ }
+
+ virtual KeyAlgorithmClass keyAlgorithmClass() const = 0;
+
+ const String& name() const { return m_name; }
+
+protected:
+ explicit KeyAlgorithm(const String& name)
+ : m_name(name)
+ {
+ }
+
+private:
+ String m_name;
+};
+
class CryptoKey : public RefCounted<CryptoKey> {
public:
using Type = CryptoKeyType;
@@ -57,7 +85,7 @@
Type type() const;
bool extractable() const { return m_extractable; }
- virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const;
+ virtual std::unique_ptr<KeyAlgorithm> buildAlgorithm() const = 0;
// FIXME: Confusing to have CryptoKeyUsage and CryptoKey::Usage named almost the same, but be slightly different.
// CryptoKeyUsage values are bit masks so they can be combined with "or", while this is a normal enum that must
@@ -65,7 +93,7 @@
enum class Usage { Encrypt, Decrypt, Sign, Verify, DeriveKey, DeriveBits, WrapKey, UnwrapKey };
Vector<Usage> usages() const;
- CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithm; }
+ CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithmIdentifier; }
CryptoKeyUsage usagesBitmap() const { return m_usages; }
bool allows(CryptoKeyUsage usage) const { return usage == (m_usages & usage); }
@@ -74,7 +102,7 @@
static Vector<uint8_t> randomData(size_t);
private:
- CryptoAlgorithmIdentifier m_algorithm;
+ CryptoAlgorithmIdentifier m_algorithmIdentifier;
Type m_type;
bool m_extractable;
CryptoKeyUsage m_usages;
@@ -92,5 +120,10 @@
static bool isType(const WebCore::CryptoKey& key) { return key.keyClass() == WebCore::KeyClass; } \
SPECIALIZE_TYPE_TRAITS_END()
+#define SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(ToClassName, KeyAlgorithmClass) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \
+ static bool isType(const WebCore::KeyAlgorithm& algorithm) { return algorithm.keyAlgorithmClass() == WebCore::KeyAlgorithmClass; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
#endif // ENABLE(SUBTLE_CRYPTO)
#endif // CryptoKey_h
Modified: trunk/Source/WebCore/crypto/CryptoKey.idl (205940 => 205941)
--- trunk/Source/WebCore/crypto/CryptoKey.idl 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/CryptoKey.idl 2016-09-15 00:19:12 UTC (rev 205941)
@@ -47,6 +47,6 @@
] interface CryptoKey {
readonly attribute KeyType type;
readonly attribute boolean extractable;
- [Custom] readonly attribute Algorithm algorithm;
- readonly attribute sequence<KeyUsage> usages;
+ [CachedAttribute, CustomGetter] readonly attribute object algorithm;
+ [CachedAttribute] readonly attribute sequence<KeyUsage> usages;
};
Modified: trunk/Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp (205940 => 205941)
--- trunk/Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp 2016-09-15 00:19:12 UTC (rev 205941)
@@ -28,7 +28,6 @@
#if ENABLE(SUBTLE_CRYPTO)
-#include "CryptoAlgorithmDescriptionBuilder.h"
#include "CryptoAlgorithmRegistry.h"
#include "CryptoKeyDataRSAComponents.h"
#include "CryptoKeyPair.h"
@@ -81,10 +80,11 @@
return 0;
}
-void CryptoKeyRSA::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
+std::unique_ptr<KeyAlgorithm> CryptoKeyRSA::buildAlgorithm() const
{
notImplemented();
- UNUSED_PARAM(builder);
+ Vector<uint8_t> publicExponent;
+ return std::make_unique<RsaKeyAlgorithm>(emptyString(), 0, WTFMove(publicExponent));
}
std::unique_ptr<CryptoKeyData> CryptoKeyRSA::exportData() const
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp (205940 => 205941)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp 2016-09-15 00:19:12 UTC (rev 205941)
@@ -28,7 +28,6 @@
#if ENABLE(SUBTLE_CRYPTO)
-#include "CryptoAlgorithmDescriptionBuilder.h"
#include "CryptoAlgorithmRegistry.h"
#include "CryptoKeyDataOctetSequence.h"
#include <wtf/text/WTFString.h>
@@ -63,10 +62,9 @@
return adoptRef(new CryptoKeyAES(algorithm, randomData(lengthBits / 8), extractable, usages));
}
-void CryptoKeyAES::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
+std::unique_ptr<KeyAlgorithm> CryptoKeyAES::buildAlgorithm() const
{
- CryptoKey::buildAlgorithmDescription(builder);
- builder.add("length", m_key.size() * 8);
+ return std::make_unique<AesKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().nameForIdentifier(algorithmIdentifier()), m_key.size() * 8);
}
std::unique_ptr<CryptoKeyData> CryptoKeyAES::exportData() const
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h (205940 => 205941)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h 2016-09-15 00:19:12 UTC (rev 205941)
@@ -34,6 +34,22 @@
namespace WebCore {
+class AesKeyAlgorithm final : public KeyAlgorithm {
+public:
+ AesKeyAlgorithm(const String& name, size_t length)
+ : KeyAlgorithm(name)
+ , m_length(length)
+ {
+ }
+
+ KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::AES; }
+
+ size_t length() const { return m_length; }
+
+private:
+ size_t m_length;
+};
+
class CryptoKeyAES final : public CryptoKey {
public:
static Ref<CryptoKeyAES> create(CryptoAlgorithmIdentifier algorithm, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage usage)
@@ -46,7 +62,7 @@
static RefPtr<CryptoKeyAES> generate(CryptoAlgorithmIdentifier, size_t lengthBits, bool extractable, CryptoKeyUsage);
- CryptoKeyClass keyClass() const override { return CryptoKeyClass::AES; }
+ CryptoKeyClass keyClass() const final { return CryptoKeyClass::AES; }
const Vector<uint8_t>& key() const { return m_key; }
@@ -53,8 +69,8 @@
private:
CryptoKeyAES(CryptoAlgorithmIdentifier, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage);
- void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const override;
- std::unique_ptr<CryptoKeyData> exportData() const override;
+ std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+ std::unique_ptr<CryptoKeyData> exportData() const final;
Vector<uint8_t> m_key;
};
@@ -63,6 +79,8 @@
SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyAES, CryptoKeyClass::AES)
+SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(AesKeyAlgorithm, KeyAlgorithmClass::AES)
+
#endif // ENABLE(SUBTLE_CRYPTO)
#endif // CryptoKeyAES_h
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp (205940 => 205941)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp 2016-09-15 00:19:12 UTC (rev 205941)
@@ -28,7 +28,6 @@
#if ENABLE(SUBTLE_CRYPTO)
-#include "CryptoAlgorithmDescriptionBuilder.h"
#include "CryptoAlgorithmRegistry.h"
#include "CryptoKeyDataOctetSequence.h"
#include <wtf/text/WTFString.h>
@@ -67,15 +66,10 @@
return adoptRef(new CryptoKeyHMAC(randomData(lengthBytes), hash, extractable, usages));
}
-void CryptoKeyHMAC::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
+std::unique_ptr<KeyAlgorithm> CryptoKeyHMAC::buildAlgorithm() const
{
- CryptoKey::buildAlgorithmDescription(builder);
-
- auto hashDescriptionBuilder = builder.createEmptyClone();
- hashDescriptionBuilder->add("name", CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_hash));
- builder.add("hash", *hashDescriptionBuilder);
-
- builder.add("length", m_key.size());
+ return std::make_unique<HmacKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().nameForIdentifier(algorithmIdentifier()),
+ CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_hash), m_key.size());
}
std::unique_ptr<CryptoKeyData> CryptoKeyHMAC::exportData() const
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h (205940 => 205941)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h 2016-09-15 00:19:12 UTC (rev 205941)
@@ -33,6 +33,25 @@
namespace WebCore {
+class HmacKeyAlgorithm final : public KeyAlgorithm {
+public:
+ HmacKeyAlgorithm(const String& name, const String& hash, size_t length)
+ : KeyAlgorithm(name)
+ , m_hash(hash)
+ , m_length(length)
+ {
+ }
+
+ KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::HMAC; }
+
+ const String& hash() const { return m_hash; }
+ size_t length() const { return m_length; }
+
+private:
+ String m_hash;
+ size_t m_length;
+};
+
class CryptoKeyHMAC final : public CryptoKey {
public:
static Ref<CryptoKeyHMAC> create(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage)
@@ -44,7 +63,7 @@
// If lengthBytes is 0, a recommended length is used, which is the size of the associated hash function's block size.
static RefPtr<CryptoKeyHMAC> generate(size_t lengthBytes, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage);
- CryptoKeyClass keyClass() const override { return CryptoKeyClass::HMAC; }
+ CryptoKeyClass keyClass() const final { return CryptoKeyClass::HMAC; }
const Vector<uint8_t>& key() const { return m_key; }
@@ -53,8 +72,8 @@
private:
CryptoKeyHMAC(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage);
- void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const override;
- std::unique_ptr<CryptoKeyData> exportData() const override;
+ std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+ std::unique_ptr<CryptoKeyData> exportData() const final;
CryptoAlgorithmIdentifier m_hash;
Vector<uint8_t> m_key;
@@ -64,5 +83,7 @@
SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyHMAC, CryptoKeyClass::HMAC)
+SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(HmacKeyAlgorithm, KeyAlgorithmClass::HMAC)
+
#endif // ENABLE(SUBTLE_CRYPTO)
#endif // CryptoKeyHMAC_h
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h (205940 => 205941)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h 2016-09-15 00:19:12 UTC (rev 205941)
@@ -47,6 +47,41 @@
class CryptoKeyPair;
class PromiseWrapper;
+class RsaKeyAlgorithm : public KeyAlgorithm {
+public:
+ RsaKeyAlgorithm(const String& name, size_t modulusLength, Vector<uint8_t>&& publicExponent)
+ : KeyAlgorithm(name)
+ , m_modulusLength(modulusLength)
+ , m_publicExponent(WTFMove(publicExponent))
+ {
+ }
+
+ KeyAlgorithmClass keyAlgorithmClass() const override { return KeyAlgorithmClass::RSA; }
+
+ size_t modulusLength() const { return m_modulusLength; }
+ const Vector<uint8_t>& publicExponent() const { return m_publicExponent; }
+
+private:
+ size_t m_modulusLength;
+ Vector<uint8_t> m_publicExponent;
+};
+
+class RsaHashedKeyAlgorithm final : public RsaKeyAlgorithm {
+public:
+ RsaHashedKeyAlgorithm(const String& name, size_t modulusLength, Vector<uint8_t>&& publicExponent, const String& hash)
+ : RsaKeyAlgorithm(name, modulusLength, WTFMove(publicExponent))
+ , m_hash(hash)
+ {
+ }
+
+ KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::HRSA; }
+
+ const String& hash() const { return m_hash; }
+
+private:
+ String m_hash;
+};
+
class CryptoKeyRSA final : public CryptoKey {
public:
static Ref<CryptoKeyRSA> create(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
@@ -69,10 +104,10 @@
private:
CryptoKeyRSA(CryptoAlgorithmIdentifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType, PlatformRSAKey, bool extractable, CryptoKeyUsage);
- CryptoKeyClass keyClass() const override { return CryptoKeyClass::RSA; }
+ CryptoKeyClass keyClass() const final { return CryptoKeyClass::RSA; }
- void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const override;
- std::unique_ptr<CryptoKeyData> exportData() const override;
+ std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+ std::unique_ptr<CryptoKeyData> exportData() const final;
PlatformRSAKey m_platformKey;
@@ -84,5 +119,9 @@
SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyRSA, CryptoKeyClass::RSA)
+SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaKeyAlgorithm, KeyAlgorithmClass::RSA)
+
+SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaHashedKeyAlgorithm, KeyAlgorithmClass::HRSA)
+
#endif // ENABLE(SUBTLE_CRYPTO)
#endif // CryptoKeyRSA_h
Modified: trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp (205940 => 205941)
--- trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp 2016-09-15 00:16:51 UTC (rev 205940)
+++ trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp 2016-09-15 00:19:12 UTC (rev 205941)
@@ -29,7 +29,6 @@
#if ENABLE(SUBTLE_CRYPTO)
#include "CommonCryptoUtilities.h"
-#include "CryptoAlgorithmDescriptionBuilder.h"
#include "CryptoAlgorithmRegistry.h"
#include "CryptoKeyDataRSAComponents.h"
#include "CryptoKeyPair.h"
@@ -160,26 +159,22 @@
return modulus.size() * 8;
}
-void CryptoKeyRSA::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
+std::unique_ptr<KeyAlgorithm> CryptoKeyRSA::buildAlgorithm() const
{
- CryptoKey::buildAlgorithmDescription(builder);
-
+ String name = CryptoAlgorithmRegistry::singleton().nameForIdentifier(algorithmIdentifier());
Vector<uint8_t> modulus;
Vector<uint8_t> publicExponent;
CCCryptorStatus status = getPublicKeyComponents(m_platformKey, modulus, publicExponent);
if (status) {
WTFLogAlways("Couldn't get RSA key components, status %d", status);
- return;
+ publicExponent.clear();
+ return std::make_unique<RsaKeyAlgorithm>(name, 0, WTFMove(publicExponent));
}
- builder.add("modulusLength", modulus.size() * 8);
- builder.add("publicExponent", publicExponent);
-
- if (m_restrictedToSpecificHash) {
- auto hashDescriptionBuilder = builder.createEmptyClone();
- hashDescriptionBuilder->add("name", CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_hash));
- builder.add("hash", *hashDescriptionBuilder);
- }
+ size_t modulusLength = modulus.size() * 8;
+ if (m_restrictedToSpecificHash)
+ return std::make_unique<RsaHashedKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent), CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_hash));
+ return std::make_unique<RsaKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent));
}
std::unique_ptr<CryptoKeyData> CryptoKeyRSA::exportData() const