Skip to content

Commit 89f62cb

Browse files
committed
chore: update dependencies
Squashed commit of the following: commit a61cace46f4f745283177a6ca4551e6237aa4d8a Author: Hugo Ferrando Seage <hugoseage@gmail.com> Date: Wed May 13 15:33:19 2020 +0200 Downgrade eslint to version 6.8.0 Version 7 dropped support for node 8 commit f08aa1e125738fe00183306f925d4e2ecf9e5704 Author: Hugo Ferrando Seage <hugoseage@gmail.com> Date: Wed May 13 14:52:18 2020 +0200 FIX unit tests - Made environment.js work with the newer mocha version - Remove all Buffer constructors - Change test order to fix broken tests in node < 10.7 - nodejs/node#21288 - Changed minimum node version to 8, due to the updated dependencies commit ce1f40d4e5ae79f4bcf6a3cca0f914ef51effd3b Author: Hugo Ferrando Seage <hugoseage@gmail.com> Date: Wed May 13 14:52:04 2020 +0200 Relint jwt-utils.js with newer eslint rules commit 59940f5552dbfb8353e71250b1a0d3038913a17e Author: Hugo Ferrando Seage <hugoseage@gmail.com> Date: Wed May 13 14:50:51 2020 +0200 Replace new Buffer with Buffer.from and Buffer.alloc The Buffer constructor was deprecated: https://nodejs.org/en/docs/guides/buffer-constructor-deprecation/ commit b46245788a6235b0490f9902e9218945cb6d585c Author: Hugo Ferrando Seage <hugoseage@gmail.com> Date: Wed May 13 14:48:56 2020 +0200 Remove travis and coveralls badges Also removed the .travis file and npm script. Neither service is executing their pipelines for this repo anymore commit 23f537ad6fdc4b8924add6feb16628512529a47a Author: Hugo Ferrando Seage <hugoseage@gmail.com> Date: Wed May 13 14:48:42 2020 +0200 Integrate jscsrc rules into eslintrc commit c0e23b53a27d82d14430d05b63426dcae868cfd9 Author: Hugo Ferrando Seage <hugoseage@gmail.com> Date: Wed May 13 14:44:52 2020 +0200 CHORE update dependencies - coveralls removed as the pipeline is not executed anymore - jscs removed as it was deprecated - added eslint-google dependency to replace jscs with eslint - jwa NOT updated as it would break compatibility - therror NOT updated
1 parent 58911e6 commit 89f62cb

9 files changed

Lines changed: 3077 additions & 155 deletions

File tree

.eslintrc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"extends": "google",
23
"env": {
34
"node": true
45
},
@@ -7,6 +8,20 @@
78
"quotes": [2, "single"],
89
"no-underscore-dangle": 0,
910
"new-cap": [1, {"capIsNew": false}],
10-
"no-mixed-requires": [1, true]
11+
"no-mixed-requires": [1, true],
12+
"require-jsdoc": ["error", {
13+
"require": {
14+
"FunctionDeclaration": false,
15+
"MethodDefinition": false,
16+
"ClassDeclaration": false,
17+
"ArrowFunctionExpression": false,
18+
"FunctionExpression": false
19+
}
20+
}],
21+
"valid-jsdoc": 0,
22+
"no-var": 0,
23+
"one-var": 0,
24+
"max-len": ["error", { "code": 120 }],
25+
"comma-dangle": ["error", "never"]
1126
}
1227
}

.jscsrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ jwt-utils
44
JSON Web Tokens (JWT) utils.
55

