This commit is contained in:
devStorm 2020-05-18 00:06:24 -07:00
parent 9fb91c83e7
commit 2b8febe0b9
No known key found for this signature in database
GPG Key ID: D52E1B66F336AC57
3 changed files with 33 additions and 21 deletions

View File

@ -62,25 +62,29 @@ def fido_setup():
LOG.error(f"An error occurred in WebAuthn registration process: {e}")
flash("Key registration failed.", "warning")
return redirect(url_for("dashboard.index"))
if current_user.fido_uuid is None:
current_user.fido_uuid = fido_uuid
FIDO.create(
credential_id = str(fido_credential.credential_id, "utf-8"),
uuid = fido_uuid,
public_key = str(fido_credential.public_key, "utf-8"),
sign_count = fido_credential.sign_count,
credential_id=str(fido_credential.credential_id, "utf-8"),
uuid=fido_uuid,
public_key=str(fido_credential.public_key, "utf-8"),
sign_count=fido_credential.sign_count,
)
db.session.commit()
LOG.d(f"credential_id={str(fido_credential.credential_id, 'utf-8')} added for {fido_uuid}")
LOG.d(
f"credential_id={str(fido_credential.credential_id, 'utf-8')} added for {fido_uuid}"
)
flash("Security key has been activated", "success")
return redirect(url_for("dashboard.recovery_code_route"))
# Prepare information for key registration process
fido_uuid = str(uuid.uuid4()) if current_user.fido_uuid is None else current_user.fido_uuid
fido_uuid = (
str(uuid.uuid4()) if current_user.fido_uuid is None else current_user.fido_uuid
)
challenge = secrets.token_urlsafe(32)
credential_create_options = webauthn.WebAuthnMakeCredentialOptions(
@ -102,11 +106,13 @@ def fido_setup():
# Prevent user from adding duplicated keys
for record in fido_model:
registration_dict["excludeCredentials"].append({
'type': 'public-key',
'id': record.credential_id,
'transports': ['usb', 'nfc', 'ble', 'internal'],
})
registration_dict["excludeCredentials"].append(
{
"type": "public-key",
"id": record.credential_id,
"transports": ["usb", "nfc", "ble", "internal"],
}
)
session["fido_uuid"] = fido_uuid
session["fido_challenge"] = challenge.rstrip("=")

View File

@ -119,13 +119,19 @@ class AliasGeneratorEnum(EnumE):
word = 1 # aliases are generated based on random words
uuid = 2 # aliases are generated based on uuid
class FIDO(db.Model, ModelMixin):
__tablename__ = "fido"
credential_id = db.Column(db.String(), nullable=False, unique=True, index=True)
uuid = db.Column(db.ForeignKey("users.fido_uuid", ondelete="cascade"), unique=False, nullable=False)
uuid = db.Column(
db.ForeignKey("users.fido_uuid", ondelete="cascade"),
unique=False,
nullable=False,
)
public_key = db.Column(db.String(), nullable=False, unique=True)
sign_count = db.Column(db.Integer(), nullable=False)
class User(db.Model, ModelMixin, UserMixin):
__tablename__ = "users"
email = db.Column(db.String(256), unique=True, nullable=False)

View File

@ -148,16 +148,16 @@ def fake_data():
db.session.commit()
FIDO.create(
credential_id = "umR9q5vX61XG7vh7gi8wT0gJ9LkYwHKSzDL5vhtZs3o",
uuid = "59576167-6c37-4d67-943b-4683b24ff821",
public_key = "pQECAyYgASFYIEjQg3TOuUZJxylLE6gJDNHcNyYVW5hOAZ-vGOY9I_TDIlggfJqIh07bj3n6RVmrEsuozsYPYM6VeJKCeduz0DFp8AY",
sign_count = 1,
credential_id="umR9q5vX61XG7vh7gi8wT0gJ9LkYwHKSzDL5vhtZs3o",
uuid="59576167-6c37-4d67-943b-4683b24ff821",
public_key="pQECAyYgASFYIEjQg3TOuUZJxylLE6gJDNHcNyYVW5hOAZ-vGOY9I_TDIlggfJqIh07bj3n6RVmrEsuozsYPYM6VeJKCeduz0DFp8AY",
sign_count=1,
)
FIDO.create(
credential_id = "1mR9q5vX61XG7vh7gi8wT0gJ9LkYwHKSzDL5vhtZs3o",
uuid = "59576167-6c37-4d67-943b-4683b24ff821",
public_key = "1QECAyYgASFYIEjQg3TOuUZJxylLE6gJDNHcNyYVW5hOAZ-vGOY9I_TDIlggfJqIh07bj3n6RVmrEsuozsYPYM6VeJKCeduz0DFp8AY",
sign_count = 1,
credential_id="1mR9q5vX61XG7vh7gi8wT0gJ9LkYwHKSzDL5vhtZs3o",
uuid="59576167-6c37-4d67-943b-4683b24ff821",
public_key="1QECAyYgASFYIEjQg3TOuUZJxylLE6gJDNHcNyYVW5hOAZ-vGOY9I_TDIlggfJqIh07bj3n6RVmrEsuozsYPYM6VeJKCeduz0DFp8AY",
sign_count=1,
)
db.session.commit()