haikuwebkit/LayoutTests/crypto/subtle/hmac-import-jwk-key-minimum...

40 lines
953 B
HTML
Raw Permalink Normal View History

Update SubtleCrypto::importKey to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=164446 <rdar://problem/29123621> Reviewed by Brent Fulgham. LayoutTests/imported/w3c: * WebCryptoAPI/idlharness-expected.txt: Source/WebCore: This patch does following few things: 1. It updates the SubtleCrypto::importKey method to match the latest spec: https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-importKey. It also refers to the latest Editor's Draft at a certain degree: https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-importKey. 2. It implements importKey operations of following algorithms: AES-CBC, AES-KW, HMAC, RSAES-PKCS1-V1_5, RSASSA-PKCS1-V1_5, and RSA-OAEP. 3. It fixes some minor problems of SubtleCrypto::generateKey. 4. It addes move constructors for CryptoKeyAES, CryptoKeyHMAC, CryptoKeyRSA and CryptoKeyDataRSAComponents. 5. It renames HmacKeyGenParams to HmacKeyParams to serve the purpose of both HmacKeyGenParams and HmacImportParams which are essentially the same. 6. It enforces the key length in bits of CryptoKeyHMAC to be multiples of 8. 7. It also fixes the following bugs: https://bugs.webkit.org/show_bug.cgi?id=126033, https://bugs.webkit.org/show_bug.cgi?id=126034, https://bugs.webkit.org/show_bug.cgi?id=151308. P.S. We currently only support Raw and Jwk key format. Tests: crypto/subtle/aes-cbc-import-jwk-key-length-128.html crypto/subtle/aes-cbc-import-jwk-key-length-192.html crypto/subtle/aes-cbc-import-jwk-key-length-256.html crypto/subtle/aes-cbc-import-jwk-key-minimum.html crypto/subtle/aes-cbc-import-jwk-key-non-extractable.html crypto/subtle/aes-cbc-import-raw-key-length-128.html crypto/subtle/aes-cbc-import-raw-key-length-192.html crypto/subtle/aes-cbc-import-raw-key-length-256.html crypto/subtle/aes-import-key-malformed-parameters.html crypto/subtle/aes-kw-import-jwk-key-length-128.html crypto/subtle/aes-kw-import-jwk-key-length-192.html crypto/subtle/aes-kw-import-jwk-key-length-256.html crypto/subtle/aes-kw-import-raw-key.html crypto/subtle/generate-key-malformed-parameters.html crypto/subtle/hmac-import-jwk-key-minimum.html crypto/subtle/hmac-import-jwk-key-non-extractable.html crypto/subtle/hmac-import-jwk-key-sha1.html crypto/subtle/hmac-import-jwk-key-sha224.html crypto/subtle/hmac-import-jwk-key-sha256.html crypto/subtle/hmac-import-jwk-key-sha384.html crypto/subtle/hmac-import-jwk-key-sha512.html crypto/subtle/hmac-import-malformed-parameters.html crypto/subtle/hmac-import-raw-key-customized-length.html crypto/subtle/hmac-import-raw-key.html crypto/subtle/import-key-malformed-parameters.html crypto/subtle/rsa-import-key-malformed-parameters.html crypto/subtle/rsa-oaep-import-jwk-private-key.html crypto/subtle/rsa-oaep-import-jwk-public-key-sha1.html crypto/subtle/rsa-oaep-import-jwk-public-key-sha224.html crypto/subtle/rsa-oaep-import-jwk-public-key-sha256.html crypto/subtle/rsa-oaep-import-jwk-public-key-sha384.html crypto/subtle/rsa-oaep-import-jwk-public-key-sha512.html crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-private-key.html crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-leading-zero.html crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-minimum.html crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-non-extractable.html crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key.html crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-private-key.html crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha1.html crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha224.html crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha256.html crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha384.html crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha512.html crypto/workers/subtle/aes-import-jwk-key.html crypto/workers/subtle/aes-import-raw-key.html crypto/workers/subtle/hmac-import-jwk-key.html crypto/workers/subtle/hmac-import-raw-key.html crypto/workers/subtle/rsa-import-jwk-private-key.html crypto/workers/subtle/rsa-import-jwk-public-key.html * CMakeLists.txt: * DerivedSources.make: * PlatformEfl.cmake: * PlatformGTK.cmake: * PlatformMac.cmake: * WebCore.xcodeproj/project.pbxproj: * bindings/js/JSSubtleCryptoCustom.cpp: (WebCore::normalizeCryptoAlgorithmParameters): (WebCore::cryptoKeyUsageFromString): (WebCore::cryptoKeyUsagesFromJSValue): (WebCore::toKeyData): (WebCore::jsSubtleCryptoFunctionGenerateKeyPromise): (WebCore::jsSubtleCryptoFunctionImportKeyPromise): (WebCore::JSSubtleCrypto::importKey): * crypto/CryptoAlgorithm.cpp: (WebCore::CryptoAlgorithm::importKey): * crypto/CryptoAlgorithm.h: * crypto/CryptoAlgorithmParameters.h: * crypto/JsonWebKey.h: Added. * crypto/JsonWebKey.idl: Added. * crypto/RsaOtherPrimesInfo.h: Added. * crypto/RsaOtherPrimesInfo.idl: Added. * crypto/SubtleCrypto.h: * crypto/SubtleCrypto.idl: * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: (WebCore::CryptoAlgorithmAES_CBC::generateKey): (WebCore::CryptoAlgorithmAES_CBC::importKey): * crypto/algorithms/CryptoAlgorithmAES_CBC.h: * crypto/algorithms/CryptoAlgorithmAES_KW.cpp: (WebCore::CryptoAlgorithmAES_KW::generateKey): (WebCore::CryptoAlgorithmAES_KW::importKey): * crypto/algorithms/CryptoAlgorithmAES_KW.h: * crypto/algorithms/CryptoAlgorithmHMAC.cpp: (WebCore::CryptoAlgorithmHMAC::generateKey): (WebCore::CryptoAlgorithmHMAC::importKey): * crypto/algorithms/CryptoAlgorithmHMAC.h: * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp: (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey): * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h: * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp: (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey): * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h: * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp: (WebCore::CryptoAlgorithmRSA_OAEP::importKey): * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h: * crypto/keys/CryptoKeyAES.cpp: (WebCore::CryptoKeyAES::CryptoKeyAES): (WebCore::CryptoKeyAES::generate): (WebCore::CryptoKeyAES::importRaw): (WebCore::CryptoKeyAES::importJwk): * crypto/keys/CryptoKeyAES.h: * crypto/keys/CryptoKeyDataRSAComponents.cpp: (WebCore::CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents): * crypto/keys/CryptoKeyDataRSAComponents.h: * crypto/keys/CryptoKeyHMAC.cpp: (WebCore::CryptoKeyHMAC::CryptoKeyHMAC): (WebCore::CryptoKeyHMAC::generate): (WebCore::CryptoKeyHMAC::importRaw): (WebCore::CryptoKeyHMAC::importJwk): (WebCore::CryptoKeyHMAC::buildAlgorithm): * crypto/keys/CryptoKeyHMAC.h: * crypto/keys/CryptoKeyRSA.cpp: Added. (WebCore::CryptoKeyRSA::importJwk): * crypto/keys/CryptoKeyRSA.h: * crypto/parameters/CryptoAlgorithmHmacKeyParams.h: Renamed from Source/WebCore/crypto/parameters/CryptoAlgorithmHmacKeyGenParams.h. * crypto/parameters/CryptoAlgorithmRsaHashedImportParams.h: Added. * crypto/parameters/HmacKeyParams.idl: Renamed from Source/WebCore/crypto/parameters/HmacKeyGenParams.idl. * crypto/parameters/RsaHashedImportParams.idl: Added. LayoutTests: Besides adding test cases for SubtleCrypto::importKey. This patch also corrects a typo: generate-key-malformed-paramters*. * crypto/subtle/aes-cbc-import-jwk-key-length-128-expected.txt: Added. * crypto/subtle/aes-cbc-import-jwk-key-length-128.html: Added. * crypto/subtle/aes-cbc-import-jwk-key-length-192-expected.txt: Added. * crypto/subtle/aes-cbc-import-jwk-key-length-192.html: Added. * crypto/subtle/aes-cbc-import-jwk-key-length-256-expected.txt: Added. * crypto/subtle/aes-cbc-import-jwk-key-length-256.html: Added. * crypto/subtle/aes-cbc-import-jwk-key-minimum-expected.txt: Added. * crypto/subtle/aes-cbc-import-jwk-key-minimum.html: Added. * crypto/subtle/aes-cbc-import-jwk-key-non-extractable-expected.txt: Added. * crypto/subtle/aes-cbc-import-jwk-key-non-extractable.html: Added. * crypto/subtle/aes-cbc-import-raw-key-length-128-expected.txt: Added. * crypto/subtle/aes-cbc-import-raw-key-length-128.html: Added. * crypto/subtle/aes-cbc-import-raw-key-length-192-expected.txt: Added. * crypto/subtle/aes-cbc-import-raw-key-length-192.html: Added. * crypto/subtle/aes-cbc-import-raw-key-length-256-expected.txt: Added. * crypto/subtle/aes-cbc-import-raw-key-length-256.html: Added. * crypto/subtle/aes-import-key-malformed-parameters-expected.txt: Added. * crypto/subtle/aes-import-key-malformed-parameters.html: Added. * crypto/subtle/aes-kw-import-jwk-key-length-128-expected.txt: Added. * crypto/subtle/aes-kw-import-jwk-key-length-128.html: Added. * crypto/subtle/aes-kw-import-jwk-key-length-192-expected.txt: Added. * crypto/subtle/aes-kw-import-jwk-key-length-192.html: Added. * crypto/subtle/aes-kw-import-jwk-key-length-256-expected.txt: Added. * crypto/subtle/aes-kw-import-jwk-key-length-256.html: Added. * crypto/subtle/aes-kw-import-raw-key-expected.txt: Added. * crypto/subtle/aes-kw-import-raw-key.html: Added. * crypto/subtle/generate-key-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/generate-key-malformed-paramters-expected.txt. * crypto/subtle/generate-key-malformed-parameters.html: Renamed from LayoutTests/crypto/subtle/generate-key-malformed-paramters.html. * crypto/subtle/hmac-generate-key-customized-length-expected.txt: * crypto/subtle/hmac-generate-key-customized-length.html: * crypto/subtle/hmac-generate-key-malformed-parameters-expected.txt: * crypto/subtle/hmac-generate-key-malformed-parameters.html: * crypto/subtle/hmac-import-raw-key-customized-length-expected.txt: * crypto/subtle/hmac-import-raw-key-customized-length.html: * crypto/subtle/hmac-import-jwk-key-minimum-expected.txt: Added. * crypto/subtle/hmac-import-jwk-key-minimum.html: Added. * crypto/subtle/hmac-import-jwk-key-non-extractable-expected.txt: Added. * crypto/subtle/hmac-import-jwk-key-non-extractable.html: Added. * crypto/subtle/hmac-import-jwk-key-sha1-expected.txt: Added. * crypto/subtle/hmac-import-jwk-key-sha1.html: Added. * crypto/subtle/hmac-import-jwk-key-sha224-expected.txt: Added. * crypto/subtle/hmac-import-jwk-key-sha224.html: Added. * crypto/subtle/hmac-import-jwk-key-sha256-expected.txt: Added. * crypto/subtle/hmac-import-jwk-key-sha256.html: Added. * crypto/subtle/hmac-import-jwk-key-sha384-expected.txt: Added. * crypto/subtle/hmac-import-jwk-key-sha384.html: Added. * crypto/subtle/hmac-import-jwk-key-sha512-expected.txt: Added. * crypto/subtle/hmac-import-jwk-key-sha512.html: Added. * crypto/subtle/hmac-import-malformed-parameters-expected.txt: Added. * crypto/subtle/hmac-import-malformed-parameters.html: Added. * crypto/subtle/hmac-import-raw-key-customized-length-expected.txt: Added. * crypto/subtle/hmac-import-raw-key-customized-length.html: Added. * crypto/subtle/hmac-import-raw-key-expected.txt: Added. * crypto/subtle/hmac-import-raw-key.html: Added. * crypto/subtle/import-key-malformed-parameters-expected.txt: Added. * crypto/subtle/import-key-malformed-parameters.html: Added. * crypto/subtle/rsa-import-key-malformed-parameters-expected.txt: Added. * crypto/subtle/rsa-import-key-malformed-parameters.html: Added. * crypto/subtle/rsa-oaep-import-jwk-private-key-expected.txt: Added. * crypto/subtle/rsa-oaep-import-jwk-private-key.html: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha1-expected.txt: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha1.html: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha224-expected.txt: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha224.html: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha256-expected.txt: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha256.html: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha384-expected.txt: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha384.html: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha512-expected.txt: Added. * crypto/subtle/rsa-oaep-import-jwk-public-key-sha512.html: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-private-key-expected.txt: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-private-key.html: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-expected.txt: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-leading-zero-expected.txt: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-leading-zero.html: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-minimum-expected.txt: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-minimum.html: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-non-extractable-expected.txt: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-non-extractable.html: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key.html: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-private-key-expected.txt: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-private-key.html: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha1-expected.txt: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha1.html: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha224-expected.txt: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha224.html: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha256-expected.txt: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha256.html: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha384-expected.txt: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha384.html: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha512-expected.txt: Added. * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha512.html: Added. * crypto/webkitSubtle/hmac-generate-key-expected.txt: * crypto/webkitSubtle/hmac-generate-key.html: * crypto/webkitSubtle/hmac-import-jwk-expected.txt: * crypto/webkitSubtle/hmac-import-jwk.html: * crypto/webkitSubtle/hmac-postMessage-expected.txt: * crypto/webkitSubtle/hmac-postMessage.html: * crypto/webkitSubtle/hmac-sign-verify-expected.txt: * crypto/webkitSubtle/hmac-sign-verify.html: * crypto/workers/subtle/aes-import-jwk-key-expected.txt: Added. * crypto/workers/subtle/aes-import-jwk-key.html: Added. * crypto/workers/subtle/aes-import-raw-key-expected.txt: Added. * crypto/workers/subtle/aes-import-raw-key.html: Added. * crypto/workers/subtle/hmac-import-jwk-key-expected.txt: Added. * crypto/workers/subtle/hmac-import-jwk-key.html: Added. * crypto/workers/subtle/hmac-import-raw-key-expected.txt: Added. * crypto/workers/subtle/hmac-import-raw-key.html: Added. * crypto/workers/subtle/hmac-postMessage-worker-expected.txt: * crypto/workers/subtle/hmac-postMessage-worker.html: * crypto/workers/subtle/resources/aes-import-jwk-key.js: Added. * crypto/workers/subtle/resources/aes-import-raw-key.js: Added. * crypto/workers/subtle/resources/hmac-import-jwk-key.js: Added. * crypto/workers/subtle/resources/hmac-import-raw-key.js: Added. * crypto/workers/subtle/resources/hmac-postMessage-worker.js: * crypto/workers/subtle/resources/rsa-import-jwk-private-key.js: Added. * crypto/workers/subtle/resources/rsa-import-jwk-public-key.js: Added. * crypto/workers/subtle/rsa-import-jwk-private-key-expected.txt: Added. * crypto/workers/subtle/rsa-import-jwk-private-key.html: Added. * crypto/workers/subtle/rsa-import-jwk-public-key-expected.txt: Added. * crypto/workers/subtle/rsa-import-jwk-public-key.html: Added. Canonical link: https://commits.webkit.org/182271@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208548 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-10 18:36:44 +00:00
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test importing a JWK HMAC key with minimum JWK information");
jsTestIsAsync = true;
var jwkKey = {
kty: "oct",
k: "YWJjZGVmZ2gxMjM0NTY3OA",
};
var extractable = true;
debug("Importing a key...");
crypto.subtle.importKey("jwk", jwkKey, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"]).then(function(result) {
key = result;
shouldBe("key.type", "'secret'");
shouldBe("key.extractable", "true");
shouldBe("key.algorithm.name", "'HMAC'");
shouldBe("key.algorithm.length", "128");
shouldBe("key.algorithm.hash.name", "'SHA-1'");
shouldBe("key.usages", "['sign', 'verify']");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>