Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions slackeventsapi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,19 @@ def verify_signature(self, timestamp, signature):
# Python 2.7.6 doesn't support compare_digest
# It's recommended to use Python 2.7.7+
# noqa See https://docs.python.org/2/whatsnew/2.7.html#pep-466-network-security-enhancements-for-python-2-7
req = str.encode('v0:' + str(timestamp) + ':') + request.get_data()
request_hash = 'v0=' + hmac.new(
str.encode(self.signing_secret),
req, hashlib.sha256
).hexdigest()

if hasattr(hmac, "compare_digest"):
req = str.encode('v0:' + str(timestamp) + ':') + request.get_data()
request_hash = 'v0=' + hmac.new(
str.encode(self.signing_secret),
req, hashlib.sha256
).hexdigest()
# Compare byte strings for Python 2
if (sys.version_info[0] == 2):
return hmac.compare_digest(bytes(request_hash), bytes(signature))
else:
return hmac.compare_digest(request_hash, signature)
else:
# So, we'll compare the signatures explicitly
req = str.encode('v0:' + str(timestamp) + ':') + request.get_data()
request_hash = 'v0=' + hmac.new(
str.encode(self.signing_secret),
req, hashlib.sha256
).hexdigest()

if len(request_hash) != len(signature):
return False
result = 0
Expand Down Expand Up @@ -127,6 +121,7 @@ class SlackEventAdapterException(Exception):
"""
Base exception for all errors raised by the SlackClient library
"""

def __init__(self, msg=None):
if msg is None:
# default error message
Expand Down