working!
This commit is contained in:
parent
e512edcde5
commit
0d7fad8a15
188
credentailsex.py
188
credentailsex.py
@ -33,6 +33,8 @@ On Windows, the native WebAuthn API will be used.
|
|||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import pickle
|
||||||
|
|
||||||
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
|
||||||
@ -132,6 +134,7 @@ while True:
|
|||||||
pk__1 = auth_data.credential_data.public_key.get(-1)
|
pk__1 = auth_data.credential_data.public_key.get(-1)
|
||||||
pk__2 = auth_data.credential_data.public_key.get(-2)
|
pk__2 = auth_data.credential_data.public_key.get(-2)
|
||||||
pk__3 = auth_data.credential_data.public_key.get(-3)
|
pk__3 = auth_data.credential_data.public_key.get(-3)
|
||||||
|
pickled = pickle.dumps(credentials)
|
||||||
|
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
@ -152,12 +155,12 @@ while True:
|
|||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
# Define the SQL query for inserting data
|
# Define the SQL query for inserting data
|
||||||
insert_query = '''
|
insert_query = '''
|
||||||
INSERT INTO credential_data ("AAGUID", "credential_id", "pk_algo", "pk_1", "pk_3", "pk_neg1", "pk_neg2", "pk_neg3")
|
INSERT INTO credential_data ("AAGUID", "credential_id", "pk_algo", "pk_1", "pk_3", "pk_neg1", "pk_neg2", "pk_neg3", "pickled")
|
||||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s);
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s);
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# Execute the SQL query
|
# Execute the SQL query
|
||||||
cur.execute(insert_query, (aaguid, cred_id, pk_algo, pk_1, pk_3, pk__1, pk__2, pk__3))
|
cur.execute(insert_query, (aaguid, cred_id, pk_algo, pk_1, pk_3, pk__1, pk__2, pk__3, pickled))
|
||||||
|
|
||||||
# Commit the changes
|
# Commit the changes
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@ -192,114 +195,111 @@ while True:
|
|||||||
print("CREDENTIAL DATA:", auth_data.credential_data)
|
print("CREDENTIAL DATA:", auth_data.credential_data)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
server = Fido2Server({"id": "example.com", "name": "Example RP"}, attestation="direct")
|
try:
|
||||||
uv = "discouraged"
|
server = Fido2Server({"id": "example.com", "name": "Example RP"}, attestation="direct")
|
||||||
|
uv = "discouraged"
|
||||||
|
|
||||||
# Set up a FIDO 2 client using the origin https://example.com
|
# Set up a FIDO 2 client using the origin https://example.com
|
||||||
client = Fido2Client(dev, "https://example.com", user_interaction=CliInteraction())
|
client = Fido2Client(dev, "https://example.com", user_interaction=CliInteraction())
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
# Replace these variables with your connection parameters
|
# Replace these variables with your connection parameters
|
||||||
dbname = "CNSA-276-FP-DAS"
|
dbname = "CNSA-276-FP-DAS"
|
||||||
user = "FP-DEV-USER"
|
user = "FP-DEV-USER"
|
||||||
password = "purchase-immortal-prescribe-repave-detention-seizing-candied-antiques-episode-list"
|
password = "purchase-immortal-prescribe-repave-detention-seizing-candied-antiques-episode-list"
|
||||||
host = "postgres.eggtech.net"
|
host = "postgres.eggtech.net"
|
||||||
|
|
||||||
# Define the SQL query for retrieving data
|
# Define the SQL query for retrieving data
|
||||||
select_query = '''
|
select_query = '''
|
||||||
SELECT "AAGUID", credential_id, pk_algo, pk_1, pk_3, pk_neg1, pk_neg2, pk_neg3
|
SELECT "AAGUID", credential_id, pk_algo, pk_1, pk_3, pk_neg1, pk_neg2, pk_neg3, pickled
|
||||||
FROM credential_data
|
FROM credential_data
|
||||||
WHERE "AAGUID" = %s;
|
WHERE "AAGUID" = %s;
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
# Function to connect to the PostgreSQL database and retrieve data
|
# Function to connect to the PostgreSQL database and retrieve data
|
||||||
def fetch_data(aaguid):
|
def fetch_data(aaguid):
|
||||||
conn = None
|
conn = None
|
||||||
try:
|
try:
|
||||||
# Connect to the PostgreSQL server
|
# Connect to the PostgreSQL server
|
||||||
conn = psycopg2.connect(dbname=dbname, user=user, password=password, host=host)
|
conn = psycopg2.connect(dbname=dbname, user=user, password=password, host=host)
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
|
||||||
# Execute the SQL query
|
# Execute the SQL query
|
||||||
cur.execute(select_query, (gotAaguid,))
|
cur.execute(select_query, (gotAaguid,))
|
||||||
|
|
||||||
# Fetch the results
|
# Fetch the results
|
||||||
result = cur.fetchone()
|
result = cur.fetchone()
|
||||||
if result:
|
if result:
|
||||||
data = {
|
data = {
|
||||||
"AAGUID": result[0],
|
"AAGUID": result[0],
|
||||||
"credential_id": result[1],
|
"credential_id": result[1],
|
||||||
"pk_algo": result[2],
|
"pk_algo": result[2],
|
||||||
"pk_1": result[3],
|
"pk_1": result[3],
|
||||||
"pk_3": result[4],
|
"pk_3": result[4],
|
||||||
"pk_neg1": result[5],
|
"pk_neg1": result[5],
|
||||||
"pk_neg2": result[6],
|
"pk_neg2": result[6],
|
||||||
"pk_neg3": result[7]
|
"pk_neg3": result[7],
|
||||||
}
|
"pickled": result[8]
|
||||||
return data
|
}
|
||||||
else:
|
return data
|
||||||
print("No data found for AAGUID:", aaguid)
|
else:
|
||||||
return None
|
print("No data found for AAGUID:", aaguid)
|
||||||
|
return None
|
||||||
|
|
||||||
# Close communication with the database
|
# Close communication with the database
|
||||||
cur.close()
|
cur.close()
|
||||||
except (Exception, psycopg2.DatabaseError) as error:
|
except (Exception, psycopg2.DatabaseError) as error:
|
||||||
print(error)
|
print(error)
|
||||||
finally:
|
finally:
|
||||||
if conn is not None:
|
if conn is not None:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# Example usage: Fetch data for a specific AAGUID and store in variables
|
# Example usage: Fetch data for a specific AAGUID and store in variables
|
||||||
aaguid_data = fetch_data("your_specific_aaguid_here")
|
aaguid_data = fetch_data("your_specific_aaguid_here")
|
||||||
|
|
||||||
if aaguid_data:
|
if aaguid_data:
|
||||||
# Store each piece of data into a separate variable
|
# Store each piece of data into a separate variable
|
||||||
testa = aaguid_data["AAGUID"]
|
testa = aaguid_data["AAGUID"]
|
||||||
cred_id = aaguid_data["credential_id"]
|
cred_id = aaguid_data["credential_id"]
|
||||||
pk_algo = aaguid_data["pk_algo"]
|
pk_algo = aaguid_data["pk_algo"]
|
||||||
pk_1 = aaguid_data["pk_1"]
|
pk_1 = aaguid_data["pk_1"]
|
||||||
pk_3 = aaguid_data["pk_3"]
|
pk_3 = aaguid_data["pk_3"]
|
||||||
pk_neg1 = aaguid_data["pk_neg1"]
|
pk_neg1 = aaguid_data["pk_neg1"]
|
||||||
pk_neg2 = aaguid_data["pk_neg2"]
|
pk_neg2 = aaguid_data["pk_neg2"]
|
||||||
pk_neg3 = aaguid_data["pk_neg3"]
|
pk_neg3 = aaguid_data["pk_neg3"]
|
||||||
auth_data = fido2.webauthn.AttestedCredentialData(testa, cred_id, pk_algo)
|
pickled = aaguid_data["pickled"]
|
||||||
# auth_data.aaguid = AAGUID
|
|
||||||
# auth_data.credential_id = cred_id
|
|
||||||
# auth_data.public_key.ALGORITHM= pk_algo
|
|
||||||
# auth_data.public_key.setdefault(1, pk_1)
|
|
||||||
# auth_data.public_key.setdefault(3, pk_3)
|
|
||||||
# auth_data.public_key.setdefault(-1, pk__1)
|
|
||||||
# auth_data.public_key.setdefault(-2, pk__2)
|
|
||||||
# auth_data.public_key.setdefault(-3,pk__3)
|
|
||||||
|
|
||||||
credentials = [auth_data]
|
|
||||||
|
|
||||||
|
|
||||||
# Prepare parameters for getAssertion
|
credentials = pickle.loads(pickled)
|
||||||
request_options, state = server.authenticate_begin(credentials, user_verification=uv)
|
|
||||||
|
|
||||||
# Authenticate the credential
|
|
||||||
result = client.get_assertion(request_options["publicKey"])
|
|
||||||
|
|
||||||
# Only one cred in allowCredentials, only one response.
|
# Prepare parameters for getAssertion
|
||||||
result = result.get_response(0)
|
request_options, state = server.authenticate_begin(credentials, user_verification=uv)
|
||||||
|
|
||||||
# Complete authenticator
|
# Authenticate the credential
|
||||||
server.authenticate_complete(
|
result = client.get_assertion(request_options["publicKey"])
|
||||||
state,
|
|
||||||
|
|
||||||
credentials,
|
# Only one cred in allowCredentials, only one response.
|
||||||
result.credential_id,
|
result = result.get_response(0)
|
||||||
result.client_data,
|
|
||||||
result.authenticator_data,
|
|
||||||
result.signature,
|
|
||||||
)
|
|
||||||
|
|
||||||
print("Credential authenticated!")
|
# Complete authenticator
|
||||||
|
server.authenticate_complete(
|
||||||
|
state,
|
||||||
|
|
||||||
print("CLIENT DATA:", result.client_data)
|
credentials,
|
||||||
print()
|
result.credential_id,
|
||||||
print("AUTH DATA:", result.authenticator_data)
|
result.client_data,
|
||||||
|
result.authenticator_data,
|
||||||
|
result.signature,
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Credential authenticated!")
|
||||||
|
|
||||||
|
print("CLIENT DATA:", result.client_data)
|
||||||
|
print()
|
||||||
|
print("AUTH DATA:", result.authenticator_data)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
Loading…
Reference in New Issue
Block a user