add test for succesfully logging in with security key

this is a bit complex, but essentially we're using the test variables
defined in the duolabs py_webauthn library [1]. We're already using
their test variables in tests/app/models/test_webauthn_credential.py and
in the webauthn_credential fixture in conftest.py. By using sample
signature, authenticatordata and clientdatajson from the same key we can
test that the library correctly verifies the signed challenge matches
the original.

We needed to transform some of this data as the yubico/fido2 library we
use has a slightly different way of formatting the fields for the
request body, which is why we're doing things like base64 decoding and
converting from hex to bytes in the post data.

The pytest fixture has changed - before it was incomplete/corrupted and
would error when trying to verify the signature. We took the
credential_data from the pytest fixture, converted it to an
AttestedCredentialData using WebauthnCredential.to_credential_data,
modified the public_key private dictionary to add `public_key[-1]: 1`,
and then called `AttestedCredentialData.create` to re-CBOR-encode the
blob.

The `-1: 1` is the numeric ID of the "SECP256R1" elliptic curve
algorithm. The py_webauthn library forces this particular algorithm,
which differs from the sample creds we took from the fido2 lib tests,
which is why we've had to update our data.

[1] https://github.com/duo-labs/py_webauthn/blob/master/tests/test_webauthn.py#L13-L32
This commit is contained in:
Katie Smith
2021-05-17 12:37:04 +01:00
committed by Leo Hemsted
parent 28ee2a1f9a
commit d9fd37a485
2 changed files with 89 additions and 8 deletions

View File

@@ -3963,7 +3963,7 @@ def create_active_user_manage_template_permissions(with_unique_id=False):
}
def create_platform_admin_user(with_unique_id=False, permissions=None):
def create_platform_admin_user(with_unique_id=False, auth_type='sms_auth', permissions=None):
return {
'id': str(uuid4()) if with_unique_id else sample_uuid(),
'name': 'Platform admin user',
@@ -3974,7 +3974,7 @@ def create_platform_admin_user(with_unique_id=False, permissions=None):
'failed_login_count': 0,
'permissions': permissions or {},
'platform_admin': True,
'auth_type': 'sms_auth',
'auth_type': auth_type,
'password_changed_at': str(datetime.utcnow()),
'services': [],
'organisations': [],
@@ -4481,7 +4481,7 @@ def webauthn_credential():
return {
'id': str(uuid4()),
'name': 'Test credential',
'credential_data': 'WJ0AAAAAAAAAAAAAAAAAAAAAAECKU1ppjl9gmhHWyDkgHsUvZmhr6oF3/lD3llzLE2SaOSgOGIsIuAQqgp8JQSUu3r/oOaP8RS44dlQjrH+ALfYtpAECAyYhWCAxnqAfESXOYjKUc2WACuXZ3ch0JHxV0VFrrTyjyjIHXCJYIFnx8H87L4bApR4M+hPcV+fHehEOeW+KCyd0H+WGY8s6', # noqa
'credential_data': 'WJ8AAAAAAAAAAAAAAAAAAAAAAECKU1ppjl9gmhHWyDkgHsUvZmhr6oF3/lD3llzLE2SaOSgOGIsIuAQqgp8JQSUu3r/oOaP8RS44dlQjrH+ALfYtpQECAyYgASFYIDGeoB8RJc5iMpRzZYAK5dndyHQkfFXRUWutPKPKMgdcIlggWfHwfzsvhsClHgz6E9xX58d6EQ55b4oLJ3Qf5YZjyzo=', # noqa
'registration_response': 'anything',
'created_at': '2017-10-18T16:57:14.154185Z',
}