66
[![npm version](https://badge.fury.io/js/jwt-utils.svg)](http://badge.fury.io/js/jwt-utils)
7-
[![Build Status](https://travis-ci.org/telefonica/node-jwt-utils.svg)](https://travis-ci.org/telefonica/node-jwt-utils)
8-
[![Coverage Status](https://img.shields.io/coveralls/telefonica/node-jwt-utils.svg)](https://coveralls.io/r/telefonica/node-jwt-utils)
97

108
This module is able to parse and generate both encrypted and unencrypted JWT tokens.
119

lib/jwt-utils.js

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
var crypto = require('crypto');
2121
var debugLib = require('debug'),
22-
_ = require('underscore'),
23-
jwa = require('jwa');
22+
_ = require('underscore'),
23+
jwa = require('jwa');
2424
var errors = require('./errors');
2525

2626
var debug = debugLib('tef:base:jwtUtils');
@@ -41,12 +41,12 @@ var authenticationTagBits = {
4141
'sha512': 32
4242
};
4343

44-
/*jshint -W069 */
45-
/*jshint -W072*/
46-
/*jshint -W098*/
47-
/*jshint -W117*/
44+
/* jshint -W069 */
45+
/* jshint -W072*/
46+
/* jshint -W098*/
47+
/* jshint -W117*/
4848
var DEFAULT_CONFIG = {
49-
//Number of seconds to consider a jwt expired
49+
// Number of seconds to consider a jwt expired
5050
expiration: 600,
5151
futureTolerance: 4
5252
};
@@ -57,7 +57,6 @@ var DEFAULT_CONFIG = {
5757
* @return {Object}
5858
*/
5959
module.exports = function(configuration) {
60-
6160
var config = {};
6261

6362
function base64urlEscape(str) {
@@ -70,19 +69,19 @@ module.exports = function(configuration) {
7069
}
7170

7271
function base64urlEncode(str) {
73-
return base64urlEscape(new Buffer(str).toString('base64'));
72+
return base64urlEscape(Buffer.from(str).toString('base64'));
7473
}
7574

7675
function base64urlDecode(str) {
77-
return new Buffer(base64urlUnescape(str), 'base64');
76+
return Buffer.from(base64urlUnescape(str), 'base64');
7877
}
7978

8079
function encodeBase64url(base64) {
8180
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
8281
}
8382

8483
function convertSlowBufToBuf(slowBuffer) {
85-
var buffer = new Buffer(slowBuffer.length);
84+
var buffer = Buffer.alloc(slowBuffer.length);
8685
slowBuffer.copy(buffer);
8786
return buffer;
8887
}
@@ -130,9 +129,9 @@ module.exports = function(configuration) {
130129
segments.push(base64urlEncode(JSON.stringify(header)));
131130
segments.push(base64urlEncode(JSON.stringify(payload)));
132131
var signer = jwa(header.alg);
133-
//If we use RS256, the key is the private Key
132+
// If we use RS256, the key is the private Key
134133
if (header.alg.indexOf('HS') === 0) {
135-
key = new Buffer(key, 'hex');
134+
key = Buffer.from(key, 'hex');
136135
}
137136
segments.push(signer.sign(segments.join('.'), key));
138137

@@ -155,7 +154,7 @@ module.exports = function(configuration) {
155154

156155
var signer = jwa(algorithm);
157156
if (algorithm.indexOf('HS') === 0) {
158-
key = new Buffer(key, 'hex');
157+
key = Buffer.from(key, 'hex');
159158
}
160159
if (!signer.verify(segments[0] + '.' + segments[1], segments[2], key)) {
161160
throw errors.WRONG_TOKEN_SIGNATURE();
@@ -200,7 +199,7 @@ module.exports = function(configuration) {
200199
origAuthenticationTag = segments[4];
201200
}
202201

203-
var encKeyBuffer = new Buffer(encKey, 'hex');
202+
var encKeyBuffer = Buffer.from(encKey, 'hex');
204203
var result, hashBuf;
205204
try {
206205
var decipher = crypto.createDecipheriv(algorithms.cipherAlgorithm, encKeyBuffer, initializationVector);
@@ -211,21 +210,21 @@ module.exports = function(configuration) {
211210
var endBody = decipher.final();
212211
result = Buffer.concat([convertSlowBufToBuf(mainBody), convertSlowBufToBuf(endBody)]).toString();
213212

214-
var b64Header = new Buffer(segments[0]);
215-
var iv = new Buffer(initializationVector);
216-
var encryptedBody = new Buffer(cypherText);
213+
var b64Header = Buffer.from(segments[0]);
214+
var iv = Buffer.from(initializationVector);
215+
var encryptedBody = Buffer.from(cypherText);
217216

218217
// create al vector
219-
var al = new Buffer(4);
218+
var al = Buffer.alloc(4);
220219
al.writeInt32BE(b64Header.length * 8, 0);
221220

222-
var buf4Clear = new Buffer(4);
221+
var buf4Clear = Buffer.alloc(4);
223222
buf4Clear.fill(0);
224223
var alResult = Buffer.concat([buf4Clear, al]);
225224

226-
var authTag = new Buffer(Buffer.concat([b64Header, iv, encryptedBody, alResult]));
225+
var authTag = Buffer.from(Buffer.concat([b64Header, iv, encryptedBody, alResult]));
227226

228-
var hashKeyBuffer = new Buffer(hashKey, 'hex');
227+
var hashKeyBuffer = Buffer.from(hashKey, 'hex');
229228
var authTagHash = crypto.createHmac(algorithms.hashAlgorithm, hashKeyBuffer).update(authTag).digest();
230229

231230
var authTagHashBuf = convertSlowBufToBuf(authTagHash);
@@ -251,11 +250,10 @@ module.exports = function(configuration) {
251250
iv.push(Math.round(Math.random() * 255));
252251
}
253252

254-
return new Buffer(iv);
253+
return Buffer.from(iv);
255254
}
256255

257256
function encryptJWT(payload, header, encKey, hashKey) {
258-
259257
header = _.defaults(header, {
260258
alg: 'dir',
261259
enc: 'A256CBC-HS512'
@@ -271,7 +269,7 @@ module.exports = function(configuration) {
271269

272270
var segments = [];
273271

274-
var b64Header = encodeBase64url(new Buffer(JSON.stringify(header)).toString('base64'));
272+
var b64Header = encodeBase64url(Buffer.from(JSON.stringify(header)).toString('base64'));
275273
segments.push(b64Header);
276274

277275
var b64Jek = '';
@@ -280,10 +278,10 @@ module.exports = function(configuration) {
280278
var b64IV = encodeBase64url(iv.toString('base64'));
281279
segments.push(b64IV);
282280

283-
var encKeyBuffer = new Buffer(encKey, 'hex');
281+
var encKeyBuffer = Buffer.from(encKey, 'hex');
284282
var cipher = crypto.createCipheriv(algorithms.cipherAlgorithm, encKeyBuffer, iv);
285283

286-
var cipherTextBegin = cipher.update(new Buffer(JSON.stringify(payload), 'utf8'));
284+
var cipherTextBegin = cipher.update(Buffer.from(JSON.stringify(payload), 'utf8'));
287285

288286
var cipherTextEnd = cipher.final();
289287

@@ -294,21 +292,21 @@ module.exports = function(configuration) {
294292

295293
// Calculate AuthTag
296294

297-
var b64HeaderBuf = new Buffer(b64Header);
295+
var b64HeaderBuf = Buffer.from(b64Header);
298296

299297
// We have iv Buffer and cipherTextBuf Buffer calculated.
300298

301-
var al = new Buffer(4);
299+
var al = Buffer.alloc(4);
302300
al.writeInt32BE(b64HeaderBuf.length * 8, 0);
303301

304-
var buf4Clear = new Buffer(4);
302+
var buf4Clear = Buffer.alloc(4);
305303
buf4Clear.fill(0);
306304

307305
var alResult = Buffer.concat([buf4Clear, al]);
308306

309-
var authTag = new Buffer(Buffer.concat([b64HeaderBuf, iv, cipherTextBuf, alResult]));
307+
var authTag = Buffer.from(Buffer.concat([b64HeaderBuf, iv, cipherTextBuf, alResult]));
310308

311-
var hashKeyBuffer = new Buffer(hashKey, 'hex');
309+
var hashKeyBuffer = Buffer.from(hashKey, 'hex');
312310
var base64str = crypto.createHmac(algorithms.hashAlgorithm, hashKeyBuffer).update(authTag).digest();
313311

314312
var buf = convertSlowBufToBuf(base64str);
@@ -405,7 +403,6 @@ module.exports = function(configuration) {
405403
} else {
406404
return cb(errors.ENCRYPTION_ERROR(err.message));
407405
}
408-
409406
}
410407
cb(null, result);
411408
},

0 commit comments

Comments
 (0)