mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
crypto: validate the limit of PBKDF2 iterations
Reject iteration counts outside of OpenSSL supported range Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65704 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
1 parent
cd5a7611e9
commit
e44669bb7d
3 files changed
+32
No files matched your search
@@ -16,6 +16,7 @@ const {
|
||||
kEmptyObject,
|
||||
} = require('internal/util');
|
||||
const {
|
||||
isInt32,
|
||||
isUint32,
|
||||
} = require('internal/validators');
|
||||
const {
|
||||
@@ -513,6 +514,11 @@ converters.Pbkdf2Params = createDictionaryConverter(
|
||||
validator: (V, dict) => {
|
||||
if (V === 0)
|
||||
throw lazyDOMException('iterations cannot be zero', 'OperationError');
|
||||
if (!isInt32(V)) {
|
||||
throw lazyDOMException(
|
||||
'iterations exceeds the implementation limit',
|
||||
'NotSupportedError');
|
||||
}
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
|
||||
@@ -124,6 +124,9 @@ export const vectors = {
|
||||
[true,
|
||||
{ name: 'PBKDF2', hash: 'SHA-256', salt: Buffer.alloc(0), iterations: 1 },
|
||||
{ name: 'HMAC', hash: 'SHA-256' }],
|
||||
[false,
|
||||
{ name: 'PBKDF2', hash: 'SHA-256', salt: Buffer.alloc(0), iterations: 2 ** 31 },
|
||||
{ name: 'AES-CBC', length: 128 }],
|
||||
[false,
|
||||
{ name: 'PBKDF2', hash: 'SHA-256', salt: Buffer.alloc(0), iterations: 1 },
|
||||
'HKDF'],
|
||||
@@ -183,6 +186,7 @@ export const vectors = {
|
||||
[true, { name: 'PBKDF2', hash: 'SHA-256', salt: Buffer.alloc(0), iterations: 1 }, 8],
|
||||
[true, { name: 'PBKDF2', hash: 'SHA-256', salt: Buffer.alloc(0), iterations: 1 }, 0],
|
||||
[false, { name: 'PBKDF2', hash: 'SHA-256', salt: Buffer.alloc(0), iterations: 0 }, 8],
|
||||
[false, { name: 'PBKDF2', hash: 'SHA-256', salt: Buffer.alloc(0), iterations: 2 ** 31 }, 8],
|
||||
[false, { name: 'PBKDF2', hash: 'SHA-256', salt: Buffer.alloc(0), iterations: 1 }, null],
|
||||
[false, { name: 'PBKDF2', hash: 'SHA-256', salt: Buffer.alloc(0), iterations: 1 }, 7],
|
||||
[false, { name: 'PBKDF2', hash: 'Invalid', salt: Buffer.alloc(0), iterations: 1 }, 8],
|
||||
|
||||
@@ -120,6 +120,28 @@ const rejectsXCurves = hasFIPS(3, 5);
|
||||
}
|
||||
}
|
||||
|
||||
// Test PBKDF2 rejects iteration counts beyond the native signed int range
|
||||
{
|
||||
async function test() {
|
||||
const key = await subtle.importKey(
|
||||
'raw',
|
||||
new Uint8Array([1]),
|
||||
'PBKDF2',
|
||||
false,
|
||||
['deriveBits']);
|
||||
await assert.rejects(
|
||||
subtle.deriveBits({
|
||||
name: 'PBKDF2',
|
||||
hash: 'SHA-256',
|
||||
salt: new Uint8Array([2]),
|
||||
iterations: 2 ** 31,
|
||||
}, key, 8),
|
||||
{ name: 'NotSupportedError' });
|
||||
}
|
||||
|
||||
test().then(common.mustCall());
|
||||
}
|
||||
|
||||
// Test X25519 and X448 bit derivation
|
||||
{
|
||||
async function test(name) {
|
||||
|
||||
Reference in new issue
Block a user