Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: clear OpenSSL error queue after calling X509_verify() #45377

Merged
merged 4 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/crypto/crypto_x509.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ void X509Certificate::Verify(const FunctionCallbackInfo<Value>& args) {
X509_verify(
cert->get(),
key->Data()->GetAsymmetricKey().get()) > 0);
ERR_clear_error();
takuro-sato marked this conversation as resolved.
Show resolved Hide resolved
}

void X509Certificate::ToLegacy(const FunctionCallbackInfo<Value>& args) {
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-crypto-x509.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ const der = Buffer.from(
code: 'ERR_INVALID_ARG_VALUE'
});

// Confirm failure of X509Certificate:verify() doesn't affect other functions that use OpenSSL
takuro-sato marked this conversation as resolved.
Show resolved Hide resolved
assert(!x509.verify(x509.publicKey));
// It should not throw
takuro-sato marked this conversation as resolved.
Show resolved Hide resolved
createPrivateKey(key);

// X509Certificate can be cloned via MessageChannel/MessagePort
const mc = new MessageChannel();
mc.port1.onmessage = common.mustCall(({ data }) => {
Expand Down