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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.