mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-02 04:27:12 +02:00
LibWeb: Allow importing ChaCha20-Poly1305 JWK without alg
The WebCrypto specification does not require the "alg" member to be present when importing a symmetric JWK, as long as the key material itself is valid. Add tests covering JWK import without an "alg" field. This fixes the following WPT: WebCryptoAPI/import_export/ChaCha20-Poly1305_importKey
This commit is contained in:
committed by
Jelle Raaijmakers
parent
e190f3ec23
commit
4a1a15ce66
Notes:
github-actions[bot]
2026-02-06 10:34:43 +00:00
Author: https://github.com/mikiubo Commit: https://github.com/LadybirdBrowser/ladybird/commit/4a1a15ce669 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7741 Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/stelar7
@@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
|
||||
// Jwk format wants Base 64 without the typical padding at the end.
|
||||
function byteArrayToUnpaddedBase64(byteArray){
|
||||
var binaryString = "";
|
||||
for (var i=0; i<byteArray.byteLength; i++){
|
||||
binaryString += String.fromCharCode(byteArray[i]);
|
||||
}
|
||||
var base64String = btoa(binaryString);
|
||||
|
||||
return base64String.replace(/=/g, "");
|
||||
}
|
||||
|
||||
asyncTest(async done => {
|
||||
var subtle = self.crypto.subtle;
|
||||
|
||||
|
||||
var keyData = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]);
|
||||
|
||||
var jwk = {
|
||||
kty: "oct",
|
||||
k: byteArrayToUnpaddedBase64(keyData)
|
||||
// alg MISSING
|
||||
};
|
||||
|
||||
var key = await subtle.importKey(
|
||||
"jwk",
|
||||
jwk,
|
||||
{ name: "ChaCha20-Poly1305" },
|
||||
true,
|
||||
["encrypt"]
|
||||
);
|
||||
|
||||
println(key.extractable);
|
||||
println(key.algorithm.name);
|
||||
println(key.type);
|
||||
println(key.usages.join(","));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user