Verifying signatures
Aviowiki-Signature: t=1715782200000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8f9Part
Description
Verification Steps
import hmac
import hashlib
import time
def verify_signature(payload, signature_header, secret, tolerance_ms=300000):
parts = dict(item.split("=", 1) for item in signature_header.split(","))
timestamp = int(parts["t"])
expected_sig = parts["v1"]
# Check timestamp tolerance (5 minutes)
if time.time() * 1000 - timestamp > tolerance_ms:
return False
message = f"{timestamp}.{payload}"
computed = hmac.new(
secret.encode("utf-8"),
message.encode("utf-8"),
hashlib.sha256
).hexdigest()
return hmac.compare_digest(computed, expected_sig)