digest compare in timedHmac

master
Kevin Froman 2017-12-29 12:06:23 -05:00
parent 6d34907196
commit 1fbd6eb64e
1 changed files with 5 additions and 1 deletions

View File

@ -33,7 +33,11 @@ class TimedHMAC:
return return
def check(self, data): def check(self, data):
# Check a hash (and verify time is sane)
testHash = hmac.HMAC(base64.b64decode(base64Key).decode(), digestmod=self.hashAlgo) testHash = hmac.HMAC(base64.b64decode(base64Key).decode(), digestmod=self.hashAlgo)
testHash.update(data + math.floor(time.time())) testHash.update(data + math.floor(time.time()))
testHash = testHash.hexdigest() testHash = testHash.hexdigest()
if hmac.compare_digest(testHash, self.HMACResult) if hmac.compare_digest(testHash, self.HMACResult):
return true
else:
return false