From 7e3b6678d609ea2e027230197a2eaf84226b9c3f Mon Sep 17 00:00:00 2001 From: EggMan Date: Thu, 9 May 2024 23:14:52 -0400 Subject: [PATCH] revert to before nfc --- .idea/CNSA-276-FP.iml | 2 +- .idea/misc.xml | 2 +- install.sh | 1 - main.py | 36 ++++++------------------------------ 4 files changed, 8 insertions(+), 33 deletions(-) diff --git a/.idea/CNSA-276-FP.iml b/.idea/CNSA-276-FP.iml index b7fe510..673a12b 100644 --- a/.idea/CNSA-276-FP.iml +++ b/.idea/CNSA-276-FP.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 92298c3..0cddb8e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/install.sh b/install.sh index a6de1d3..8f3769a 100644 --- a/install.sh +++ b/install.sh @@ -5,7 +5,6 @@ sudo apt-get upgrade -y sudo apt-get update sudo apt-get install python3-psycopg2 -y sudo apt-get install python3-fido2 -y -sudo apt-get install python3-nfcpy -y sudo apt-get install screen -y sudo apt-get update diff --git a/main.py b/main.py index 5fd8f8f..342d51c 100644 --- a/main.py +++ b/main.py @@ -33,12 +33,11 @@ On Windows, the native WebAuthn API will be used. """ import time import configparser -gpie = True +gpie = False if gpie: import RPi.GPIO as GPIO import pickle import psycopg2 -import ndef import fido2.webauthn from fido2.hid import CtapHidDevice from fido2.client import Fido2Client, WindowsClient, UserInteraction @@ -48,14 +47,11 @@ import sys import ctypes from fido2.ctap2 import Ctap2 from fido2 import cbor -import nfc config = configparser.ConfigParser() config.read('config.ini') -isNfc = False - dbusername = config.get('Setup', 'dbusername') dbpassword = config.get('Setup', 'dbpassword') dbname = config.get('Setup', 'dbname') @@ -73,10 +69,6 @@ redLed = 7 door = 40 -def send_fido2_over_nfc(encoded_message): - ndef_message = ndef.Message(ndef.Record('application/fido2', '', encoded_message)) - return clf.connect(rdwr={'on-connect': lambda tag: tag.ndef.records.append(ndef_message)}) - if gpie: # badCredentials = False GPIO.setup(greenLed, GPIO.OUT) @@ -110,21 +102,7 @@ class CliInteraction(UserInteraction): print("User Verification required.") return True -clf = None -def read_nfc_tag(): - try: - import nfc - clf = nfc.ContactlessFrontend('usb') - tag = clf.connect(rdwr={'on-connect': lambda tag: False}) - nfc = True - return tag.identifier if tag else None - except Exception as e: - # print("NFC read error:", e) - return None - finally: - if clf: - clf.close() - pass + while True: isNfc = False @@ -137,7 +115,7 @@ while True: GPIO.output(redLed, GPIO.HIGH) while True: try: - nfc_tag = read_nfc_tag() + dev = next(CtapHidDevice.list_devices(), None) if dev: @@ -248,11 +226,9 @@ while True: request_options, state = server.authenticate_begin(credentials, user_verification=uv) # Authenticate the credential - if not isNfc: - result = client.get_assertion(request_options["publicKey"]) - else: - sendme = cbor.encode(credentials) - send_fido2_over_nfc(sendme) + + result = client.get_assertion(request_options["publicKey"]) + # Only one cred in allowCredentials, only one response. result = result.get_response(0)