Skip to content

Commit

Permalink
be explicit about endiannes in int.{to,from}_bytes (#41 and #42)
Browse files Browse the repository at this point in the history
  • Loading branch information
biemster committed Dec 11, 2023
1 parent 57e62b4 commit 113ebf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions generate_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions request_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 113ebf4

Please sign in to comment.