Skip to content
Snippets Groups Projects
Commit 1eee78db authored by Julian's avatar Julian
Browse files

ported webauthn code to fido2 version in buster

parent 0f898174
Branches
Tags
No related merge requests found
# Versions from Debian Buster
ldap3==2.4.1
flask==1.0.2
Flask-SQLAlchemy==2.1
qrcode==6.1
fido2==0.5.0
Flask-OAuthlib==0.9.5
from flask import Blueprint, render_template, session, request, redirect, url_for, flash, current_app from flask import Blueprint, render_template, session, request, redirect, url_for, flash, current_app
import urllib.parse import urllib.parse
from fido2.webauthn import PublicKeyCredentialRpEntity, UserVerificationRequirement
from fido2.client import ClientData from fido2.client import ClientData
from fido2.server import Fido2Server from fido2.server import Fido2Server, RelyingParty
from fido2.ctap2 import AttestationObject, AuthenticatorData from fido2.ctap2 import AttestationObject, AuthenticatorData
from fido2 import cbor from fido2 import cbor
...@@ -104,7 +103,7 @@ def delete_totp(id): ...@@ -104,7 +103,7 @@ def delete_totp(id):
return redirect(url_for('mfa.setup')) return redirect(url_for('mfa.setup'))
def get_webauthn_server(): def get_webauthn_server():
return Fido2Server(PublicKeyCredentialRpEntity(urllib.parse.urlsplit(request.url).hostname, "uffd")) return Fido2Server(RelyingParty(urllib.parse.urlsplit(request.url).hostname, "uffd"))
@bp.route('/setup/webauthn/begin', methods=['POST']) @bp.route('/setup/webauthn/begin', methods=['POST'])
@login_required() @login_required()
...@@ -123,11 +122,10 @@ def setup_webauthn_begin(): ...@@ -123,11 +122,10 @@ def setup_webauthn_begin():
"displayName": user.displayname, "displayName": user.displayname,
}, },
creds, creds,
user_verification=UserVerificationRequirement.DISCOURAGED, user_verification='discouraged',
authenticator_attachment="cross-platform",
) )
session["webauthn-state"] = state session["webauthn-state"] = state
return cbor.encode(registration_data) return cbor.dumps(registration_data)
@bp.route('/setup/webauthn/complete', methods=['POST']) @bp.route('/setup/webauthn/complete', methods=['POST'])
@login_required() @login_required()
...@@ -135,7 +133,7 @@ def setup_webauthn_begin(): ...@@ -135,7 +133,7 @@ def setup_webauthn_begin():
def setup_webauthn_complete(): def setup_webauthn_complete():
user = get_current_user() user = get_current_user()
server = get_webauthn_server() server = get_webauthn_server()
data = cbor.decode(request.get_data()) data = cbor.loads(request.get_data())[0]
client_data = ClientData(data["clientDataJSON"]) client_data = ClientData(data["clientDataJSON"])
att_obj = AttestationObject(data["attestationObject"]) att_obj = AttestationObject(data["attestationObject"])
auth_data = server.register_complete(session["webauthn-state"], client_data, att_obj) auth_data = server.register_complete(session["webauthn-state"], client_data, att_obj)
...@@ -143,7 +141,7 @@ def setup_webauthn_complete(): ...@@ -143,7 +141,7 @@ def setup_webauthn_complete():
db.session.add(method) db.session.add(method)
db.session.commit() db.session.commit()
print("REGISTERED CREDENTIAL:", auth_data.credential_data) print("REGISTERED CREDENTIAL:", auth_data.credential_data)
return cbor.encode({"status": "OK"}) return cbor.dumps({"status": "OK"})
@bp.route('/setup/webauthn/<int:id>/delete') @bp.route('/setup/webauthn/<int:id>/delete')
@login_required() @login_required()
...@@ -163,9 +161,9 @@ def auth_webauthn_begin(): ...@@ -163,9 +161,9 @@ def auth_webauthn_begin():
creds = [method.cred_data.credential_data for method in methods] creds = [method.cred_data.credential_data for method in methods]
if not creds: if not creds:
abort(404) abort(404)
auth_data, state = server.authenticate_begin(creds, user_verification=UserVerificationRequirement.DISCOURAGED) auth_data, state = server.authenticate_begin(creds, user_verification='discouraged')
session["webauthn-state"] = state session["webauthn-state"] = state
return cbor.encode(auth_data) return cbor.dumps(auth_data)
@bp.route("/auth/webauthn/complete", methods=["POST"]) @bp.route("/auth/webauthn/complete", methods=["POST"])
def auth_webauthn_complete(): def auth_webauthn_complete():
...@@ -175,7 +173,7 @@ def auth_webauthn_complete(): ...@@ -175,7 +173,7 @@ def auth_webauthn_complete():
creds = [method.cred_data.credential_data for method in methods] creds = [method.cred_data.credential_data for method in methods]
if not creds: if not creds:
abort(404) abort(404)
data = cbor.decode(request.get_data()) data = cbor.loads(request.get_data())[0]
credential_id = data["credentialId"] credential_id = data["credentialId"]
client_data = ClientData(data["clientDataJSON"]) client_data = ClientData(data["clientDataJSON"])
auth_data = AuthenticatorData(data["authenticatorData"]) auth_data = AuthenticatorData(data["authenticatorData"])
...@@ -189,7 +187,7 @@ def auth_webauthn_complete(): ...@@ -189,7 +187,7 @@ def auth_webauthn_complete():
signature, signature,
) )
session['user_mfa'] = True session['user_mfa'] = True
return cbor.encode({"status": "OK"}) return cbor.dumps({"status": "OK"})
@bp.route('/auth', methods=['GET']) @bp.route('/auth', methods=['GET'])
@login_required(skip_mfa=True) @login_required(skip_mfa=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment