Skip to content

Commit

Permalink
crypto: fix DiffieHellman generator validation
Browse files Browse the repository at this point in the history
PR-URL: #38311
Fixes: #38302
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
eladkishon authored and targos committed Apr 29, 2021
1 parent 5b393d9 commit 7354479
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/crypto/diffiehellman.js
Expand Up @@ -122,9 +122,9 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
generator = DH_GENERATOR;
} else if (typeof generator === 'number') {
validateInt32(generator, 'generator');
} else if (generator !== true) {
} else if (typeof generator === 'string') {
generator = toBuf(generator, genEncoding);
} else {
} else if (!isArrayBufferView(generator) && !isAnyArrayBuffer(generator)) {
throw new ERR_INVALID_ARG_TYPE(
'generator',
['number', 'string', 'ArrayBuffer', 'Buffer', 'TypedArray', 'DataView'],
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-crypto-dh.js
Expand Up @@ -495,3 +495,7 @@ assert.throws(
code: 'ERR_INVALID_ARG_TYPE'
}
);
[true, Symbol(), {}, () => {}, []].forEach((generator) => assert.throws(
() => crypto.createDiffieHellman('', 'base64', generator),
{ code: 'ERR_INVALID_ARG_TYPE' }
));

0 comments on commit 7354479

Please sign in to comment.