-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: remove webcrypto HKDF and PBKDF2 default-applied lengths #44945
Merged
nodejs-github-bot
merged 1 commit into
nodejs:main
from
panva:fix-webcrypto-remove-pbkdf2-default
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -2,7 +2,6 @@ | |||
|
||||
const { | ||||
FunctionPrototypeCall, | ||||
Promise, | ||||
} = primordials; | ||||
|
||||
const { Buffer } = require('buffer'); | ||||
|
@@ -18,7 +17,6 @@ const { | |||
validateInt32, | ||||
validateInteger, | ||||
validateString, | ||||
validateUint32, | ||||
} = require('internal/validators'); | ||||
|
||||
const { ERR_MISSING_OPTION } = require('internal/errors').codes; | ||||
|
@@ -32,6 +30,7 @@ const { | |||
|
||||
const { | ||||
lazyDOMException, | ||||
promisify, | ||||
} = require('internal/util'); | ||||
|
||||
function pbkdf2(password, salt, iterations, keylen, digest, callback) { | ||||
|
@@ -100,6 +99,7 @@ function check(password, salt, iterations, keylen, digest) { | |||
return { password, salt, iterations, keylen, digest }; | ||||
} | ||||
|
||||
const pbkdf2Promise = promisify(pbkdf2); | ||||
async function pbkdf2DeriveBits(algorithm, baseKey, length) { | ||||
const { iterations } = algorithm; | ||||
let { hash } = algorithm; | ||||
|
@@ -116,27 +116,26 @@ async function pbkdf2DeriveBits(algorithm, baseKey, length) { | |||
|
||||
const raw = baseKey[kKeyObject].export(); | ||||
|
||||
let byteLength = 64; // the default | ||||
if (length !== undefined) { | ||||
if (length === 0) | ||||
throw lazyDOMException('length cannot be zero', 'OperationError'); | ||||
if (length === null) | ||||
throw lazyDOMException('length cannot be null', 'OperationError'); | ||||
validateUint32(length, 'length'); | ||||
if (length % 8) { | ||||
throw lazyDOMException( | ||||
'length must be a multiple of 8', | ||||
'OperationError'); | ||||
} | ||||
byteLength = length / 8; | ||||
if (length === 0) | ||||
throw lazyDOMException('length cannot be zero', 'OperationError'); | ||||
if (length === null) | ||||
throw lazyDOMException('length cannot be null', 'OperationError'); | ||||
if (length % 8) { | ||||
throw lazyDOMException( | ||||
'length must be a multiple of 8', | ||||
'OperationError'); | ||||
} | ||||
|
||||
let result; | ||||
try { | ||||
result = await pbkdf2Promise(raw, salt, iterations, length / 8, hash); | ||||
} catch (err) { | ||||
throw lazyDOMException( | ||||
'The operation failed for an operation-specific reason', | ||||
{ name: 'OperationError', cause: err }); | ||||
} | ||||
|
||||
return new Promise((resolve, reject) => { | ||||
pbkdf2(raw, salt, iterations, byteLength, hash, (err, result) => { | ||||
if (err) return reject(err); | ||||
resolve(result.buffer); | ||||
}); | ||||
}); | ||||
return result.buffer; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
} | ||||
|
||||
module.exports = { | ||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.