Skip to content

Commit

Permalink
Fixed the unexplained message verification failures when there is no …
Browse files Browse the repository at this point in the history
…OTA communication.
  • Loading branch information
twardokus committed Mar 2, 2021
1 parent 28dd510 commit 648b118
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Local.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run_local(self, with_gui=False):

lock = Lock()

receiver = Receiver()
receiver = Receiver(gui_enabled=True)

listener = Thread(target=receiver.run_receiver, args=(s2, lock,))
listener.start()
Expand All @@ -44,7 +44,7 @@ def run_local(self, with_gui=False):
root.mainloop()

else:
receiver = Receiver()
receiver = Receiver(gui_enabled=False)

listener = Thread(target=receiver.run_receiver)
listener.start()
Expand Down
15 changes: 5 additions & 10 deletions Receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

class Receiver:

def __init__(self):
def __init__(self, gui_enabled=False):
self.verifier = Verifier()
self.messageCounter = 1
self.gui = gui_enabled

def run_receiver(self, s=None, lock=None, with_gui=False):
if with_gui and (not s or not lock):
def run_receiver(self, s=None, lock=None):
if self.gui and (not s or not lock):
print("Error - cannot run GUI without valid socket and thread lock. Exiting")
exit(1)

Expand All @@ -34,13 +35,8 @@ def listen_for_wsms(self, gui_socket, gui_socket_lock):

def process_packet(self, payload, s, lock):

print("Processing packet")
print(payload)

data = self.parse_wsm(payload)

print(data)

bsm_data = bytes.fromhex(data[0]).decode('ascii').replace("\n", "").split(",")

decoded_data = {}
Expand All @@ -55,7 +51,6 @@ def process_packet(self, payload, s, lock):
# publicKey = keys.import_key("keys/" + decodedData['id'] + "/p256.pub",curve=curve.P256, public=True)
public_key = keys.import_key("keys/0/p256.pub", curve=curve.P256, public=True)


is_valid_sig = self.verifier.verify_signature(data[1], data[2], data[0], public_key)

elapsed, is_recent = self.verifier.verify_time(data[3])
Expand All @@ -67,7 +62,7 @@ def process_packet(self, payload, s, lock):

vehicle_data_json = json.dumps(decoded_data)

if s == None or lock == None:
if not self.gui:
self.terminal_out(vehicle_data_json)
else:
with lock:
Expand Down
8 changes: 8 additions & 0 deletions WavePacketBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,20 @@ def getIeee1609Dot2Data(self, message, key):

private, public = import_key(key)
r, s = ecdsa.sign(message, private, hashfunc=sha256)

r = hex(r)
s = hex(s)

r = r.split("x")[1][:len(r) - 2]
s = s.split("x")[1][:len(s) - 2]

# these while loops pad the front of the hex key with zeros to make sure they fit the 32-byte field length
while len(r) < 64:
r = "0" + r

while len(s) < 64:
s = "0" + s

# r (32 bytes)
bytestring += str(r)

Expand Down

0 comments on commit 648b118

Please sign in to comment.