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: fix webcrypto derive key lengths #42542

Merged

Conversation

panva
Copy link
Member

@panva panva commented Mar 31, 2022

This implements the get key length operation of possible deriveKey derived key's algorithms.

Specifically, for

AES Keys
image

PBKDF2 and HKDF Keys

Return null.

HMAC Keys

image

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Mar 31, 2022
@panva panva added webcrypto experimental Issues and PRs related to experimental features. labels Mar 31, 2022
@panva
Copy link
Member Author

panva commented Mar 31, 2022

Prior to this code in place the following, which works in the browser

const alice = await crypto.subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, false, ['deriveKey']);

const bob = await crypto.subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, false, ['deriveKey']);

const alice_ecdh_params = { name: 'ECDH', public: bob.publicKey };
const alice_shared_key = await crypto.subtle.deriveKey(alice_ecdh_params, alice.privateKey, 'HKDF', false, ['deriveKey']);

Failed in Node.js with

TypeError [ERR_INVALID_ARG_TYPE]: The "length" argument must be of type number. Received undefined
    at __node_internal_captureLargerStackTrace (node:internal/errors:465:5)
    at new NodeError (node:internal/errors:372:5)
    at __node_internal_ (node:internal/validators:103:13)
    at Object.asyncDeriveBitsECDH (node:internal/crypto/diffiehellman:435:5)
    at SubtleCrypto.deriveKey (node:internal/crypto/webcrypto:184:10)
    at REPL10:1:83 {
  code: 'ERR_INVALID_ARG_TYPE'

Because the length passed to asyncDeriveBitsECDH was undefined rather than the expected null which indicates to give us everything that is generated.

@panva panva requested review from jasnell and tniessen March 31, 2022 14:39
@nodejs-github-bot
Copy link
Collaborator

@panva panva added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 1, 2022
@VoltrexKeyva VoltrexKeyva removed the needs-ci PRs that need a full CI run. label Apr 1, 2022
@panva panva added the needs-ci PRs that need a full CI run. label Apr 2, 2022
@panva panva added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 2, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 2, 2022
@nodejs-github-bot nodejs-github-bot merged commit 18bd02f into nodejs:master Apr 2, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 18bd02f

@panva panva deleted the fix-webcrypto-derive-lengths branch April 2, 2022 14:54
juanarbol pushed a commit to juanarbol/node that referenced this pull request Apr 5, 2022
PR-URL: nodejs#42542
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This was referenced Apr 5, 2022
juanarbol pushed a commit that referenced this pull request Apr 6, 2022
PR-URL: #42542
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
xtx1130 pushed a commit to xtx1130/node that referenced this pull request Apr 25, 2022
PR-URL: nodejs#42542
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
juanarbol pushed a commit that referenced this pull request May 31, 2022
PR-URL: #42542
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
danielleadams pushed a commit that referenced this pull request Jun 27, 2022
PR-URL: #42542
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
targos pushed a commit that referenced this pull request Jul 11, 2022
PR-URL: #42542
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
targos pushed a commit that referenced this pull request Jul 31, 2022
PR-URL: #42542
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
PR-URL: nodejs/node#42542
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
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. experimental Issues and PRs related to experimental features. needs-ci PRs that need a full CI run. webcrypto
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants