Browse Source

v1.2.9: bugfix RSA hash type

tags/v1.2.9
AJ ONeal 9 months ago
parent
commit
e04557c84a
3 changed files with 6 additions and 6 deletions
  1. 4
    4
      keypairs.js
  2. 1
    1
      package.json
  3. 1
    1
      test.js

+ 4
- 4
keypairs.js View File

@@ -154,9 +154,9 @@ Keypairs.signJwt = function (opts) {
154 154
     var header = opts.header || {};
155 155
     var claims = JSON.parse(JSON.stringify(opts.claims || {}));
156 156
     header.typ = 'JWT';
157
-    if (!header.kid) {
158
-      header.kid = thumb;
159
-    }
157
+
158
+    if (!header.kid) { header.kid = thumb; }
159
+    if (!header.alg && opts.alg) { header.alg = opts.alg; }
160 160
     if (!claims.iat && (false === claims.iat || false === opts.iat)) {
161 161
       claims.iat = undefined;
162 162
     } else if (!claims.iat) {
@@ -197,7 +197,7 @@ Keypairs.signJws = function (opts) {
197 197
       if (!opts.jwk) {
198 198
         throw new Error("opts.jwk must exist and must declare 'typ'");
199 199
       }
200
-      return ('RSA' === opts.jwk.typ) ? "RS256" : "ES256";
200
+      return ('RSA' === opts.jwk.kty) ? "RS256" : "ES256";
201 201
     }
202 202
 
203 203
     function sign(pem) {

+ 1
- 1
package.json View File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "keypairs",
3
-  "version": "1.2.8",
3
+  "version": "1.2.9",
4 4
   "description": "Lightweight RSA/ECDSA keypair generation and JWK <-> PEM",
5 5
   "main": "keypairs.js",
6 6
   "files": [

+ 1
- 1
test.js View File

@@ -90,7 +90,7 @@ Keypairs.parseOrGenerate({ key: '' }).then(function (pair) {
90 90
       if ('NOERR' === e.code) { throw e; }
91 91
       return true;
92 92
     })
93
-  , Keypairs.signJwt({ jwk: pair.private, iss: 'https://example.com/', exp: '1h' }).then(function (jwt) {
93
+  , Keypairs.signJwt({ jwk: pair.private, alg: 'ES512', iss: 'https://example.com/', exp: '1h' }).then(function (jwt) {
94 94
       var parts = jwt.split('.');
95 95
       var now = Math.round(Date.now()/1000);
96 96
       var token = {

Loading…
Cancel
Save