Skip to content

Commit

Permalink
Fix signature verificaton for Python 3.6 (#1)
Browse files Browse the repository at this point in the history
Signed-Off-By: David Bonner <[email protected]>
  • Loading branch information
rascalking authored and fophillips committed Feb 19, 2017
1 parent c37e3fe commit 6cd36d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion github_webhook/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hmac
import logging

import six
from flask import abort, request


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

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

def hook(self, event_type='push'):
Expand Down Expand Up @@ -50,9 +53,11 @@ def _postreceive(self):

if digest is not None:
sig_parts = _get_header('X-Hub-Signature').split('=', 1)
if not isinstance(digest, six.text_type):
digest = six.text_type(digest)

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

event_type = _get_header('X-Github-Event')
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
author_email="[email protected], [email protected], [email protected], [email protected]",
license='Apache 2.0',
packages=["github_webhook"],
install_requires=['flask'],
install_requires=['flask', 'six'],
tests_require=['mock', 'nose'],

classifiers=[
'Development Status :: 4 - Beta',
Expand Down

0 comments on commit 6cd36d1

Please sign in to comment.