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

Remove constant_time_string_compare #163

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions jose/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from jose.constants import ALGORITHMS
from jose.exceptions import JWKError
from jose.utils import base64url_decode, base64url_encode
from jose.utils import constant_time_string_compare
from jose.backends.base import Key

try:
Expand Down Expand Up @@ -135,7 +134,7 @@ def sign(self, msg):
return hmac.new(self.prepared_key, msg, self.hash_alg).digest()

def verify(self, msg, sig):
return constant_time_string_compare(sig, self.sign(msg))
return hmac.compare_digest(sig, self.sign(msg))

def to_dict(self):
return {
Expand Down
24 changes: 0 additions & 24 deletions jose/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,3 @@ def timedelta_total_seconds(delta):
delta (timedelta): A timedelta to convert to seconds.
"""
return delta.days * 24 * 60 * 60 + delta.seconds


def constant_time_string_compare(a, b):
"""Helper for comparing string in constant time, independent
of the python version being used.

Args:
a (str): A string to compare
b (str): A string to compare
"""

try:
return hmac.compare_digest(a, b)
except AttributeError:

if len(a) != len(b):
return False

result = 0

for x, y in zip(a, b):
result |= ord(x) ^ ord(y)

return result == 0