Comparing version 0.0.3 to 0.0.4
42
index.js
// deed - verify x-hub-signature | ||
module.exports = verify | ||
module.exports = deed | ||
var string_decoder = require('string_decoder') | ||
, crypto = require('crypto') | ||
, util = require('util') | ||
, stream = require('stream') | ||
; | ||
function write (buf) { | ||
return new string_decoder.StringDecoder('hex').write(buf) | ||
util.inherits(Verify, stream.Transform) | ||
function Verify (sig) { | ||
stream.Transform.call(this) | ||
this.buf = 'sha1=' | ||
this.sig = sig | ||
this.dec = new string_decoder.StringDecoder('hex') | ||
this._readableState.objectMode = true | ||
} | ||
function match (hmac, sig) { | ||
var chunk | ||
, str = 'sha1=' | ||
; | ||
while (null !== (chunk = hmac.read())) { | ||
str += write(chunk) | ||
} | ||
return str === sig | ||
Verify.prototype._transform = function (chunk, enc, cb) { | ||
this.buf += this.dec.write(chunk) | ||
cb() | ||
} | ||
function verify (secret, req, cb) { | ||
Verify.prototype._flush = function () { | ||
this.push(this.buf === this.sig ? true : false) | ||
} | ||
function deed (secret, req, cb) { | ||
var xub = 'X-Hub-Signature' | ||
, sig = req.headers[xub] || req.headers[xub.toLowerCase()] | ||
, sig = req.headers[xub] || req.headers[xub.toLowerCase()] | ||
; | ||
if (!sig) return cb(new Error('no ' + xub)) | ||
var hmac = crypto.createHmac('sha1', secret) | ||
hmac.once('finish', function () { | ||
var verified = match(hmac, sig) | ||
verified ? cb(null, req) : cb(new Error('unverified ' + xub)) | ||
, verify = new Verify(sig) | ||
; | ||
verify.once('readable', function () { | ||
verify.read() ? cb(null, req) : cb(new Error('unverified ' + xub)) | ||
}) | ||
verify.once('error', cb) | ||
hmac.once('error', cb) | ||
req.once('error', cb) | ||
req.pipe(hmac) | ||
req.pipe(hmac).pipe(verify) | ||
return req | ||
} |
{ | ||
"name": "deed", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "verify x-hub-signature", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5679
115