]> git.kaiwu.me - njs.git/commit
Webcrypto: fix RSA-OAEP digest being ignored for non-SHA-1 hashes
authorTomas Psota <to.psota@gmail.com>
Mon, 27 Jul 2026 13:17:16 +0000 (15:17 +0200)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 12 Aug 2026 03:36:54 +0000 (20:36 -0700)
commit757d2302e54e494f808918a829cc1ba95a194dd8
tree11900714dd0ccfb809372ab55e9dcad0100393dd
parent4f4eca5e8e522b27f3edb5bde1d084c6c23831d4
Webcrypto: fix RSA-OAEP digest being ignored for non-SHA-1 hashes

The issue was introduced in 8cd5ff2fa413 (0.7.0), which replaced
EVP_PKEY_CTX_set_rsa_oaep_md() with EVP_PKEY_CTX_set_signature_md()
to restore building with OpenSSL <= 1.0.1.

The signature digest control is not valid for encryption or decryption.
Its unchecked failure left the OAEP digest at the SHA-1 default while
MGF1 used the requested hash.  As a result, RSA-OAEP with a non-SHA-1
hash produced a non-standard digest pair that only interoperated with
njs itself.

Use the proper OAEP digest control and check all RSA context setters.
Preserve compatibility with older OpenSSL and LibreSSL versions by
supporting RSA-OAEP with SHA-1 and explicitly rejecting unsupported
digests.

Add externally generated SHA-256 and SHA-384 ciphertexts to ensure the
tests verify interoperability instead of an njs-only round trip.

Co-authored-by: Cursor <cursoragent@cursor.com>
external/njs_openssl.h
external/njs_webcrypto_module.c
external/qjs_webcrypto_module.c
test/webcrypto/rsa_decoding.t.mjs
test/webcrypto/text.base64.rsa-oaep-sha256.enc [new file with mode: 0644]
test/webcrypto/text.base64.rsa-oaep-sha384.enc [new file with mode: 0644]