From: Dmitry Volyntsev Date: Thu, 19 Nov 2026 01:05:29 +0000 (-0800) Subject: WebCrypto: fix HKDF and PBKDF2 key algorithm in QuickJS X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=f97490a444f27428f0364d374a68423417aea2a4;p=njs.git WebCrypto: fix HKDF and PBKDF2 key algorithm in QuickJS Previously, reading key.algorithm on an HKDF or PBKDF2 key passed a NULL hash name to JS_NewString() and crashed the process. These keys went through the HMAC branch, although they have no hash. Report only the algorithm name for them. The issue was introduced in 75ca26f8 (0.8.10). --- diff --git a/external/qjs_webcrypto_module.c b/external/qjs_webcrypto_module.c index 311e32bf..48b91bf6 100644 --- a/external/qjs_webcrypto_module.c +++ b/external/qjs_webcrypto_module.c @@ -5467,6 +5467,8 @@ qjs_webcrypto_key_algorithm(JSContext *cx, JSValueConst this_val) case QJS_ALGORITHM_ED25519: case QJS_ALGORITHM_X25519: + case QJS_ALGORITHM_PBKDF2: + case QJS_ALGORITHM_HKDF: break; case QJS_ALGORITHM_HMAC: diff --git a/test/webcrypto/key_algorithm.t.mjs b/test/webcrypto/key_algorithm.t.mjs new file mode 100644 index 00000000..0285e714 --- /dev/null +++ b/test/webcrypto/key_algorithm.t.mjs @@ -0,0 +1,30 @@ +/*--- +includes: [compatWebcrypto.js, runTsuite.js] +flags: [async] +---*/ + +async function test(params) { + let key = await crypto.subtle.importKey('raw', new Uint8Array(16), + params.name, false, + ['deriveBits']); + let algorithm = key.algorithm; + + if (algorithm.name !== params.name) { + throw Error(`unexpected algorithm: ${JSON.stringify(algorithm)}`); + } + + return 'SUCCESS'; +} + +let key_algorithm_tsuite = { + name: 'derivation key algorithm', + skip: () => !has_webcrypto(), + T: test, + tests: [ + { name: 'HKDF' }, + { name: 'PBKDF2' }, + ], +}; + +run([key_algorithm_tsuite]) +.then($DONE, $DONE);