Skip to content

Commit 6d654c4

Browse files
committed
fix(security): use ERR_get_error (oldest) for RSA empty-recovery match
The previous fixup used ERR_peek_last_error which returns the NEWEST error in OpenSSL's FIFO queue. For verify_recover failures the queue typically holds an outer wrapper error on top of the inner padding-check error, so the narrow constants from the original code (0x1C880004, low-byte 0x04) never matched and every recovery went through throwOpaqueDecryptFailure. Switch to ERR_get_error to read the OLDEST queued error — same behavior as the original code that worked, restoring the empty plaintext round-trip.
1 parent 94a77e6 commit 6d654c4

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

packages/react-native-quick-crypto/cpp/cipher/HybridRsaCipher.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ std::shared_ptr<ArrayBuffer> HybridRsaCipher::publicDecrypt(const std::shared_pt
298298
// key — anyone can perform it — so the special case does not enable a
299299
// Bleichenbacher-style oracle. The fall-through still uses the opaque
300300
// throw helper.
301-
unsigned long err = ERR_peek_last_error();
301+
//
302+
// Use ERR_get_error (oldest in the FIFO queue) to match the inner
303+
// padding-check error rather than ERR_peek_last_error which returns
304+
// the outer wrapper code that doesn't satisfy the narrow match.
305+
unsigned long err = ERR_get_error();
302306
if ((err & 0xFFFFFFF) == 0x1C880004 || (err & 0xFF) == 0x04) {
303307
ERR_clear_error();
304308
EVP_PKEY_CTX_free(ctx);

0 commit comments

Comments
 (0)