JWT signing with private key & passphrase throws error
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, node.js
- Domain
- authentication, security
Research direction
Reproduce the example with Node.js v12.20.0, then trace the signing path through jsonwebtoken/sign.js, jwa/index.js, and jws/lib/sign-stream.js shown in the stack trace. The fix is complete when a passphrase-protected PEM private key can sign a PS512 token without the key.key type error, with regression coverage for this case.
Written by the indexing model from the issue text.
Description
Description
Signing jwt token with private key & passphrase results in error. Generated private key as below
ssh-keygen -t rsa -b 2048 -m PEM -f PS512.key and add passphrase
Reproduction
const jwt = require('jsonwebtoken');
const privateKey = `<copy & paste the generated private key here>`;
const token = jwt.sign(
{ test: 12 },
{ key: privateKey , passphrase: '...' }, {
algorithm: 'PS512'
});
console.log(token);
Error
internal/crypto/keys.js:288
throw new ERR_INVALID_ARG_TYPE(
^
TypeError [ERR_INVALID_ARG_TYPE]: The "key.key" property must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received an instance of Object
at prepareAsymmetricKey (internal/crypto/keys.js:288:13)
at preparePrivateKey (internal/crypto/keys.js:308:10)
at Sign.sign (internal/crypto/sig.js:94:46)
at Object.sign (jwt-playground/node_modules/jwa/index.js:174:45)
at Object.jwsSign [as sign] (jwt-playground/node_modules/jws/lib/sign-stream.js:32:24)
at Object.module.exports [as sign] (jwt-playground/node_modules/jsonwebtoken/sign.js:204:16)
at Object.<anonymous> (jwt-playground/pem-format-passphrase/jwt-pem-formar-passphrase.js:75:19)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32) {
code: 'ERR_INVALID_ARG_TYPE'
}
Environment
- Version of the library used: 8.5.1
- Version of the Node.js: v12.20.0
- OS: macOS Monterey - 12.6
- Dominant language
- JavaScript
- Stars
- 18.2k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from auth0/node-jsonwebtoken
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
auth0/node-jsonwebtoken#1042 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
auth0/node-jsonwebtoken#1000 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 65/100
auth0/node-jsonwebtoken#1046 ·
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
auth0/node-jsonwebtoken#1034 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
auth0/node-jsonwebtoken#1032 ·
All issues in auth0/node-jsonwebtoken
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
antfu-collective/icones#398 ·
-
ECmail.com Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
wesbos/burner-email-providers#554 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
radiantearth/stac-browser#1023 ·
-
HMR stops working Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
components-web-app/docs#92 ·