haikuwebkit/LayoutTests/crypto/subtle/pbkdf2-import-key-derive-hm...

40 lines
1.2 KiB
HTML
Raw Permalink Normal View History

Implement PBKDF2 in WebCrypto https://bugs.webkit.org/show_bug.cgi?id=143458 <rdar://problem/27311703> Reviewed by Brent Fulgham. LayoutTests/imported/w3c: * web-platform-tests/WebCryptoAPI/derive_bits_keys/pbkdf2.worker-expected.txt: * web-platform-tests/WebCryptoAPI/derive_bits_keys/test_pbkdf2-expected.txt: * web-platform-tests/WebCryptoAPI/import_export/symmetric_importKey.worker-expected.txt: * web-platform-tests/WebCryptoAPI/import_export/test_symmetric_importKey-expected.txt: Source/WebCore: This patch implements PBKDF2 according to the spec: https://www.w3.org/TR/WebCryptoAPI/#pbkdf2. Supported operations include deriveKey, deriveBits, importKey and getKeyLength. Tests: crypto/subtle/ecdh-import-key-derive-pbkdf2-key.html crypto/subtle/pbkdf2-derive-bits-malformed-parametrs.html crypto/subtle/pbkdf2-import-key-derive-bits.html crypto/subtle/pbkdf2-import-key-derive-hmac-key.html crypto/subtle/pbkdf2-import-key-malformed-parameters.html crypto/subtle/pbkdf2-import-key.html crypto/workers/subtle/pbkdf2-import-key-derive-bits.html crypto/workers/subtle/pbkdf2-import-key-derive-hmac-key.html crypto/workers/subtle/pbkdf2-import-key.html * CMakeLists.txt: * DerivedSources.make: * PlatformGTK.cmake: * PlatformMac.cmake: * WebCore.xcodeproj/project.pbxproj: * bindings/js/JSCryptoKeyCustom.cpp: (WebCore::JSCryptoKey::algorithm): Added RawKeyAlgorithm. * bindings/js/JSSubtleCryptoCustom.cpp: (WebCore::normalizeCryptoAlgorithmParameters): A bit of reordering. * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneSerializer::write): Faked implementation. * crypto/CryptoAlgorithmParameters.h: * crypto/CryptoKey.h: * crypto/algorithms/CryptoAlgorithmPBKDF2.cpp: Added. (WebCore::CryptoAlgorithmPBKDF2::create): (WebCore::CryptoAlgorithmPBKDF2::identifier): (WebCore::CryptoAlgorithmPBKDF2::deriveBits): (WebCore::CryptoAlgorithmPBKDF2::importKey): (WebCore::CryptoAlgorithmPBKDF2::getKeyLength): * crypto/algorithms/CryptoAlgorithmPBKDF2.h: Added. * crypto/gnutls/CryptoAlgorithmPBKDF2GnuTLS.cpp: Added. (WebCore::CryptoAlgorithmPBKDF2::platformDeriveBits): * crypto/keys/CryptoKeyRaw.cpp: Added. (WebCore::CryptoKeyRaw::CryptoKeyRaw): (WebCore::CryptoKeyRaw::buildAlgorithm): (WebCore::CryptoKeyRaw::exportData): * crypto/keys/CryptoKeyRaw.h: Added. (WebCore::RawKeyAlgorithm::RawKeyAlgorithm): The CryptoKey class for PBKDF2 and later on HKDF. * crypto/mac/CryptoAlgorithmPBKDF2Mac.cpp: Added. (WebCore::commonCryptoHMACAlgorithm): (WebCore::CryptoAlgorithmPBKDF2::platformDeriveBits): * crypto/mac/CryptoAlgorithmRegistryMac.cpp: (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): * crypto/parameters/CryptoAlgorithmPbkdf2Params.h: Added. * crypto/parameters/Pbkdf2Params.idl: Added. LayoutTests: * TestExpectations: Mark slow tests as slow. * crypto/subtle/derive-key-malformed-parameters.html: * crypto/subtle/ecdh-import-key-derive-pbkdf2-key-expected.txt: Added. * crypto/subtle/ecdh-import-key-derive-pbkdf2-key.html: Added. * crypto/subtle/pbkdf2-derive-bits-malformed-parametrs-expected.txt: Added. * crypto/subtle/pbkdf2-derive-bits-malformed-parametrs.html: Added. * crypto/subtle/pbkdf2-import-key-derive-bits-expected.txt: Added. * crypto/subtle/pbkdf2-import-key-derive-bits.html: Added. * crypto/subtle/pbkdf2-import-key-derive-hmac-key-expected.txt: Added. * crypto/subtle/pbkdf2-import-key-derive-hmac-key.html: Added. * crypto/subtle/pbkdf2-import-key-expected.txt: Added. * crypto/subtle/pbkdf2-import-key-malformed-parameters-expected.txt: Added. * crypto/subtle/pbkdf2-import-key-malformed-parameters.html: Added. * crypto/subtle/pbkdf2-import-key.html: Added. * crypto/workers/subtle/pbkdf2-import-key-derive-bits-expected.txt: Added. * crypto/workers/subtle/pbkdf2-import-key-derive-bits.html: Added. * crypto/workers/subtle/pbkdf2-import-key-derive-hmac-key-expected.txt: Added. * crypto/workers/subtle/pbkdf2-import-key-derive-hmac-key.html: Added. * crypto/workers/subtle/pbkdf2-import-key-expected.txt: Added. * crypto/workers/subtle/pbkdf2-import-key.html: Added. * crypto/workers/subtle/resources/pbkdf2-import-key-derive-bits.js: Added. * crypto/workers/subtle/resources/pbkdf2-import-key-derive-hmac-key.js: Added. * crypto/workers/subtle/resources/pbkdf2-import-key.js: Added. Canonical link: https://commits.webkit.org/186427@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213671 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-09 22:24:26 +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 HMAC Keys with imported PBKDF2 base key");
jsTestIsAsync = true;
var nonExtractable = false;
var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
var salt = asciiToUint8Array("jnOw99oO");
crypto.subtle.importKey("raw", rawKey, "PBKDF2", nonExtractable, ["deriveKey"]).then(function(baseKey) {
return crypto.subtle.deriveKey({name: "PBKDF2", salt: salt, iterations: 100000, hash: "sha-1"}, baseKey, {name: "hmac", hash: "sha-1"}, nonExtractable, ['sign', 'verify']);
}).then(function(result) {
derivedKey = result;
shouldBe("derivedKey.type", "'secret'");
shouldBe("derivedKey.extractable", "false");
shouldBe("derivedKey.algorithm.name", "'HMAC'");
shouldBe("derivedKey.algorithm.length", "512");
shouldBe("derivedKey.algorithm.hash.name", "'SHA-1'");
shouldBe("derivedKey.usages", "['sign', 'verify']");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>