Skip to content

Commit 57d747e

Browse files
added support for RSA-SHA1 signatures
1 parent 5dff265 commit 57d747e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/passport-http-oauth/strategies/consumer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ ConsumerStrategy.prototype.authenticate = function(req) {
302302
if (tokenSecret) { key += utils.encode(tokenSecret); }
303303
var computedSignature = utils.hmacsha256(key, base);
304304

305+
if (signature !== computedSignature) {
306+
return self.fail(self._challenge('signature_invalid'));
307+
}
308+
} else if (signatureMethod === 'RSA-SHA1') {
309+
var key = utils.encode(consumerSecret) + '&';
310+
if (tokenSecret) { key += utils.encode(tokenSecret); }
311+
var computedSignature = utils.rsasha1(key, base);
312+
305313
if (signature !== computedSignature) {
306314
return self.fail(self._challenge('signature_invalid'));
307315
}

lib/passport-http-oauth/strategies/utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ exports.hmacsha256 = function(key, text) {
198198
return crypto.createHmac('sha256', key).update(text).digest('base64')
199199
}
200200

201+
/**
202+
* Generate RSA-SHA1 signature.
203+
*
204+
* @param {String} key
205+
* @param {String} text
206+
* @return {String}
207+
* @api private
208+
*/
209+
exports.rsasha1 = function(key, text) {
210+
return crypto.createSign('RSA-SHA1').update(text).sign(key, 'base64')
211+
}
212+
201213
/**
202214
* Generate PLAINTEXT signature.
203215
*

0 commit comments

Comments
 (0)