Skip to content

Truly independent web browser

LibWeb: Expect "sig" as the use of an HMAC JWK

Shannon Boothaa4a700b7259
diff --git a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp
index 9dadf2fcebb..26ae47287bd 100644
--- a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp
+++ b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp
@@ -8119,9 +8119,9 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> HMAC::import_key(JS::Realm& realm, Web::
return WebIDL::DataError::create("Invalid algorithm"_utf16);
}
- // 7. If usages is non-empty and the use field of jwk is present and is not "sign", then
+ // 7. If usages is non-empty and the use field of jwk is present and is not "sig", then
// throw a DataError.
- if (!usages.is_empty() && jwk.use.has_value() && jwk.use != "sign"sv)
+ if (!usages.is_empty() && jwk.use.has_value() && jwk.use != "sig"sv)
return WebIDL::DataError::create("Invalid use in JsonWebKey"_utf16);
// 8. If the key_ops field of jwk is present, and is invalid according to the requirements
diff --git a/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-HMAC-jwk-use.txt b/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-HMAC-jwk-use.txt
new file mode 100644
index 00000000000..2c835fe653c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-HMAC-jwk-use.txt
@@ -0,0 +1,2 @@
+use "sig": ok
+use "sign": DataError
diff --git a/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-HMAC-jwk-use.html b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-HMAC-jwk-use.html
new file mode 100644
index 00000000000..e138afe3fb1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-HMAC-jwk-use.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<script src="../include.js"></script>
+<script>
+ promiseTest(async () => {
+ async function check(label, promise) {
+ try {
+ await promise;
+ println(`${label}: ok`);
+ } catch (error) {
+ println(`${label}: ${error.name}`);
+ }
+ }
+
+ const jwk = use => ({ kty: "oct", k: "AAAAAAAAAAAAAAAAAAAAAA", alg: "HS256", use });
+ const algorithm = { name: "HMAC", hash: "SHA-256" };
+
+ await check('use "sig"', crypto.subtle.importKey("jwk", jwk("sig"), algorithm, false, ["sign"]));
+ await check('use "sign"', crypto.subtle.importKey("jwk", jwk("sign"), algorithm, false, ["sign"]));
+ });
+</script>