From 113ebf4017729b92a381624c1932065588c3ebde Mon Sep 17 00:00:00 2001 From: Lars Beemster Date: Mon, 11 Dec 2023 18:24:04 +0100 Subject: [PATCH] be explicit about endiannes in int.{to,from}_bytes (#41 and #42) --- generate_keys.py | 4 ++-- request_reports.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/generate_keys.py b/generate_keys.py index 3519f45..1386071 100755 --- a/generate_keys.py +++ b/generate_keys.py @@ -25,8 +25,8 @@ def sha256(data): priv = random.getrandbits(224) adv = ec.derive_private_key(priv, ec.SECP224R1(), default_backend()).public_key().public_numbers().x - priv_bytes = int.to_bytes(priv, 28) - adv_bytes = int.to_bytes(adv, 28) + priv_bytes = int.to_bytes(priv, 28, 'big') + adv_bytes = int.to_bytes(adv, 28, 'big') priv_b64 = base64.b64encode(priv_bytes).decode("ascii") adv_b64 = base64.b64encode(adv_bytes).decode("ascii") diff --git a/request_reports.py b/request_reports.py index 0be3ba2..baac99a 100755 --- a/request_reports.py +++ b/request_reports.py @@ -21,8 +21,8 @@ def decrypt(enc_data, algorithm_dkey, mode): def decode_tag(data): latitude = struct.unpack(">i", data[0:4])[0] / 10000000.0 longitude = struct.unpack(">i", data[4:8])[0] / 10000000.0 - confidence = int.from_bytes(data[8:9]) - status = int.from_bytes(data[9:10]) + confidence = int.from_bytes(data[8:9], 'big') + status = int.from_bytes(data[9:10], 'big') return {'lat': latitude, 'lon': longitude, 'conf': confidence, 'status':status} def getAuth(regenerate=False, second_factor='sms'): @@ -78,11 +78,11 @@ def getAuth(regenerate=False, second_factor='sms'): ordered = [] found = set() for report in res: - priv = int.from_bytes(base64.b64decode(privkeys[report['id']])) + priv = int.from_bytes(base64.b64decode(privkeys[report['id']]), 'big') data = base64.b64decode(report['payload']) # the following is all copied from https://github.com/hatomist/openhaystack-python, thanks @hatomist! - timestamp = int.from_bytes(data[0:4]) +978307200 + timestamp = int.from_bytes(data[0:4], 'big') +978307200 sq3.execute(f"INSERT OR REPLACE INTO reports VALUES ('{names[report['id']]}', {timestamp}, {report['datePublished']}, '{report['payload']}', '{report['id']}', {report['statusCode']})") if timestamp >= startdate: eph_key = ec.EllipticCurvePublicKey.from_encoded_point(ec.SECP224R1(), data[5:62])