haikuwebkit/LayoutTests/crypto/subtle/ecdh-import-key-derive-aes-...

54 lines
1.6 KiB
HTML
Raw Permalink Normal View History

[WebCrypto] Implement SubtleCrypto::DeriveKey method https://bugs.webkit.org/show_bug.cgi?id=169386 <rdar://problem/23789585> Reviewed by Brent Fulgham. Source/WebCore: This patch does following few things: 1. It implements SubtleCrypto::DeriveKey method according to the spec: https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-deriveKey. 2. It implements getKeyLength operations for AES-CBC, AES-KW, AES-CFB, AES-GCM, and HMAC, which is needed by the SubtleCrypto::DeriveKey method. 3. It enables ECDH DeriveKey operation. 4. It replaces unigned long with size_t in all the crypto codes. Tests: crypto/subtle/derive-key-malformed-parameters.html crypto/subtle/ecdh-import-key-derive-aes-key.html crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html crypto/subtle/unwrap-key-malformed-parameters.html crypto/subtle/wrap-key-malformed-parameters.html crypto/workers/subtle/ecdh-import-key-derive-key.html * CMakeLists.txt: * DerivedSources.make: * WebCore.xcodeproj/project.pbxproj: * bindings/js/JSSubtleCryptoCustom.cpp: (WebCore::normalizeCryptoAlgorithmParameters): (WebCore::jsSubtleCryptoFunctionEncryptPromise): (WebCore::jsSubtleCryptoFunctionDecryptPromise): (WebCore::jsSubtleCryptoFunctionSignPromise): (WebCore::jsSubtleCryptoFunctionVerifyPromise): (WebCore::jsSubtleCryptoFunctionDigestPromise): (WebCore::jsSubtleCryptoFunctionDeriveKeyPromise): (WebCore::jsSubtleCryptoFunctionDeriveBitsPromise): Remove unnecessary return statement from callbacks. * crypto/CryptoAlgorithm.cpp: (WebCore::CryptoAlgorithm::deriveBits): (WebCore::CryptoAlgorithm::getKeyLength): * crypto/CryptoAlgorithm.h: * crypto/CryptoAlgorithmParameters.h: * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: (WebCore::CryptoAlgorithmAES_CBC::generateKey): (WebCore::CryptoAlgorithmAES_CBC::getKeyLength): * crypto/algorithms/CryptoAlgorithmAES_CBC.h: * crypto/algorithms/CryptoAlgorithmAES_CFB.cpp: (WebCore::CryptoAlgorithmAES_CFB::generateKey): (WebCore::CryptoAlgorithmAES_CFB::getKeyLength): * crypto/algorithms/CryptoAlgorithmAES_CFB.h: * crypto/algorithms/CryptoAlgorithmAES_GCM.cpp: (WebCore::CryptoAlgorithmAES_GCM::generateKey): (WebCore::CryptoAlgorithmAES_GCM::getKeyLength): * crypto/algorithms/CryptoAlgorithmAES_GCM.h: * crypto/algorithms/CryptoAlgorithmAES_KW.cpp: (WebCore::CryptoAlgorithmAES_KW::generateKey): (WebCore::CryptoAlgorithmAES_KW::getKeyLength): * crypto/algorithms/CryptoAlgorithmAES_KW.h: * crypto/algorithms/CryptoAlgorithmECDH.cpp: (WebCore::CryptoAlgorithmECDH::deriveBits): * crypto/algorithms/CryptoAlgorithmECDH.h: * crypto/algorithms/CryptoAlgorithmHMAC.cpp: (WebCore::CryptoAlgorithmHMAC::getKeyLength): * crypto/algorithms/CryptoAlgorithmHMAC.h: * crypto/keys/CryptoKeyAES.cpp: (WebCore::CryptoKeyAES::getKeyLength): * crypto/keys/CryptoKeyAES.h: * crypto/keys/CryptoKeyHMAC.cpp: (WebCore::getKeyLengthFromHash): (WebCore::CryptoKeyHMAC::generate): (WebCore::CryptoKeyHMAC::getKeyLength): * crypto/keys/CryptoKeyHMAC.h: * crypto/mac/CryptoAlgorithmECDHMac.cpp: (WebCore::CryptoAlgorithmECDH::platformDeriveBits): * crypto/parameters/AesKeyParams.idl: Renamed from Source/WebCore/crypto/parameters/AesKeyGenParams.idl. * crypto/parameters/CryptoAlgorithmAesKeyParams.h: Renamed from Source/WebCore/crypto/parameters/CryptoAlgorithmAesKeyGenParams.h. Rename AesKeyGenParams to AesKeyParams to represent a unified dictionary for AesKeyGenParams and AesDerivedKeyParams. * crypto/parameters/CryptoAlgorithmHmacKeyParams.h: * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h: LayoutTests: * crypto/subtle/aes-generate-key-malformed-parameters-expected.txt: * crypto/subtle/derive-key-malformed-parameters-expected.txt: Added. * crypto/subtle/derive-key-malformed-parameters.html: Added. * crypto/subtle/deriveKey-malformed-parameters-expected.txt: Removed. * crypto/subtle/deriveKey-malformed-parameters.html: Removed. * crypto/subtle/ecdh-import-key-derive-aes-key-expected.txt: Added. * crypto/subtle/ecdh-import-key-derive-aes-key.html: Added. * crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length-expected.txt: Added. * crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html: Added. * crypto/subtle/unwrap-key-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters-expected.txt. * crypto/subtle/unwrap-key-malformed-parameters.html: Renamed from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters.html. * crypto/subtle/wrap-key-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/wrapKey-malformed-parameters-expected.txt. * crypto/subtle/wrap-key-malformed-parameters.html: Renamed from LayoutTests/crypto/subtle/wrapKey-malformed-parameters.html. A bit renaming. * crypto/workers/subtle/ecdh-import-key-derive-key-expected.txt: Added. * crypto/workers/subtle/ecdh-import-key-derive-key.html: Added. * crypto/workers/subtle/resources/ecdh-import-key-derive-key.js: Added. Canonical link: https://commits.webkit.org/186385@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213628 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-09 05:50:31 +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 deriving AES Keys with imported ECDH base key");
jsTestIsAsync = true;
var extractable = true;
var jwkPrivateKey = {
kty: "EC",
crv: "P-256",
x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA",
y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI",
d: "ppxBSov3N8_AUcisAuvmLV4yE8e_L_BLE8bZb9Z1Xjg",
};
var jwkPublicKey = {
kty: "EC",
crv: "P-256",
x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA",
y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI",
};
crypto.subtle.importKey("jwk", jwkPrivateKey, { name: "ECDH", namedCurve: "P-256" }, extractable, ["deriveKey"]).then(function(result) {
privateKey = result;
return crypto.subtle.importKey("jwk", jwkPublicKey, { name: "ECDH", namedCurve: "P-256" }, extractable, [ ]);
}).then(function(result) {
publicKey = result;
return crypto.subtle.deriveKey({ name:"ECDH", public:publicKey }, privateKey, {name: "aes-cbc", length: 128}, extractable, ['decrypt', 'encrypt', 'unwrapKey', 'wrapKey']);
}).then(function(result) {
derivedKey = result;
shouldBe("derivedKey.type", "'secret'");
shouldBe("derivedKey.extractable", "true");
shouldBe("derivedKey.algorithm.name", "'AES-CBC'");
shouldBe("derivedKey.algorithm.length", "128");
shouldBe("derivedKey.usages", "['decrypt', 'encrypt', 'unwrapKey', 'wrapKey']");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>