From 85c5db992aa017198261967afc850531b980f314 Mon Sep 17 00:00:00 2001 From: Steve Embling <34773749+steve-embling@users.noreply.github.com> Date: Fri, 22 Feb 2019 10:00:32 +0000 Subject: [PATCH 1/4] initial testing of iclass crypto --- lrr_wiegand_listener.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lrr_wiegand_listener.py b/lrr_wiegand_listener.py index b9f79034..8e965ae5 100644 --- a/lrr_wiegand_listener.py +++ b/lrr_wiegand_listener.py @@ -7,6 +7,11 @@ ############################################################################# import pigpio +from Crypto.Cipher import DES3 +from Crypto.Random import get_random_bytes +from binascii import hexlify + +iclass_key = "00000000000000000000000000000000" # The magic code to decode wiegand data from the wiegand data lines. Borrowed from http://abyz.co.uk/rpi/pigpio/examples.html class decoder: @@ -123,6 +128,14 @@ def validateCSV(file): if not (id_num.isdigit()): id_num = 0 + def encryptIClass(wiegand_hex): + if iclass_key == "00000000000000000000000000000000": + return "FFFFFFFFFFFFFFFF".upper() + else: + key = iclass_key.decode("hex") + cipher = DES3.new(key, DES3.MODE_ECB) + plaintext = wiegand_hex.decode("hex") + return hexlify(cipher.encrypt(plaintext)) # Add scanned cards to CSV file def addCardsToCSV(bits, wiegand_binary, wiegand_hex, enc_hex, fac_code, card_num, card_num_no_fac): @@ -195,4 +208,4 @@ def callback(bits, value): raw_input() w.cancel() pi.stop() - \ No newline at end of file + From 41ea7041eda4b7fac7fccd40d45ae31af40c0310 Mon Sep 17 00:00:00 2001 From: Steve Embling <34773749+steve-embling@users.noreply.github.com> Date: Fri, 22 Feb 2019 10:08:28 +0000 Subject: [PATCH 2/4] added hooks --- lrr_wiegand_listener.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lrr_wiegand_listener.py b/lrr_wiegand_listener.py index 8e965ae5..94c6a846 100644 --- a/lrr_wiegand_listener.py +++ b/lrr_wiegand_listener.py @@ -183,7 +183,7 @@ def callback(bits, value): fac_code, card_num, card_num_no_fac, hidHeader = decodeWiegandData(bits, wiegand_binary) wiegand_binary = hidHeader + wiegand_binary wiegand_hex = "%016X" % int(wiegand_binary, 2) - enc_hex = "FFFFFFFFFFFFFFFF".upper() # To Implement + enc_hex = encryptIClass(wiegand_hex) addCardsToCSV(bits, wiegand_binary, wiegand_hex, enc_hex, fac_code, card_num, card_num_no_fac) # Debug output to console From 64f6124ff7ee28a43ca4e8e12905b47e8ca16ead Mon Sep 17 00:00:00 2001 From: Steve Embling <34773749+steve-embling@users.noreply.github.com> Date: Fri, 22 Feb 2019 10:25:23 +0000 Subject: [PATCH 3/4] uppercase for consistency --- lrr_wiegand_listener.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lrr_wiegand_listener.py b/lrr_wiegand_listener.py index 94c6a846..f30ebdf3 100644 --- a/lrr_wiegand_listener.py +++ b/lrr_wiegand_listener.py @@ -135,7 +135,7 @@ def encryptIClass(wiegand_hex): key = iclass_key.decode("hex") cipher = DES3.new(key, DES3.MODE_ECB) plaintext = wiegand_hex.decode("hex") - return hexlify(cipher.encrypt(plaintext)) + return hexlify(cipher.encrypt(plaintext)).upper() # Add scanned cards to CSV file def addCardsToCSV(bits, wiegand_binary, wiegand_hex, enc_hex, fac_code, card_num, card_num_no_fac): From 4b762909a56132442919bc6874f542ad67b8bf4c Mon Sep 17 00:00:00 2001 From: Steve Embling <34773749+steve-embling@users.noreply.github.com> Date: Fri, 22 Feb 2019 12:41:56 +0000 Subject: [PATCH 4/4] Removed unecessary import --- lrr_wiegand_listener.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lrr_wiegand_listener.py b/lrr_wiegand_listener.py index f30ebdf3..fc3697d1 100644 --- a/lrr_wiegand_listener.py +++ b/lrr_wiegand_listener.py @@ -8,7 +8,6 @@ import pigpio from Crypto.Cipher import DES3 -from Crypto.Random import get_random_bytes from binascii import hexlify iclass_key = "00000000000000000000000000000000"