From e04557c84a646d46be069db15ec254ae954e3c6a Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 8 Mar 2019 15:24:52 -0700 Subject: [PATCH] v1.2.9: bugfix RSA hash type --- keypairs.js | 8 ++++---- package.json | 2 +- test.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/keypairs.js b/keypairs.js index bc90541..19e7812 100644 --- a/keypairs.js +++ b/keypairs.js @@ -154,9 +154,9 @@ Keypairs.signJwt = function (opts) { var header = opts.header || {}; var claims = JSON.parse(JSON.stringify(opts.claims || {})); header.typ = 'JWT'; - if (!header.kid) { - header.kid = thumb; - } + + if (!header.kid) { header.kid = thumb; } + if (!header.alg && opts.alg) { header.alg = opts.alg; } if (!claims.iat && (false === claims.iat || false === opts.iat)) { claims.iat = undefined; } else if (!claims.iat) { @@ -197,7 +197,7 @@ Keypairs.signJws = function (opts) { if (!opts.jwk) { throw new Error("opts.jwk must exist and must declare 'typ'"); } - return ('RSA' === opts.jwk.typ) ? "RS256" : "ES256"; + return ('RSA' === opts.jwk.kty) ? "RS256" : "ES256"; } function sign(pem) { diff --git a/package.json b/package.json index 312f107..f001cc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keypairs", - "version": "1.2.8", + "version": "1.2.9", "description": "Lightweight RSA/ECDSA keypair generation and JWK <-> PEM", "main": "keypairs.js", "files": [ diff --git a/test.js b/test.js index 73bdb0f..5b99f72 100644 --- a/test.js +++ b/test.js @@ -90,7 +90,7 @@ Keypairs.parseOrGenerate({ key: '' }).then(function (pair) { if ('NOERR' === e.code) { throw e; } return true; }) - , Keypairs.signJwt({ jwk: pair.private, iss: 'https://example.com/', exp: '1h' }).then(function (jwt) { + , Keypairs.signJwt({ jwk: pair.private, alg: 'ES512', iss: 'https://example.com/', exp: '1h' }).then(function (jwt) { var parts = jwt.split('.'); var now = Math.round(Date.now()/1000); var token = {