LibWeb: Implement most of ECDSA verify for SubtleCrypto

This commit is contained in:
stelar7 2024-03-27 02:35:17 +01:00 committed by Andrew Kaster
commit ae230c9150
Notes: sideshowbarker 2024-07-16 20:21:48 +09:00
5 changed files with 156 additions and 1 deletions

View file

@ -0,0 +1,45 @@
<script src="../include.js"></script>
<script>
asyncTest(async done => {
const encoder = new TextEncoder();
const message = "Hello friends";
const encoded_message = encoder.encode(message);
const key_algorithm = {
name: "ECDSA",
namedCurve: "P-384",
};
const extractable = true;
const usages = ["sign", "verify"];
const key = await window.crypto.subtle.generateKey(key_algorithm, extractable, usages);
console.log(key.publicKey);
const signature_algorithm = {
name: "ECDSA",
hash: { name: "SHA-384" },
};
const signature = await window.crypto.subtle.sign(
signature_algorithm,
key.privateKey,
encoded_message
);
let result = await window.crypto.subtle.verify(
signature_algorithm,
key.publicKey,
signature,
encoded_message
);
println(`FIXME: This will fail as we dont support ECDSA sign()`);
if (result) {
println(`Verified OK`);
} else {
println(`FAIL: Verification not ok`);
}
done();
});
</script>