mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:17:44 +00:00
LibWeb: Implement SubtleCrypto.generateKey for RSA-OAEP
This patch implements and tests window.crypto.sublte.generateKey with an RSA-OAEP algorithm. In order for the types to be happy, the KeyAlgorithms objects are moved to their own .h/.cpp pair, and the new KeyAlgorithms for RSA are added there.
This commit is contained in:
parent
008c89edde
commit
a9d240c647
12 changed files with 536 additions and 81 deletions
|
@ -0,0 +1,15 @@
|
|||
generateKey with RSA-OAEP algorithm
|
||||
publicKey: [object CryptoKey]
|
||||
publicKey algorithm: {"name":"RSA-OAEP","modulusLength":512,"publicExponent":{"0":0,"1":1,"2":0},"hash":"SHA-256"}
|
||||
publicKey type: public
|
||||
publicKey extractable: true
|
||||
publicKey usages: encrypt,wrapKey
|
||||
privateKey: [object CryptoKey]
|
||||
privateKey algorithm: {"name":"RSA-OAEP","modulusLength":512,"publicExponent":{"0":0,"1":1,"2":0},"hash":"SHA-256"}
|
||||
privateKey type: private
|
||||
privateKey extractable: true
|
||||
privateKey usages: decrypt,unwrapKey
|
||||
invalid usages throw
|
||||
Error: [object DOMException]
|
||||
no usages for private key throws
|
||||
Error: [object DOMException]
|
66
Tests/LibWeb/Text/input/Crypto/SubtleCrypto-generateKey.html
Normal file
66
Tests/LibWeb/Text/input/Crypto/SubtleCrypto-generateKey.html
Normal file
|
@ -0,0 +1,66 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
function bufferToHex(buffer) {
|
||||
return [...new Uint8Array(buffer)].map(b => b.toString(16).padStart(2, "0")).join("");
|
||||
}
|
||||
|
||||
asyncTest(async done => {
|
||||
|
||||
// FIXME: Generate a key with module lengths longer than 512, when they don't take an eternity to generate.
|
||||
let algorithm = {
|
||||
name: "RSA-OAEP",
|
||||
modulusLength: 512,
|
||||
publicExponent: new Uint8Array([1, 0, 1]),
|
||||
hash: "SHA-256",
|
||||
};
|
||||
|
||||
println("generateKey with RSA-OAEP algorithm");
|
||||
var key = undefined;
|
||||
try {
|
||||
key = await window.crypto.subtle.generateKey(
|
||||
algorithm,
|
||||
true,
|
||||
["encrypt", "decrypt", "wrapKey", "unwrapKey"]
|
||||
);
|
||||
} catch (e) {
|
||||
println(`FAIL: ${e}`);
|
||||
}
|
||||
|
||||
// FIXME: Report bugs to Chrome/Firefox about the order of properties on algorithm not matching us/Safari
|
||||
println(`publicKey: ${key.publicKey}`);
|
||||
println(`publicKey algorithm: ${JSON.stringify(key.publicKey.algorithm)}`);
|
||||
println(`publicKey type: ${key.publicKey.type}`);
|
||||
println(`publicKey extractable: ${key.publicKey.extractable}`);
|
||||
println(`publicKey usages: ${key.publicKey.usages}`);
|
||||
|
||||
println(`privateKey: ${key.privateKey}`);
|
||||
println(`privateKey algorithm: ${JSON.stringify(key.privateKey.algorithm)}`);
|
||||
println(`privateKey type: ${key.privateKey.type}`);
|
||||
println(`privateKey extractable: ${key.privateKey.extractable}`);
|
||||
println(`privateKey usages: ${key.privateKey.usages}`);
|
||||
|
||||
println("invalid usages throw");
|
||||
try {
|
||||
const key2 = await window.crypto.subtle.generateKey(
|
||||
algorithm,
|
||||
true,
|
||||
["encrypt", "decrypt", "wrapKey", "unwrapKey", "sign"]
|
||||
);
|
||||
} catch (e) {
|
||||
println(`Error: ${e}`);
|
||||
}
|
||||
|
||||
println("no usages for private key throws");
|
||||
try {
|
||||
const key3 = await window.crypto.subtle.generateKey(
|
||||
algorithm,
|
||||
true,
|
||||
["encrypt", "wrapKey"]
|
||||
);
|
||||
} catch (e) {
|
||||
println(`Error: ${e}`);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue