ladybird/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-structuredClone.html
Luke Wilde 582bc7eca5 LibWeb/Crypto: Fix CryptoKey usages being lost across in serialization
Fixes WhatsApp failing to initialize with
"InvalidAccessError: Key does not support deriving keys".
2026-05-27 02:44:46 +01:00

39 lines
1.2 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
asyncTest(async done => {
const keyMaterial = await crypto.subtle.importKey(
"raw",
new TextEncoder().encode("password"),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
);
const cloned = structuredClone(keyMaterial);
println(`clone.type=${cloned.type} extractable=${cloned.extractable}`);
println(`clone.algorithm.name=${cloned.algorithm.name}`);
println(`clone.usages=${JSON.stringify([...cloned.usages].sort())}`);
try {
const derived = await crypto.subtle.deriveKey(
{
name: "PBKDF2",
salt: new TextEncoder().encode("salt"),
iterations: 1,
hash: "SHA-256",
},
cloned,
{ name: "AES-CBC", length: 256 },
false,
["encrypt"]
);
println(`derived.algorithm.name=${derived.algorithm.name}`);
} catch (e) {
println(`deriveKey threw: ${e.name}: ${e.message}`);
}
done();
});
</script>