Merge remote-tracking branch 'origin/main'

# Conflicts:
#	main.py
This commit is contained in:
EggMan20339 2024-05-10 03:23:57 -04:00
commit 40df6174a9
4 changed files with 8 additions and 34 deletions

View File

@ -5,7 +5,7 @@
<excludeFolder url="file://$MODULE_DIR$/.venv" /> <excludeFolder url="file://$MODULE_DIR$/.venv" />
<excludeFolder url="file://$MODULE_DIR$/venv" /> <excludeFolder url="file://$MODULE_DIR$/venv" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.12 (CNSA-276-FP)" jdkType="Python SDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@ -3,5 +3,5 @@
<component name="Black"> <component name="Black">
<option name="sdkName" value="Python 3.12 (CNSA-276-FP)" /> <option name="sdkName" value="Python 3.12 (CNSA-276-FP)" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (CNSA-276-FP)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (CNSA-276-FP) (2)" project-jdk-type="Python SDK" />
</project> </project>

View File

@ -5,7 +5,6 @@ sudo apt-get upgrade -y
sudo apt-get update sudo apt-get update
sudo apt-get install python3-psycopg2 -y sudo apt-get install python3-psycopg2 -y
sudo apt-get install python3-fido2 -y sudo apt-get install python3-fido2 -y
sudo apt-get install python3-nfcpy -y
sudo apt-get install screen -y sudo apt-get install screen -y
sudo apt-get update sudo apt-get update

37
main.py
View File

@ -33,12 +33,11 @@ On Windows, the native WebAuthn API will be used.
""" """
import time import time
import configparser import configparser
gpie = True gpie = False
if gpie: if gpie:
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
import pickle import pickle
import psycopg2 import psycopg2
import ndef
import fido2.webauthn import fido2.webauthn
from fido2.hid import CtapHidDevice from fido2.hid import CtapHidDevice
from fido2.client import Fido2Client, WindowsClient, UserInteraction from fido2.client import Fido2Client, WindowsClient, UserInteraction
@ -48,15 +47,11 @@ import sys
import ctypes import ctypes
from fido2.ctap2 import Ctap2 from fido2.ctap2 import Ctap2
from fido2 import cbor from fido2 import cbor
import nfc
from fido2.nfc import CtapNfcDevice
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read('config.ini') config.read('config.ini')
isNfc = False
dbusername = config.get('Setup', 'dbusername') dbusername = config.get('Setup', 'dbusername')
dbpassword = config.get('Setup', 'dbpassword') dbpassword = config.get('Setup', 'dbpassword')
dbname = config.get('Setup', 'dbname') dbname = config.get('Setup', 'dbname')
@ -74,10 +69,6 @@ redLed = 7
door = 40 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: if gpie:
# badCredentials = False # badCredentials = False
GPIO.setup(greenLed, GPIO.OUT) GPIO.setup(greenLed, GPIO.OUT)
@ -111,21 +102,7 @@ class CliInteraction(UserInteraction):
print("User Verification required.") print("User Verification required.")
return True 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: while True:
isNfc = False isNfc = False
@ -138,7 +115,7 @@ while True:
GPIO.output(redLed, GPIO.HIGH) GPIO.output(redLed, GPIO.HIGH)
while True: while True:
try: try:
nfc_tag = read_nfc_tag()
dev = next(CtapHidDevice.list_devices(), None) dev = next(CtapHidDevice.list_devices(), None)
if dev: if dev:
@ -249,11 +226,9 @@ while True:
request_options, state = server.authenticate_begin(credentials, user_verification=uv) request_options, state = server.authenticate_begin(credentials, user_verification=uv)
# Authenticate the credential # Authenticate the credential
if not isNfc:
result = client.get_assertion(request_options["publicKey"]) result = client.get_assertion(request_options["publicKey"])
else:
sendme = cbor.encode(credentials)
send_fido2_over_nfc(sendme)
# Only one cred in allowCredentials, only one response. # Only one cred in allowCredentials, only one response.
result = result.get_response(0) result = result.get_response(0)