]> git.kaiwu.me - njs.git/commitdiff
WebCrypto: remove empty hash from HKDF and PBKDF2 keys in njs
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 19 Nov 2026 01:05:40 +0000 (17:05 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 19 Nov 2026 06:07:22 +0000 (22:07 -0800)
Previously, HKDF and PBKDF2 keys went through the HMAC branch and
key.algorithm exposed an empty hash member. These keys have no hash;
their KeyAlgorithm contains only the name.

The issue was introduced in 722e2763 (0.8.0).

external/njs_webcrypto_module.c
test/webcrypto/key_algorithm.t.mjs

index 1df19647f38f6376deea1cc3c5f013f4c2827dd0..6f0859bc2e77653e66ba5430ce0f9eb123e249ff 100644 (file)
@@ -5519,6 +5519,8 @@ njs_key_ext_algorithm(njs_vm_t *vm, njs_object_prop_t *prop, uint32_t unused,
 
     case NJS_ALGORITHM_ED25519:
     case NJS_ALGORITHM_X25519:
+    case NJS_ALGORITHM_PBKDF2:
+    case NJS_ALGORITHM_HKDF:
         break;
 
     case NJS_ALGORITHM_HMAC:
index 0285e714f87e2ac5295638fb49e9988a11f7631f..3c501c8478b26d1a423fffc50a4c228598b18853 100644 (file)
@@ -9,7 +9,9 @@ async function test(params) {
                                             ['deriveBits']);
     let algorithm = key.algorithm;
 
-    if (algorithm.name !== params.name) {
+    if (Object.keys(algorithm).join() !== 'name'
+        || algorithm.name !== params.name)
+    {
         throw Error(`unexpected algorithm: ${JSON.stringify(algorithm)}`);
     }