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: remove RSA-OAEP key locking · nodejs/node@f0c0fae

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/crypto
    • crypto_rsa.cc
  • test/parallel
    • test-webcrypto-rsa-shared-key.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/crypto/crypto_rsa.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_rsa.cc
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ WebCryptoCipherStatus RSA_Cipher(Environment* env,
216216
const ByteSource& in,
217217
ByteSource* out) {
218218
CHECK_NE(key_data.GetKeyType(), kKeyTypeSecret);
219-
Mutex::ScopedLock lock(key_data.mutex());
220219
const auto& m_pkey = key_data.GetAsymmetricKey();
221220
const ncrypto::Rsa::CipherParams nparams{
222221
.padding = params.padding,
Collapse file

‎test/parallel/test-webcrypto-rsa-shared-key.js‎

Copy file name to clipboard
+109Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const assert = require('assert');
8+
const {
9+
createPrivateKey,
10+
createPublicKey,
11+
privateDecrypt,
12+
publicEncrypt,
13+
} = require('crypto');
14+
const { once } = require('events');
15+
const { Worker, parentPort, workerData } = require('worker_threads');
16+
const fixtures = require('../common/fixtures');
17+
const { subtle } = globalThis.crypto;
18+
19+
const algorithm = { name: 'RSA-OAEP', hash: 'SHA-256' };
20+
const label = Buffer.from('shared RSA-OAEP key');
21+
const plaintext = Buffer.from('concurrent key reuse');
22+
23+
async function encrypt({ publicKey, publicCryptoKey }) {
24+
const operations = Array.from({ length: 4 }, () =>
25+
subtle.encrypt({ name: 'RSA-OAEP', label }, publicCryptoKey, plaintext));
26+
27+
// Exercise the synchronous API while the shared CryptoKey jobs are queued.
28+
operations.push(publicEncrypt({
29+
key: publicKey,
30+
oaepHash: 'sha256',
31+
oaepLabel: label,
32+
}, plaintext));
33+
34+
const ciphertexts = await Promise.all(operations);
35+
for (const ciphertext of ciphertexts)
36+
assert.strictEqual(ciphertext.byteLength, 256);
37+
return ciphertexts;
38+
}
39+
40+
async function decrypt({ privateKey, privateCryptoKey }, ciphertexts) {
41+
const operations = ciphertexts.map((ciphertext) =>
42+
subtle.decrypt({ name: 'RSA-OAEP', label }, privateCryptoKey, ciphertext));
43+
44+
for (const ciphertext of ciphertexts) {
45+
assert.deepStrictEqual(privateDecrypt({
46+
key: privateKey,
47+
oaepHash: 'sha256',
48+
oaepLabel: label,
49+
}, Buffer.from(ciphertext)), plaintext);
50+
}
51+
52+
for (const result of await Promise.all(operations))
53+
assert.deepStrictEqual(Buffer.from(result), plaintext);
54+
}
55+
56+
function waitForStart(barrier, phase) {
57+
parentPort.postMessage(phase);
58+
Atomics.wait(barrier, phase, 0);
59+
}
60+
61+
async function runWorker() {
62+
const barrier = new Int32Array(workerData.barrier);
63+
waitForStart(barrier, 0);
64+
const ciphertexts = await encrypt(workerData.keys);
65+
waitForStart(barrier, 1);
66+
await decrypt(workerData.keys, ciphertexts);
67+
}
68+
69+
async function runMain() {
70+
const publicKey = createPublicKey(fixtures.readKey('rsa_public_2048.pem'));
71+
const privateKey = createPrivateKey(fixtures.readKey('rsa_private_2048.pem'));
72+
const keys = {
73+
publicKey,
74+
privateKey,
75+
publicCryptoKey: publicKey.toCryptoKey(algorithm, false, ['encrypt']),
76+
privateCryptoKey: privateKey.toCryptoKey(algorithm, false, ['decrypt']),
77+
};
78+
const barrier = new Int32Array(new SharedArrayBuffer(8));
79+
const workers = Array.from({ length: 3 }, () => new Worker(__filename, {
80+
workerData: { test: 'rsa-shared-key', keys, barrier: barrier.buffer },
81+
}));
82+
const exits = workers.map((worker) => once(worker, 'exit'));
83+
84+
// Clones retain the same backing keys. Release every worker together so
85+
// their first encryption and decryption also exercise cold key state.
86+
const ready = await Promise.all(
87+
workers.map((worker) => once(worker, 'message')));
88+
for (const [phase] of ready)
89+
assert.strictEqual(phase, 0);
90+
const decryptReady = workers.map((worker) => once(worker, 'message'));
91+
Atomics.store(barrier, 0, 1);
92+
Atomics.notify(barrier, 0);
93+
const ciphertexts = await encrypt(keys);
94+
95+
for (const [phase] of await Promise.all(decryptReady))
96+
assert.strictEqual(phase, 1);
97+
Atomics.store(barrier, 1, 1);
98+
Atomics.notify(barrier, 1);
99+
await decrypt(keys, ciphertexts);
100+
101+
for (const [code] of await Promise.all(exits))
102+
assert.strictEqual(code, 0);
103+
}
104+
105+
if (workerData?.test === 'rsa-shared-key') {
106+
runWorker().then(common.mustCall());
107+
} else {
108+
runMain().then(common.mustCall());
109+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — 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.