Skip to content
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: use byteLength in timingSafeEqual #23341

Closed
wants to merge 7 commits into from

Conversation

ZaneHannanAU
Copy link
Contributor

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

crypto.timingSafeEqual() can cause the core to abort
if the length parameter matches; however the internal
byte length differs. This commit makes the length
validation use bytewise (ArrayBufferLike) byteLength
rather than array content length.

Reissuing of #21397 with various modifications and fixes.

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels Oct 8, 2018
@ZaneHannanAU
Copy link
Contributor Author

Hm?

@ZaneHannanAU
Copy link
Contributor Author

ah

@ZaneHannanAU
Copy link
Contributor Author

... weird.

@oyyd
Copy link
Contributor

oyyd commented Oct 9, 2018

Try npx core-validate-commit --no-validate-metadata 3dd887d which validates commit messages .

@thefourtheye
Copy link
Contributor

cc @nodejs/crypto

@ZaneHannanAU ZaneHannanAU changed the title crypto: make timingSafeEqual use bytewise length instead of array length crypto,errors: make timingSafeEqual use bytewise length instead of array length Oct 9, 2018
@ZaneHannanAU
Copy link
Contributor Author

... uh what should I do?

@tniessen
Copy link
Member

tniessen commented Oct 9, 2018

Please follow the guidelines from the CONTRIBUTING file to correctly format your (first) commit message. You can use interactive rebasing to rewrite the first commit message, but there are other possibilities.

@ZaneHannanAU
Copy link
Contributor Author

… I should really figure out git …

@ZaneHannanAU
Copy link
Contributor Author

Is there a way to do it through the gh ui?

@ZaneHannanAU
Copy link
Contributor Author

... I have no idea what I'm doing

@ZaneHannanAU
Copy link
Contributor Author

... does this do anything?

@thefourtheye
Copy link
Contributor

@ZaneHannanAU What are you trying to do? You can run the tests locally by ./configure && make -j4 test, if you are on Unix based OSes.

@ZaneHannanAU
Copy link
Contributor Author

I'm trying to edit the commit message and as you can tell, I have no idea what I'm doing.

@ZaneHannanAU
Copy link
Contributor Author

Okay; how can I rebase the mess I've made myself to just have 1 commit saying

crypto,errors: use byteLength in safeTimingEqual

for the time being?

@tniessen
Copy link
Member

I took the liberty of fixing your branch accordingly, the old HEAD was c177921.

@tniessen tniessen changed the title crypto,errors: make timingSafeEqual use bytewise length instead of array length crypto: use byteLength in timingSafeEqual Oct 10, 2018
@ZaneHannanAU
Copy link
Contributor Author

Thank you! You've absolutely saved me there…

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, mostly LGTM but see comments.

@@ -518,7 +518,7 @@ E('ERR_CRYPTO_SCRYPT_NOT_SUPPORTED', 'Scrypt algorithm not supported', Error);
// Switch to TypeError. The current implementation does not seem right.
E('ERR_CRYPTO_SIGN_KEY_REQUIRED', 'No key provided to sign', Error);
E('ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH',
'Input buffers must have the same length', RangeError);
'Input buffers must have the same byteLength', RangeError);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to consider undoing this change. Error message changes are considered semver-major, meaning this couldn't be released until Node.js 12.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure, are we still doing that? I was under the impression that we don’t necessarily consider it semver-major when there’s an associated message code…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that error message changes shouldn't be semver major if there is an error code, since that was (one of) the advertised advantage in migrating to them. That said, I'm not sure there is much benefit to changing this. IMO, the error message was better before, even if it didn't completely reflect the implementation details.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, Input buffers must have the same number of bytes? Same idea, a bit more human readable?

0, 1, // 26
1, 0, // 28
1, 1, // 30
0) // 31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you factor out these Buffer.of() calls? Just assign it once to a const expected = Buffer.of(...) and compare against that.

@srl295 srl295 added the stalled Issues and PRs that are stalled. label Jul 16, 2019
@nodejs-github-bot
Copy link
Collaborator

@tniessen
Copy link
Member

I am closing this PR since it has become inactive and the relevant changes were merged in #29657.

@ZaneHannanAU I added you to 6174306 as a co-author.

@tniessen tniessen closed this Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants