Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Pythons older than 2.7.7 #42

Merged
merged 4 commits into from
Nov 1, 2016

Conversation

sebbacon
Copy link
Contributor

Fixes #41

else:
def compare_digest(s1, s2):
return s1 == s2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest instead switching to django.utils.crypto.constant_time_compare, which is available on all Django versions we support. That preserves the security aspect of the code (unlike a simple == compare).

@@ -34,7 +42,7 @@ def validate_request(self, request):
raise AnymailWebhookValidationFailure("Mailgun webhook called without required security fields")
expected_signature = hmac.new(key=self.api_key, msg='{}{}'.format(timestamp, token).encode('ascii'),
digestmod=hashlib.sha256).hexdigest()
if not hmac.compare_digest(signature, expected_signature):
if not compare_digest(signature, expected_signature):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same change is also needed in the Mandrill webhook.

`EnvironmentVarGuard` is not safe to use outside python-internal
development. Additionally, this test was failing in Python 2.7.3

From https://docs.python.org/2/library/test.html:

> Any use of this package outside of Python’s standard library is
> discouraged as code mentioned here can change or be removed without
> notice between releases of Python
@medmunds medmunds merged commit f0589e3 into anymail:master Nov 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants