File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -453,6 +453,8 @@ void X509Certificate::CheckPrivateKey(const FunctionCallbackInfo<Value>& args) {
453453 ASSIGN_OR_RETURN_UNWRAP (&key, args[0 ]);
454454 CHECK_EQ (key->Data ()->GetKeyType (), kKeyTypePrivate );
455455
456+ ClearErrorOnReturn clear_error_on_return;
457+
456458 args.GetReturnValue ().Set (
457459 X509_check_private_key (
458460 cert->get (),
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ if (!common.hasCrypto)
88const {
99 X509Certificate,
1010 createPrivateKey,
11+ generateKeyPairSync,
1112} = require ( 'crypto' ) ;
1213
1314const {
@@ -187,10 +188,18 @@ const der = Buffer.from(
187188 code : 'ERR_INVALID_ARG_VALUE'
188189 } ) ;
189190
190- // Confirm failure of X509Certificate:verify() doesn't affect other functions that use OpenSSL.
191- assert ( ! x509 . verify ( x509 . publicKey ) ) ;
192- // This call should not throw.
193- createPrivateKey ( key ) ;
191+ {
192+ // https://github.com/nodejs/node/issues/45377
193+ // https://github.com/nodejs/node/issues/45485
194+ // Confirm failures of X509Certificate:verify() and X509Certificate:CheckPrivateKey()
195+ // do not affect other functions that use OpenSSL.
196+ // Subsequent calls to e.g. createPrivateKey should not throw.
197+ const keyPair = generateKeyPairSync ( 'ed25519' ) ;
198+ assert ( ! x509 . verify ( keyPair . publicKey ) ) ;
199+ createPrivateKey ( key ) ;
200+ assert ( ! x509 . checkPrivateKey ( keyPair . privateKey ) ) ;
201+ createPrivateKey ( key ) ;
202+ }
194203
195204 // X509Certificate can be cloned via MessageChannel/MessagePort
196205 const mc = new MessageChannel ( ) ;
You can’t perform that action at this time.
0 commit comments