diff --git a/.idea/CNSA-276-FP.iml b/.idea/CNSA-276-FP.iml index b7fe510..3c6ad93 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..c76ee5f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/tet.py b/tet.py index 7eb87dc..cbb7e17 100644 --- a/tet.py +++ b/tet.py @@ -1,21 +1,56 @@ from fido2.server import Fido2Server -from fido2.webauthn import PublicKeyCredentialRpEntity - -rp = PublicKeyCredentialRpEntity("example.com", "Example RP") -server = Fido2Server(rp) -registration_data, state = server.register_begin({ - "91974": b"user_id", # user ID as bytes - "Cyrus": "cyrus@eggtech.net", - "displayName": "Admin" -}) +from fido2.webauthn import (PublicKeyCredentialRpEntity, PublicKeyCredentialUserEntity, + PublicKeyCredentialParameters, PublicKeyCredentialCreationOptions) from fido2.client import Fido2Client from fido2.hid import CtapHidDevice +import os -# List FIDO devices on the system -devices = list(CtapHidDevice.list_devices()) -if not devices: +# Setup the relying party (RP) entity +rp = PublicKeyCredentialRpEntity("10.1.1.245", "Example RP") + +# Setup the user entity +user = PublicKeyCredentialUserEntity( + id=b'user_id', # User ID as bytes + name="user@example.com", + display_name="User Display Name" +) + +# Define the public key credential parameters +cred_params = [ + PublicKeyCredentialParameters("public-key", -7), # ES256 + PublicKeyCredentialParameters("public-key", -257) # RS256 +] + +# FIDO2 Server setup +server = Fido2Server(rp) + +# Generate a random challenge +challenge = os.urandom(32) + +# Manually create the PublicKeyCredentialCreationOptions +options = PublicKeyCredentialCreationOptions( + rp=rp, + user=user, + challenge=challenge, + pub_key_cred_params=cred_params +) + +# Start the registration process (adjust this method if needed) +registration_data, state = server.register_begin( + user=user, + challenge=challenge +) + +# Assuming the device is the first one connected +device = next(CtapHidDevice.list_devices(), None) +if device is None: raise ValueError("No FIDO device found") -device = devices[0] -client = Fido2Client(device, "https://example.com") -attestation_object, client_data = client.make_credential(registration_data) +# Client instance for the device +client = Fido2Client(device, "10.1.1.245") + +# Use the manual options we created for make_credential +attestation_object, client_data = client.make_credential(options) + +# Finalize the registration to validate the response and store the credentials +auth_data = server.register_complete(state, client_data, attestation_object)