Skip to content

Truly independent web browser

LibWeb: Accept AES JWKs without an alg member

Shannon Boothde36f3b03901
diff --git a/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs b/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs
index 729da73b305..750701f16c7 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs
@@ -3219,10 +3219,6 @@ impl AlgorithmMethods for AesCtr {
return Err(dom_error("DataError", b"Missing 'k' field"));
}
- if jwk.alg.is_none() {
- return Err(dom_error("DataError", b"Missing 'alg' field"));
- }
-
// 4. Let data be the byte sequence obtained by decoding the k field of jwk.
data = parse_jwk_symmetric_key(cx.vm(), &jwk)?;
@@ -3696,10 +3692,6 @@ impl AlgorithmMethods for AesGcm {
return Err(dom_error("DataError", b"Missing 'k' field"));
}
- if jwk.alg.is_none() {
- return Err(dom_error("DataError", b"Missing 'alg' field"));
- }
-
// 4. Let data be the byte sequence obtained by decoding the k field of jwk.
data = parse_jwk_symmetric_key(cx.vm(), &jwk)?;
@@ -4212,10 +4204,6 @@ impl AlgorithmMethods for AesKw {
// * An "alg" member SHOULD also be present to identify the algorithm intended to be used with the key,
// unless the application uses another means or convention to determine the algorithm used.
// NOTE: "k" is already checked in step 4.
- if jwk.alg.is_none() {
- return Err(dom_error("DataError", b"Missing 'alg' field"));
- }
-
// 4. Let data be the byte sequence obtained by decoding the k field of jwk.
data = parse_jwk_symmetric_key(cx.vm(), &jwk)?;
@@ -4842,10 +4830,6 @@ impl AlgorithmMethods for AesOcb {
// 3. If jwk does not meet the requirements of Section 6.4 of JSON Web Algorithms [JWA], then throw a DataError.
// NOTE: "k" is already checked in step 4.
- if jwk.alg.is_none() {
- return Err(dom_error("DataError", b"Missing 'alg' field"));
- }
-
// 4. Let data be the byte sequence obtained by decoding the k field of jwk.
data = parse_jwk_symmetric_key(cx.vm(), &jwk)?;
diff --git a/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-AES-jwk-without-alg.txt b/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-AES-jwk-without-alg.txt
new file mode 100644
index 00000000000..b67db38b1f1
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-AES-jwk-without-alg.txt
@@ -0,0 +1,5 @@
+AES-CBC: imported, exported alg A128CBC
+AES-CTR: imported, exported alg A128CTR
+AES-GCM: imported, exported alg A128GCM
+AES-KW: imported, exported alg A128KW
+AES-OCB: imported, exported alg A128OCB
diff --git a/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-AES-jwk-without-alg.html b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-AES-jwk-without-alg.html
new file mode 100644
index 00000000000..4ff21ce0b27
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-AES-jwk-without-alg.html
@@ -0,0 +1,22 @@
+<!doctype html>
+<script src="../include.js"></script>
+<script>
+ promiseTest(async () => {
+ const jwk = { kty: "oct", k: "AAAAAAAAAAAAAAAAAAAAAA" };
+ for (const [name, usages] of [
+ ["AES-CBC", ["encrypt"]],
+ ["AES-CTR", ["encrypt"]],
+ ["AES-GCM", ["encrypt"]],
+ ["AES-KW", ["wrapKey"]],
+ ["AES-OCB", ["encrypt"]],
+ ]) {
+ try {
+ const key = await crypto.subtle.importKey("jwk", jwk, name, true, usages);
+ const exported = await crypto.subtle.exportKey("jwk", key);
+ println(`${name}: imported, exported alg ${exported.alg}`);
+ } catch (error) {
+ println(`${name}: ${error.name}`);
+ }
+ }
+ });
+</script>