-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from totem/develop
0.5.0 : Support for Github hook signature
- Loading branch information
Showing
7 changed files
with
131 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*jshint maxcomplexity:15 */ | ||
|
||
/*! | ||
* Docker Image Factory - Authenticates request using request signature. | ||
* Signature is calculated using SHA HMAC (using hexdigest) of the payload | ||
* using pre-configured secret | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var crypto = require('crypto'), | ||
restify = require('restify'); | ||
|
||
module.exports = usingSignedRequest; | ||
|
||
/** | ||
* Returns middleware that authorizes the request payload using signature | ||
* specified in the header. | ||
* | ||
* @param secret Secret to be used for computing SHA HMAC of the payload. | ||
* @param header Header name of the request which contains signature. | ||
* @returns {authorize} | ||
*/ | ||
function usingSignedRequest(secret, header) { | ||
header = header || 'X-Hook-Signature'; | ||
|
||
return function authorize(req, res, next) { | ||
var hmac = crypto.createHmac('sha1', secret); | ||
hmac.update(req.body); | ||
var calculatedSignature = 'sha1=' + hmac.digest('hex'); | ||
var actualSignature = req.header(header); | ||
if (actualSignature !== calculatedSignature) { | ||
return (next( | ||
new restify.errors.InvalidCredentialsError( | ||
'Mismatch in computed signature and the passed signature of the request payload.'))); | ||
} else { | ||
return (next()); | ||
} | ||
}; | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters