Skip to content

Commit efe19eb

Browse files
takuro-satoruyadorno
authored andcommitted
crypto: clear OpenSSL error queue after calling X509_verify()
Prior to this commit, functions accessing the OpenSSL error queue did not work properly after x509.verify() returned false. PR-URL: #45377 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent bbba42f commit efe19eb

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/crypto/crypto_x509.cc

+2
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ void X509Certificate::Verify(const FunctionCallbackInfo<Value>& args) {
468468
ASSIGN_OR_RETURN_UNWRAP(&key, args[0]);
469469
CHECK_EQ(key->Data()->GetKeyType(), kKeyTypePublic);
470470

471+
ClearErrorOnReturn clear_error_on_return;
472+
471473
args.GetReturnValue().Set(
472474
X509_verify(
473475
cert->get(),

test/parallel/test-crypto-x509.js

+5
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ const der = Buffer.from(
186186
code: 'ERR_INVALID_ARG_VALUE'
187187
});
188188

189+
// Confirm failure of X509Certificate:verify() doesn't affect other functions that use OpenSSL.
190+
assert(!x509.verify(x509.publicKey));
191+
// This call should not throw.
192+
createPrivateKey(key);
193+
189194
// X509Certificate can be cloned via MessageChannel/MessagePort
190195
const mc = new MessageChannel();
191196
mc.port1.onmessage = common.mustCall(({ data }) => {

0 commit comments

Comments
 (0)