PR comments

This commit is contained in:
Adrià Casajús 2022-05-13 18:14:21 +02:00
parent 3e0cb546a2
commit 64c67f4429
No known key found for this signature in database
GPG Key ID: F0033226A5AFC9B9
2 changed files with 13 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import base64
import binascii
import enum
import hmac
import json
@ -1409,9 +1410,7 @@ def generate_verp_email(
).lower()
def get_verp_info_from_email(
email: str, validate_time: bool = True
) -> Optional[Tuple[VerpType, int]]:
def get_verp_info_from_email(email: str) -> Optional[Tuple[VerpType, int]]:
"""This method processes the email address, checks if it's a signed verp email generated by us to receive bounces
and extracts the type of verp email and associated email log id/transactional email id stored as object_id
"""
@ -1422,10 +1421,15 @@ def get_verp_info_from_email(
fields = username.split(".")
if len(fields) != 3 or fields[0] != VERP_PREFIX:
return None
padding = (8 - (len(fields[1]) % 8)) % 8
payload = base64.b32decode(fields[1].encode("utf-8").upper() + (b"=" * padding))
padding = (8 - (len(fields[2]) % 8)) % 8
signature = base64.b32decode(fields[2].encode("utf-8").upper() + (b"=" * padding))
try:
padding = (8 - (len(fields[1]) % 8)) % 8
payload = base64.b32decode(fields[1].encode("utf-8").upper() + (b"=" * padding))
padding = (8 - (len(fields[2]) % 8)) % 8
signature = base64.b32decode(
fields[2].encode("utf-8").upper() + (b"=" * padding)
)
except binascii.Error:
return None
expected_signature = hmac.new(
VERP_EMAIL_SECRET.encode("utf-8"), payload, VERP_HMAC_ALGO
).digest()[:8]
@ -1435,8 +1439,6 @@ def get_verp_info_from_email(
# verp type, object_id, time
if len(data) != 3:
return None
if validate_time and (
data[2] > (time.time() + VERP_MESSAGE_LIFETIME - VERP_TIME_START) / 60
):
if data[2] > (time.time() + VERP_MESSAGE_LIFETIME - VERP_TIME_START) / 60:
return None
return VerpType(data[0]), data[1]

View File

@ -61,4 +61,4 @@ PROTON_CLIENT_ID=to_fill
PROTON_CLIENT_SECRET=to_fill
PROTON_BASE_URL=https://localhost/api
POSTMASTER=postmaster@simplelogin.co
POSTMASTER=postmaster@test.domain