Skip to content

Commit

Permalink
Fix timing attack against signature comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Howells authored and lillialexis committed Jul 19, 2010
1 parent ce4630f commit 12efd78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openid/association.py
Expand Up @@ -532,7 +532,7 @@ def checkMessageSignature(self, message):
if not message_sig:
raise ValueError("%s has no sig." % (message,))
calculated_sig = self.getMessageSignature(message)
return calculated_sig == message_sig
return cryptutil.const_eq(calculated_sig, message_sig)


def _makePairs(self, message):
Expand Down
10 changes: 10 additions & 0 deletions openid/cryptutil.py
Expand Up @@ -218,3 +218,13 @@ def randomString(length, chrs=None):
else:
n = len(chrs)
return ''.join([chrs[randrange(n)] for _ in xrange(length)])

def const_eq(s1, s2):
if len(s1) != len(s2):
return False

result = True
for i in range(len(s1)):
result = result and (s1[i] == s2[i])

return result

0 comments on commit 12efd78

Please sign in to comment.