Permalink
Browse files

Fix timing attack against signature comparison

  • Loading branch information...
1 parent ce4630f commit 12efd783e7b58aa72aff8feaff54bed1c133a3f9 Carl Howells committed with lillialexis Jul 19, 2010
Showing with 11 additions and 1 deletion.
  1. +1 −1 openid/association.py
  2. +10 −0 openid/cryptutil.py
@@ -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):
View
@@ -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.