From 7296900ddfa85ce6a92d54f6ee1503d466c24231 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 19 Jun 2017 16:32:53 -0400 Subject: [PATCH] Updates for key validation: - Check the start and stop bytes of the RFID message in addition to the expected length to prevent crashes. - There is no need to re-lock the door if it was never unlocked. Signed-off-by: Anna Schumaker --- doors.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doors.py b/doors.py index 0cb42fc..52fffa4 100755 --- a/doors.py +++ b/doors.py @@ -154,8 +154,8 @@ RFID_SERIAL = serial.Serial(RFID_PATH, 2400, timeout=1) def read_key(): RFID_SERIAL.reset_input_buffer() # Clear input buffer before reading string = RFID_SERIAL.read(12) - if len(string) > 0: - key = string[1:11].decode() #exclude start x0A and stop x0D bytes + if len(string) == 12 and string[0] == 0xA and string[-1] == 0xD: + key = string[1:11].decode() #exclude start 0xA and stop 0xD bytes if key.isalnum(): return key; return None @@ -166,7 +166,7 @@ def read_rfid(): if key and verify_key(key): unlock_door() time.sleep(5) # block for 5 seconds before resetting door - lock_door() + lock_door() flush_keys() except Exception as e: print(e)