Skip to content

Commit

Permalink
Get pem from modulas and exponent.
Browse files Browse the repository at this point in the history
  • Loading branch information
maeltm committed Jul 6, 2016
1 parent d83dd3a commit ec25d34
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var _ = require('underscore');
var certCache = require('./certCache');
var crypto = require('crypto');
var getPem = require('rsa-pem-from-mod-exp');

function decodeBase64WithUriEncoding(encodedText) {
return new Buffer(encodedText, 'base64').toString('utf8');
Expand Down Expand Up @@ -40,9 +41,11 @@ function verifySignature(jwt, keys) {
throw new Error('Cannot not found valid JWK');
}

var pem = getPem(keys[kid].n, keys[kid].e);

var verifier = crypto.createVerify('sha256');
verifier.update(jwt.dataToSign);
if (!verifier.verify(keys[kid], jwt.signature, 'base64')) {
if (!verifier.verify(pem, jwt.signature, 'base64')) {
throw new Error('Invalid Signature');
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "google-id-token-verifier",
"version": "0.2.0",
"version": "0.2.2",
"description": "A small library to validate a google ID token for consuming it in node.js backend server.",
"main": "./lib/main.js",
"scripts": {
Expand Down Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"request": "^2.65.0",
"rsa-pem-from-mod-exp": "^0.8.4",
"underscore": "^1.8.3"
}
}
6 changes: 5 additions & 1 deletion test/fixtures/oauthcerts.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"keyid": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDzU+jLTzW6154Joezxrd2+5pCN\nYP0HcaMoYqEyXfNRpkNE7wrQUEG830o4Qcaae2BhqZoujwSW7RkR6h0Fkd0WTR8h\n5J8rSGNHv/1jJoUUjP9iZ/5SFAyIIyEYfDPqtnA4iF1QWO2lXWlEFSuZjwM/8jBm\neGzoiw17akNThIw8NwIDAQAB\n-----END PUBLIC KEY-----\n"
"keyid": {
"pem": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDzU+jLTzW6154Joezxrd2+5pCN\nYP0HcaMoYqEyXfNRpkNE7wrQUEG830o4Qcaae2BhqZoujwSW7RkR6h0Fkd0WTR8h\n5J8rSGNHv/1jJoUUjP9iZ/5SFAyIIyEYfDPqtnA4iF1QWO2lXWlEFSuZjwM/8jBm\neGzoiw17akNThIw8NwIDAQAB\n-----END PUBLIC KEY-----\n",
"n": "APNT6MtPNbrXngmh7PGt3b7mkI1g/QdxoyhioTJd81GmQ0TvCtBQQbzfSjhBxpp7YGGpmi6PBJbtGRHqHQWR3RZNHyHknytIY0e//WMmhRSM/2Jn/lIUDIgjIRh8M+q2cDiIXVBY7aVdaUQVK5mPAz/yMGZ4bOiLDXtqQ1OEjDw3",
"e": "AQAB"
}
}

0 comments on commit ec25d34

Please sign in to comment.