GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto: clear openssl error stack after en/decrypt · nodejs/node@2c32e59

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_crypto.cc
  • test/parallel
    • test-crypto-private-decrypt-gh32240.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5026,6 +5026,7 @@ template <PublicKeyCipher::Operation operation,
50265026
PublicKeyCipher::EVP_PKEY_cipher_init_t EVP_PKEY_cipher_init,
50275027
PublicKeyCipher::EVP_PKEY_cipher_t EVP_PKEY_cipher>
50285028
void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
5029+
MarkPopErrorOnReturn mark_pop_error_on_return;
50295030
Environment* env = Environment::GetCurrent(args);
50305031

50315032
unsigned int offset = 0;
@@ -5056,8 +5057,6 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
50565057

50575058
AllocatedBuffer out;
50585059

5059-
ClearErrorOnReturn clear_error_on_return;
5060-
50615060
bool r = Cipher<operation, EVP_PKEY_cipher_init, EVP_PKEY_cipher>(
50625061
env,
50635062
pkey,
Collapse file

‎test/parallel/test-crypto-private-decrypt-gh32240.js‎

Copy file name to clipboard
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
// Verify that privateDecrypt() does not leave an error on the
4+
// openssl error stack that is visible to subsequent operations.
5+
6+
const common = require('../common');
7+
if (!common.hasCrypto)
8+
common.skip('missing crypto');
9+
10+
const assert = require('assert');
11+
const {
12+
generateKeyPairSync,
13+
publicEncrypt,
14+
privateDecrypt,
15+
} = require('crypto');
16+
17+
const pair = generateKeyPairSync('rsa', { modulusLength: 512 });
18+
19+
const expected = Buffer.from('shibboleth');
20+
const encrypted = publicEncrypt(pair.publicKey, expected);
21+
22+
const pkey = pair.privateKey.export({ type: 'pkcs1', format: 'pem' });
23+
const pkeyEncrypted =
24+
pair.privateKey.export({
25+
type: 'pkcs1',
26+
format: 'pem',
27+
cipher: 'aes128',
28+
passphrase: 'secret',
29+
});
30+
31+
function decrypt(key) {
32+
const decrypted = privateDecrypt(key, encrypted);
33+
assert.deepStrictEqual(decrypted, expected);
34+
}
35+
36+
decrypt(pkey);
37+
assert.throws(() => decrypt(pkeyEncrypted), { code: 'ERR_MISSING_PASSPHRASE' });
38+
decrypt(pkey); // Should not throw.

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.