-
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 default encoding from sign/verify #49145
Merged
nodejs-github-bot
merged 1 commit into
nodejs:main
from
tniessen:crypto-sig-default-encoding
Aug 15, 2023
Merged
crypto: remove default encoding from sign/verify #49145
nodejs-github-bot
merged 1 commit into
nodejs:main
from
tniessen:crypto-sig-default-encoding
Aug 15, 2023
Conversation
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
getDefaultEncoding() always returns 'buffer' in Node.js 20. It requires some careful justification but the default encoding can be eliminated from sig.js entirely. In Sign.prototype.update, we can safely remove the conditional assignment of getDefaultEncoding() to encoding. This is because SignUpdate() in crypto_sig.cc internally calls node::crypto::Decode, which returns UTF8 for falsy encoding values. In other words, with the conditional assignment, StringBytes::Write() ultimately receives the encoding BUFFER, and without the conditional assignment, it receives the encoding UTF8. However, StringBytes::Write() treats both encodings identically, so there is no need to deviate from the internal default encoding UTF8. In Sign.prototype.sign, we can also safely remove the conditional assignment of getDefaultEncoding() to encoding. Whether encoding is falsy or 'buffer' makes no difference. In Verify.prototype.verify, we can also safely remove the conditional assignment of getDefaultEncoding() to sigEncoding. This is because the function passes the sigEncoding to getArrayBufferOrView(), which passes it to Buffer.from(). If sigEncoding is 'buffer', getArrayBufferOrView() instead passes 'utf8' to Buffer.from(). Because the default encoding of Buffer.from() is 'utf8', passing a falsy encoding to getArrayBufferOrView() instead of 'buffer' results in the same behavior. Refs: nodejs#47182
tniessen
added
crypto
Issues and PRs related to the crypto subsystem.
dont-land-on-v16.x
dont-land-on-v18.x
PRs that should not land on the v18.x-staging branch and should not be released in v18.x.
labels
Aug 13, 2023
Review requested:
|
panva
added
request-ci
Add this label to start a Jenkins CI on a PR.
author ready
PRs that have at least one approval, no pending requests for changes, and a CI started.
labels
Aug 14, 2023
panva
approved these changes
Aug 14, 2023
github-actions
bot
removed
the
request-ci
Add this label to start a Jenkins CI on a PR.
label
Aug 14, 2023
This comment was marked as outdated.
This comment was marked as outdated.
tniessen
added a commit
to tniessen/node
that referenced
this pull request
Aug 14, 2023
getDefaultEncoding() always returns 'buffer' in Node.js 20. It requires some careful justification but the default encoding can be eliminated from hash.js entirely. The reasoning is almost identical with that in nodejs#49145 so I won't repeat it here. Refs: nodejs#47182
tniessen
added a commit
to tniessen/node
that referenced
this pull request
Aug 14, 2023
Refs: nodejs#47182 Refs: nodejs#47869 Refs: nodejs#47943 Refs: nodejs#47998 Refs: nodejs#49140 Refs: nodejs#49145 Refs: nodejs#49167 Refs: nodejs#49169
22 tasks
lpinca
approved these changes
Aug 15, 2023
tniessen
added
the
commit-queue
Add this label to land a pull request using GitHub Actions.
label
Aug 15, 2023
nodejs-github-bot
removed
the
commit-queue
Add this label to land a pull request using GitHub Actions.
label
Aug 15, 2023
Landed in 6f9d6f2 |
24 tasks
nodejs-github-bot
pushed a commit
that referenced
this pull request
Aug 16, 2023
getDefaultEncoding() always returns 'buffer' in Node.js 20. It requires some careful justification but the default encoding can be eliminated from hash.js entirely. The reasoning is almost identical with that in #49145 so I won't repeat it here. Refs: #47182 PR-URL: #49167 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
tniessen
added a commit
to tniessen/node
that referenced
this pull request
Aug 16, 2023
Refs: nodejs#47182 Refs: nodejs#47869 Refs: nodejs#47943 Refs: nodejs#47998 Refs: nodejs#49140 Refs: nodejs#49145 Refs: nodejs#49167 Refs: nodejs#49169
26 tasks
debadree25
pushed a commit
that referenced
this pull request
Aug 19, 2023
Refs: #47182 Refs: #47869 Refs: #47943 Refs: #47998 Refs: #49140 Refs: #49145 Refs: #49167 Refs: #49169 PR-URL: #49170 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
UlisesGascon
pushed a commit
that referenced
this pull request
Sep 10, 2023
getDefaultEncoding() always returns 'buffer' in Node.js 20. It requires some careful justification but the default encoding can be eliminated from sig.js entirely. In Sign.prototype.update, we can safely remove the conditional assignment of getDefaultEncoding() to encoding. This is because SignUpdate() in crypto_sig.cc internally calls node::crypto::Decode, which returns UTF8 for falsy encoding values. In other words, with the conditional assignment, StringBytes::Write() ultimately receives the encoding BUFFER, and without the conditional assignment, it receives the encoding UTF8. However, StringBytes::Write() treats both encodings identically, so there is no need to deviate from the internal default encoding UTF8. In Sign.prototype.sign, we can also safely remove the conditional assignment of getDefaultEncoding() to encoding. Whether encoding is falsy or 'buffer' makes no difference. In Verify.prototype.verify, we can also safely remove the conditional assignment of getDefaultEncoding() to sigEncoding. This is because the function passes the sigEncoding to getArrayBufferOrView(), which passes it to Buffer.from(). If sigEncoding is 'buffer', getArrayBufferOrView() instead passes 'utf8' to Buffer.from(). Because the default encoding of Buffer.from() is 'utf8', passing a falsy encoding to getArrayBufferOrView() instead of 'buffer' results in the same behavior. Refs: #47182 PR-URL: #49145 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
UlisesGascon
pushed a commit
that referenced
this pull request
Sep 10, 2023
getDefaultEncoding() always returns 'buffer' in Node.js 20. It requires some careful justification but the default encoding can be eliminated from hash.js entirely. The reasoning is almost identical with that in #49145 so I won't repeat it here. Refs: #47182 PR-URL: #49167 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
UlisesGascon
pushed a commit
that referenced
this pull request
Sep 10, 2023
Refs: #47182 Refs: #47869 Refs: #47943 Refs: #47998 Refs: #49140 Refs: #49145 Refs: #49167 Refs: #49169 PR-URL: #49170 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
author ready
PRs that have at least one approval, no pending requests for changes, and a CI started.
crypto
Issues and PRs related to the crypto subsystem.
dont-land-on-v18.x
PRs that should not land on the v18.x-staging branch and should not be released in v18.x.
needs-ci
PRs that need a full CI run.
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.
getDefaultEncoding()
always returns'buffer'
in Node.js 20. It requires some careful justification but the default encoding can be eliminated fromsig.js
entirely.In
Sign.prototype.update
, we can safely remove the conditional assignment ofgetDefaultEncoding()
toencoding
. This is becauseSignUpdate()
incrypto_sig.cc
internally callsnode::crypto::Decode
, which returnsUTF8
for falsyencoding
values. In other words, with the conditional assignment,StringBytes::Write()
ultimately receives the encodingBUFFER
, and without the conditional assignment, it receives the encodingUTF8
. However,StringBytes::Write()
treats both encodings identically, so there is no need to deviate from the internal default encodingUTF8
.In
Sign.prototype.sign
, we can also safely remove the conditional assignment ofgetDefaultEncoding()
to encoding. Whether encoding is falsy or'buffer'
makes no difference.In
Verify.prototype.verify
, we can also safely remove the conditional assignment ofgetDefaultEncoding()
tosigEncoding
. This is because the function passes thesigEncoding
togetArrayBufferOrView()
, which passes it toBuffer.from()
. IfsigEncoding
is'buffer'
,getArrayBufferOrView()
instead passes'utf8'
toBuffer.from()
. Because the default encoding ofBuffer.from()
is'utf8'
, passing a falsy encoding togetArrayBufferOrView()
instead of'buffer'
results in the same behavior.This partially addresses:
node/lib/internal/crypto/util.js
Lines 77 to 80 in af9b48a
Refs: #47182