Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7611fc1

Browse filesBrowse files
panvaaduh95
authored andcommitted
crypto: fix output of privateDecrypt with zero-length data
closes #57553 closes #57572 closes #57558 PR-URL: #57575 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent ad5dcc5 commit 7611fc1
Copy full SHA for 7611fc1

File tree

Expand file treeCollapse file tree

2 files changed

+57
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+57
-1
lines changed
Open diff view settings
Collapse file

‎deps/ncrypto/ncrypto.cc‎

Copy file name to clipboardExpand all lines: deps/ncrypto/ncrypto.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Buffer<void> DataPointer::release() {
215215
DataPointer DataPointer::resize(size_t len) {
216216
size_t actual_len = std::min(len_, len);
217217
auto buf = release();
218-
if (actual_len == len_) return DataPointer(buf);
218+
if (actual_len == len_) return DataPointer(buf.data, actual_len);
219219
buf.data = OPENSSL_realloc(buf.data, actual_len);
220220
buf.len = actual_len;
221221
return DataPointer(buf);
Collapse file
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const fixtures = require('../common/fixtures');
8+
const assert = require('assert');
9+
const crypto = require('crypto');
10+
11+
const { subtle } = globalThis.crypto;
12+
13+
// Regression test for https://github.com/nodejs/node/issues/57553.
14+
{
15+
const privateKey = crypto.createPrivateKey(fixtures.readKey('rsa_private.pem', 'ascii'));
16+
const publicKey = crypto.createPublicKey(fixtures.readKey('rsa_public.pem', 'ascii'));
17+
18+
const data = Buffer.alloc(0);
19+
{
20+
21+
const ciphertext = crypto.publicEncrypt({
22+
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
23+
key: publicKey,
24+
}, data);
25+
26+
const plaintext = crypto.privateDecrypt({
27+
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
28+
key: privateKey
29+
}, ciphertext);
30+
31+
assert.deepStrictEqual(plaintext, data);
32+
}
33+
34+
{
35+
const ciphertext = crypto.publicEncrypt(publicKey, data);
36+
const plaintext = crypto.privateDecrypt(privateKey, ciphertext);
37+
38+
assert.deepStrictEqual(plaintext, data);
39+
}
40+
41+
{
42+
(async () => {
43+
const pkcs8 = privateKey.export({ format: 'der', type: 'pkcs8' });
44+
const spki = publicKey.export({ format: 'der', type: 'spki' });
45+
46+
const kp = {
47+
privateKey: await subtle.importKey('pkcs8', pkcs8, { name: 'RSA-OAEP', hash: 'SHA-1' }, false, ['decrypt']),
48+
publicKey: await subtle.importKey('spki', spki, { name: 'RSA-OAEP', hash: 'SHA-1' }, false, ['encrypt']),
49+
};
50+
51+
const ciphertext = await subtle.encrypt('RSA-OAEP', kp.publicKey, data);
52+
const plaintext = await subtle.decrypt('RSA-OAEP', kp.privateKey, ciphertext);
53+
assert.deepStrictEqual(plaintext, data.buffer);
54+
})().then(common.mustCall());
55+
}
56+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.