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

Change crypto lib #380

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions middleware/auth-utils/grant-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const URL = require('url');
const http = require('http');
const https = require('https');
const crypto = require('crypto');
const jwa = require('jwa');
const querystring = require('querystring');
const Grant = require('./grant');
const Token = require('./token');
Expand Down Expand Up @@ -440,12 +440,11 @@ GrantManager.prototype.validateToken = function validateToken (token, expectedTy
reject(new Error('invalid token (wrong audience)'));
}
}
const verify = crypto.createVerify('RSA-SHA256');
const verify = jwa('RS256');
// if public key has been supplied use it to validate token
if (this.publicKey) {
try {
verify.update(token.signed);
if (!verify.verify(this.publicKey, token.signature, 'base64')) {
if (!verify.verify(token.signed, token.signature, this.publicKey)) {
reject(new Error('invalid token (signature)'));
} else {
resolve(token);
Expand All @@ -456,8 +455,7 @@ GrantManager.prototype.validateToken = function validateToken (token, expectedTy
} else {
// retrieve public KEY and use it to validate token
this.rotation.getJWK(token.header.kid).then(key => {
verify.update(token.signed);
if (!verify.verify(key, token.signature)) {
if (!verify.verify(token.signed, token.signature, key)) {
reject(new Error('invalid token (public key signature)'));
} else {
resolve(token);
Expand Down
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"jwa": "^2.0.0",
"jwk-to-pem": "^2.0.0"
},
"devDependencies": {
Expand Down