Skip to content

Commit 6cd36d1

Browse files
rascalkingfophillips
authored andcommitted
Fix signature verificaton for Python 3.6 (#1)
Signed-Off-By: David Bonner <dbonner@gmail.com>
1 parent c37e3fe commit 6cd36d1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

github_webhook/webhook.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hmac
44
import logging
55

6+
import six
67
from flask import abort, request
78

89

@@ -21,6 +22,8 @@ def __init__(self, app, endpoint='/postreceive', secret=None):
2122

2223
self._hooks = collections.defaultdict(list)
2324
self._logger = logging.getLogger('webhook')
25+
if secret is not None and not isinstance(secret, six.binary_type):
26+
secret = secret.encode('utf-8')
2427
self._secret = secret
2528

2629
def hook(self, event_type='push'):
@@ -50,9 +53,11 @@ def _postreceive(self):
5053

5154
if digest is not None:
5255
sig_parts = _get_header('X-Hub-Signature').split('=', 1)
56+
if not isinstance(digest, six.text_type):
57+
digest = six.text_type(digest)
5358

5459
if (len(sig_parts) < 2 or sig_parts[0] != 'sha1'
55-
or not hmac.compare_digest(sig_parts[1], unicode(digest))):
60+
or not hmac.compare_digest(sig_parts[1], digest)):
5661
abort(400, 'Invalid signature')
5762

5863
event_type = _get_header('X-Github-Event')

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
author_email="achamberlai9@bloomberg.net, fphillips7@bloomberg.net, dkiss1@bloomberg.net, dbeer1@bloomberg.net",
99
license='Apache 2.0',
1010
packages=["github_webhook"],
11-
install_requires=['flask'],
11+
install_requires=['flask', 'six'],
12+
tests_require=['mock', 'nose'],
1213

1314
classifiers=[
1415
'Development Status :: 4 - Beta',

0 commit comments

Comments
 (0)