rack-github_webhooks 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 356ef06d3434bd82cf6259402c287ac2d576f439
4
- data.tar.gz: fb0f199fc1c489350794c4545795bbd76f866e11
3
+ metadata.gz: e0ad149d1ccf3096eb22b95c057dea5cca062e2d
4
+ data.tar.gz: 5257261e19046d920788756cf143c72d2c8cab0f
5
5
  SHA512:
6
- metadata.gz: 6fb61aea03f0354d2a5f817064b2cf3f94cefefbb874d490291140a050535851ef50c18e7c7ce40091164b8ae7e6f1222f4b6865b04d928bfbd1e8424ba923b8
7
- data.tar.gz: 264cbf318764db94000244c4157780d35a905a82315493c16b4b39db39479423678e8afc415ad57350dcc5c4577b665b7ad0b7f4a6bce6586d4d8a8eb60d2243
6
+ metadata.gz: 208989b2d0f31db4b1c5ce7fc91d1f31324fd5a176c31c1f8c041e963d7ec20d6a915186c223d5074c3487aae9b5b5d3e621a1a5f3c21df313164002308fe009
7
+ data.tar.gz: 062f9dfd96e31a08452eaf54598f0a75daf71fc3e921cbcecc8dd145541db1d179a298a0053171b5567c982efbc7166a1b4741417f943da294ca5c80fc9fa1ec
@@ -3,9 +3,11 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
- ## 0.1.0 - 2015-11-29
6
+ ## [0.3.0] - 2015-11-29
7
7
 
8
- - Initial release
8
+ ### Changed
9
+
10
+ - Internal refactor to separate out `Signature` class.
9
11
 
10
12
  ## [0.2.0] - 2015-11-29
11
13
 
@@ -13,4 +15,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
13
15
 
14
16
  - Don't error when there's no 'X-Hub-Signature' header.
15
17
 
18
+
19
+ ## 0.1.0 - 2015-11-29
20
+
21
+ - Initial release
22
+
16
23
  [0.2.0]: https://github.com/chrismytton/rack-github_webhooks/compare/v0.1.0...v0.2.0
24
+ [0.3.0]: https://github.com/chrismytton/rack-github_webhooks/compare/v0.2.0...v0.3.0
@@ -4,11 +4,22 @@ require 'json'
4
4
 
5
5
  module Rack
6
6
  class GithubWebhooks
7
- HMAC_DIGEST = OpenSSL::Digest.new('sha1')
7
+ class Signature
8
+ HMAC_DIGEST = OpenSSL::Digest.new('sha1')
9
+
10
+ def initialize(secret, hub_signature, payload_body)
11
+ @secret = secret
12
+ @hub_signature = hub_signature
13
+ @signature = 'sha1=' +
14
+ OpenSSL::HMAC.hexdigest(HMAC_DIGEST, secret, payload_body)
15
+ end
8
16
 
9
- attr_reader :app
10
- attr_reader :secret
11
- attr_reader :request
17
+ def valid?
18
+ return true unless @secret
19
+ return false unless @hub_signature
20
+ Rack::Utils.secure_compare(@signature, @hub_signature)
21
+ end
22
+ end
12
23
 
13
24
  def initialize(app, opts = {})
14
25
  @app = app
@@ -16,29 +27,14 @@ module Rack
16
27
  end
17
28
 
18
29
  def call(env)
19
- @request = Rack::Request.new(env)
20
- return [400, {}, ["Signatures didn't match!"]] unless signature_valid?
21
- app.call(env)
22
- end
23
-
24
- private
25
-
26
- # Taken from https://developer.github.com/webhooks/securing/
27
- def signature_valid?
28
- return true unless secret
29
- return false unless request.env['HTTP_X_HUB_SIGNATURE']
30
- Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE'])
31
- end
32
-
33
- def signature
34
- "sha1=#{OpenSSL::HMAC.hexdigest(HMAC_DIGEST, secret, payload_body)}"
35
- end
36
-
37
- def payload_body
38
- @payload_body ||= begin
39
- request.body.rewind
40
- request.body.read
41
- end
30
+ env['rack.input'].rewind
31
+ signature = Signature.new(
32
+ @secret,
33
+ env['HTTP_X_HUB_SIGNATURE'],
34
+ env['rack.input'].read
35
+ )
36
+ return [400, {}, ["Signatures didn't match!"]] unless signature.valid?
37
+ @app.call(env)
42
38
  end
43
39
  end
44
40
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class GithubWebhooks
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-github_webhooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Mytton