From ec3f6f3dd29e4503a69f6e7dc1cc65c3061d2361 Mon Sep 17 00:00:00 2001 From: Mawoka Date: Sun, 18 Dec 2022 19:49:00 +0100 Subject: [PATCH] :bug: Fixed webauthn --- classquiz/routers/login.py | 5 +++-- classquiz/routers/users/webauthn.py | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/classquiz/routers/login.py b/classquiz/routers/login.py index 10de373..52cad4a 100644 --- a/classquiz/routers/login.py +++ b/classquiz/routers/login.py @@ -4,6 +4,7 @@ import base64 import enum import os +import urllib.parse import uuid import pyotp @@ -84,7 +85,7 @@ def verify_webauthn(data, fidocredentialss: list[FidoCredentials], login_session verify_authentication_response( credential=credential, expected_challenge=base64.b64decode(login_session.webauthn_challenge), - expected_rp_id="localhost", + expected_rp_id=urllib.parse.urlparse(settings.root_address).netloc, expected_origin=settings.root_address, credential_public_key=user_cred.public_key, credential_current_sign_count=user_cred.sign_count, @@ -115,7 +116,7 @@ async def start_login(data: StartLoginInput): else: step_1.add(StartLoginResponseTypes.PASSKEY) webauthn_data = generate_authentication_options( - rp_id="localhost", + rp_id=urllib.parse.urlparse(settings.root_address).netloc, allow_credentials=[ PublicKeyCredentialDescriptor(id=cred.id, type="public-key") for cred in user.fidocredentialss ], diff --git a/classquiz/routers/users/webauthn.py b/classquiz/routers/users/webauthn.py index a909fc1..6750506 100644 --- a/classquiz/routers/users/webauthn.py +++ b/classquiz/routers/users/webauthn.py @@ -1,3 +1,5 @@ +import urllib.parse + from fastapi import APIRouter, Depends, HTTPException from pydantic import BaseModel from webauthn.helpers.cose import COSEAlgorithmIdentifier @@ -26,7 +28,7 @@ router = APIRouter() async def request_add_key_data(user: User = Depends(get_current_user)): user = await User.objects.select_related("fidocredentialss").get(id=user.id) options = generate_registration_options( - rp_id="localhost", + rp_id=urllib.parse.urlparse(settings.root_address).netloc, rp_name="ClassQuiz", user_id=user.id.hex, user_name=user.email, @@ -57,7 +59,7 @@ async def confirm_add_key_data(credential: RegistrationCredential, user: User = verification = verify_registration_response( credential=credential, expected_challenge=current_registration_challenge, - expected_rp_id="localhost", + expected_rp_id=urllib.parse.urlparse(settings.root_address).netloc, expected_origin=settings.root_address, ) new_credential = FidoCredentials(