Skip to content

Conversation

@XadillaX
Copy link
Contributor

@XadillaXXadillaX commented Jun 3, 2021

Refs: #38883

@XadillaXXadillaX changed the title Crypto tag bytelengthcrypto: fix aes crash when tag length too smallJun 3, 2021
@github-actionsgithub-actionsbot added crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Jun 3, 2021
false,
[ 'encrypt', 'decrypt' ])
.then((k) =>{
assert.rejects(async () =>{
Copy link
Member

Choose a reason for hiding this comment

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

This function does not need the async keyword, and using it hides whether the exception is thrown synchronously or the Promise is actually rejected.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Hmmmmm, Chrome rejects this situation in Promise. So shall we do reject or throw?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

window.crypto.subtle.decrypt({name: 'AES-GCM',iv: newUint8Array(12)},k,newUint8Array(0));>Promise{<pending>}Uncaught(inpromise) DOMException: Theprovideddataistoosmall

Copy link
Member

Choose a reason for hiding this comment

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

I believe that the behavior is correct, and the test works, but it isn't as strict as it could be. assert.rejects is fine, but the async weakens the test:

functionfnThatThrows(){thrownewError();}asyncfunctionfnThatRejects(){thrownewError();}// With 'async':assert.rejects(async()=>fnThatRejects());// passesassert.rejects(async()=>fnThatThrows());// passes, but should not!// Now remove the 'async' keyword:assert.rejects(()=>fnThatRejects());// passesassert.rejects(()=>fnThatThrows());// fails as it should

So I'd simply remove the async keyword from the function declaration :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I've resolved it.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

XadillaX added a commit that referenced this pull request Jun 15, 2021
Fixes: #38883 PR-URL: #38914 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
@XadillaX
Copy link
ContributorAuthor

Landed in 7a9635b

danielleadams pushed a commit that referenced this pull request Jun 21, 2021
Fixes: #38883 PR-URL: #38914 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
@danielleadamsdanielleadams mentioned this pull request Jun 21, 2021
@richardlau
Copy link
Member

This doesn't land cleanly on v14.x-staging.

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.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decrypting a zero-length array with SubtleCrypto triggers Assertion failures

5 participants

@XadillaX@nodejs-github-bot@richardlau@jasnell@tniessen