crypto: remove Argon2 KDF derivation from its job setup · nodejs/node@28a7874 · GitHub
Skip to content

Commit 28a7874

Browse files
panvaaduh95
authored andcommitted
crypto: remove Argon2 KDF derivation from its job setup
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #62863 Backport-PR-URL: #63173 Fixes: #62861 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 2ca42c8 commit 28a7874

4 files changed

Lines changed: 140 additions & 16 deletions

File tree

src/crypto/crypto_argon2.cc

Lines changed: 0 additions & 14 deletions

src/node_errors.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
5353
V(ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED, Error) \
5454
V(ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS, Error) \
5555
V(ERR_CRYPTO_INITIALIZATION_FAILED, Error) \
56-
V(ERR_CRYPTO_INVALID_ARGON2_PARAMS, TypeError) \
5756
V(ERR_CRYPTO_INVALID_AUTH_TAG, TypeError) \
5857
V(ERR_CRYPTO_INVALID_COUNTER, TypeError) \
5958
V(ERR_CRYPTO_INVALID_CURVE, TypeError) \
@@ -195,7 +194,6 @@ ERRORS_WITH_CODE(V)
195194
V(ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS, \
196195
"The selected key encoding is incompatible with the key type") \
197196
V(ERR_CRYPTO_INITIALIZATION_FAILED, "Initialization failed") \
198-
V(ERR_CRYPTO_INVALID_ARGON2_PARAMS, "Invalid Argon2 params") \
199197
V(ERR_CRYPTO_INVALID_AUTH_TAG, "Invalid authentication tag") \
200198
V(ERR_CRYPTO_INVALID_COUNTER, "Invalid counter") \
201199
V(ERR_CRYPTO_INVALID_CURVE, "Invalid EC curve name") \
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Flags: --expose-internals --no-warnings
2+
'use strict';
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const { hasOpenSSL } = require('../common/crypto');
8+
9+
if (!hasOpenSSL(3, 2))
10+
common.skip('requires OpenSSL >= 3.2');
11+
12+
// Exercises the native Argon2 job directly via internalBinding, bypassing
13+
// the JS validators, to ensure that if invalid parameters ever reach the
14+
// native layer they produce a clean error from the KDF rather than crashing,
15+
// in both sync and async modes.
16+
17+
const assert = require('node:assert');
18+
const { internalBinding } = require('internal/test/binding');
19+
const {
20+
Argon2Job,
21+
kCryptoJobAsync,
22+
kCryptoJobSync,
23+
kTypeArgon2id,
24+
} = internalBinding('crypto');
25+
26+
const pass = Buffer.from('password');
27+
const salt = Buffer.alloc(16, 0x02);
28+
const empty = Buffer.alloc(0);
29+
30+
// Parameters that OpenSSL's Argon2 KDF rejects.
31+
const badParams = [
32+
{ lanes: 0, keylen: 32, memcost: 16, iter: 1 }, // lanes < 1
33+
{ lanes: 1, keylen: 32, memcost: 0, iter: 1 }, // memcost == 0
34+
{ lanes: 1, keylen: 32, memcost: 16, iter: 0 }, // iter == 0
35+
];
36+
37+
for (const { lanes, keylen, memcost, iter } of badParams) {
38+
{
39+
const job = new Argon2Job(
40+
kCryptoJobSync, pass, salt, lanes, keylen, memcost, iter,
41+
empty, empty, kTypeArgon2id);
42+
const { 0: err, 1: result } = job.run();
43+
assert.ok(err);
44+
assert.match(err.message, /Deriving bits failed/);
45+
assert.strictEqual(result, undefined);
46+
}
47+
48+
{
49+
const job = new Argon2Job(
50+
kCryptoJobAsync, pass, salt, lanes, keylen, memcost, iter,
51+
empty, empty, kTypeArgon2id);
52+
job.ondone = common.mustCall((err, result) => {
53+
assert.ok(err);
54+
assert.match(err.message, /Deriving bits failed/);
55+
assert.strictEqual(result, undefined);
56+
});
57+
job.run();
58+
}
59+
}
Lines changed: 81 additions & 0 deletions

0 commit comments

Comments
 (0)