Skip to content

Truly independent web browser

LibWeb: Add a test for out-of-range RSA-PSS salt lengths

Andreas Klingc64db8938099
diff --git a/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-RSA-PSS-salt-length-range.txt b/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-RSA-PSS-salt-length-range.txt
new file mode 100644
index 00000000000..4b5df2b660a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-RSA-PSS-salt-length-range.txt
@@ -0,0 +1,12 @@
+verify saltLength 32: true
+verify saltLength 31: false
+verify saltLength 1000: false
+verify saltLength 2147483647: false
+verify saltLength 2147483648: OperationError
+verify saltLength 4294967292: true
+verify saltLength 4294967294: true
+verify saltLength 4294967295: true
+sign saltLength 1000: OperationError
+sign saltLength 2147483648: OperationError
+sign saltLength 4294967294: ok
+sign saltLength 4294967295: ok
diff --git a/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-RSA-PSS-salt-length-range.html b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-RSA-PSS-salt-length-range.html
new file mode 100644
index 00000000000..c2adb4eef85
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-RSA-PSS-salt-length-range.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ promiseTest(async () => {
+ const message = new TextEncoder().encode("Hello friends");
+ const { privateKey, publicKey } = await crypto.subtle.generateKey(
+ { name: "RSA-PSS", modulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" },
+ false,
+ ["sign", "verify"]
+ );
+
+ const signature = await crypto.subtle.sign({ name: "RSA-PSS", saltLength: 32 }, privateKey, message);
+
+ for (const saltLength of [32, 31, 1000, 2147483647, 2147483648, 4294967292, 4294967294, 4294967295]) {
+ try {
+ const result = await crypto.subtle.verify({ name: "RSA-PSS", saltLength }, publicKey, signature, message);
+ println(`verify saltLength ${saltLength}: ${result}`);
+ } catch (error) {
+ println(`verify saltLength ${saltLength}: ${error.name}`);
+ }
+ }
+
+ for (const saltLength of [1000, 2147483648, 4294967294, 4294967295]) {
+ try {
+ await crypto.subtle.sign({ name: "RSA-PSS", saltLength }, privateKey, message);
+ println(`sign saltLength ${saltLength}: ok`);
+ } catch (error) {
+ println(`sign saltLength ${saltLength}: ${error.name}`);
+ }
+ }
+ });
+</script>