Skip to content

crypto: use byteLength in timingSafeEqual - #23341

Closed
ZaneHannanAU wants to merge 7 commits into
nodejs:masterfrom
ZaneHannanAU:patch-1
Closed

crypto: use byteLength in timingSafeEqual#23341
ZaneHannanAU wants to merge 7 commits into
nodejs:masterfrom
ZaneHannanAU:patch-1

Conversation

@ZaneHannanAU

Copy link
Copy Markdown
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-botnodejs-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
Copy Markdown
ContributorAuthor

Hm?

@ZaneHannanAU

Copy link
Copy Markdown
ContributorAuthor

ah

@ZaneHannanAU

Copy link
Copy Markdown
ContributorAuthor

... weird.

@oyyd

oyyd commented Oct 9, 2018

Copy link
Copy Markdown
Contributor

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

@thefourtheye

Copy link
Copy Markdown
Contributor

cc @nodejs/crypto

@ZaneHannanAUZaneHannanAU changed the title crypto: make timingSafeEqual use bytewise length instead of array lengthcrypto,errors: make timingSafeEqual use bytewise length instead of array lengthOct 9, 2018
@ZaneHannanAU

Copy link
Copy Markdown
ContributorAuthor

... uh what should I do?

@tniessen

Copy link
Copy Markdown
Member

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
Copy Markdown
ContributorAuthor

… I should really figure out git …

@ZaneHannanAU

Copy link
Copy Markdown
ContributorAuthor

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

@ZaneHannanAU

Copy link
Copy Markdown
ContributorAuthor

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

@ZaneHannanAU

Copy link
Copy Markdown
ContributorAuthor

... does this do anything?

@thefourtheye

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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

@ZaneHannanAU

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Member

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

@tniessentniessen changed the title crypto,errors: make timingSafeEqual use bytewise length instead of array lengthcrypto: use byteLength in timingSafeEqualOct 10, 2018
@ZaneHannanAU

Copy link
Copy Markdown
ContributorAuthor

Thank you! You've absolutely saved me there…

@bnoordhuisbnoordhuis left a comment

Copy link
Copy Markdown
Member

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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@srl295srl295 added the stalled Issues and PRs that are stalled. label Jul 16, 2019
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@tniessen

Copy link
Copy Markdown
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.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cryptoIssues and PRs related to the crypto subsystem.errorsIssues and PRs related to JavaScript errors originated in Node.js core.stalledIssues and PRs that are stalled.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@ZaneHannanAU@oyyd@thefourtheye@tniessen@nodejs-github-bot@bnoordhuis@jasnell@addaleax@cjihrig@srl295