Skip to content

Commit 51b5e91

Browse files
committed
Merge branch 'main' into ylle-ignore-subclassing
2 parents 9807cbf + a055249 commit 51b5e91

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

mypy.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ disallow_subclassing_any = True
44
disallow_untyped_decorators = True
55
ignore_missing_imports = True
66
warn_unused_ignores = True
7+
8+
[mypy-ndnkdf.*]
9+
follow_untyped_imports = True
10+
11+
[mypy-fido_mds.*]
12+
follow_untyped_imports = True

src/eduid/vccs/server/password.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from binascii import unhexlify
2-
from typing import cast
32

43
from ndnkdf import NDNKDF
54

@@ -106,4 +105,4 @@ async def calculate_cred_hash(
106105

107106
# PBKDF2 again with iter=1 to mix in the local_salt into the final H2.
108107
H2 = kdf.pbkdf2_hmac_sha512(T2, 1, local_salt)
109-
return cast(str, H2.hex())
108+
return H2.hex()

src/eduid/webapp/common/authn/webauthn.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def get_authenticator_information(
9696
user_present = att.auth_data.flags.user_present
9797
user_verified = att.auth_data.flags.user_verified
9898
authenticator_id = att.aaguid or att.certificate_key_identifier
99+
if authenticator_id is None:
100+
raise AttestationVerificationError("attestation contains no authenticator id (aaguid or certificate key identifier)")
99101

100102
# allow automatic tests to use any webauthn device
101103
if is_backdoor:
@@ -159,6 +161,8 @@ def get_authenticator_information(
159161

160162
# create authenticator information from attestation and metadata
161163
metadata_entry = fido_mds.get_entry(authenticator_id=authenticator_id)
164+
if metadata_entry is None:
165+
raise AttestationVerificationError(f"no metadata entry found for authenticator {authenticator_id}")
162166
# mongodb does not support date
163167
last_status_change = metadata_entry.time_of_last_status_change
164168
user_verification_methods = [
@@ -178,7 +182,7 @@ def get_authenticator_information(
178182

179183
return AuthenticatorInformation(
180184
attestation_format=att.fmt,
181-
authenticator_id=att.aaguid or att.certificate_key_identifier,
185+
authenticator_id=authenticator_id,
182186
status=max(
183187
metadata_entry.status_reports, key=lambda sr: sr.effective_date
184188
).status, # latest status reports status

src/eduid/webapp/security/tests/test_webauthn.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
RegistrationResponse,
1111
UserVerificationRequirement,
1212
)
13-
from fido_mds import FidoMetadataStore
13+
from fido_mds import Attestation, FidoMetadataStore
14+
from fido_mds.models.webauthn import AttestationFormat
15+
from fido_mds.tests.data import IPHONE_12, MICROSOFT_SURFACE_1796, NEXUS_5, NONE_ATTESTATION, YUBIKEY_4, YUBIKEY_5_NFC
1416
from future.backports.datetime import timedelta
1517
from pytest_mock import MockerFixture
1618
from werkzeug.test import TestResponse
@@ -34,10 +36,22 @@
3436

3537
# CTAP1 test data
3638

37-
# result of calling Fido2Server.register_begin
38-
from fido_mds import Attestation
39-
from fido_mds.models.webauthn import AttestationFormat
40-
from fido_mds.tests.data import IPHONE_12, MICROSOFT_SURFACE_1796, NEXUS_5, NONE_ATTESTATION, YUBIKEY_4, YUBIKEY_5_NFC
39+
40+
def _apple_special_verify_attestation(self: FidoMetadataStore, attestation: Attestation, client_data: bytes) -> bool:
41+
if attestation.fmt is AttestationFormat.PACKED:
42+
return self.verify_packed_attestation(attestation=attestation, client_data=client_data)
43+
if attestation.fmt is AttestationFormat.APPLE:
44+
# apple attestation cert in fido_mds test data is only valid for three days
45+
return True
46+
if attestation.fmt is AttestationFormat.TPM:
47+
return self.verify_tpm_attestation(attestation=attestation, client_data=client_data)
48+
if attestation.fmt is AttestationFormat.ANDROID_SAFETYNET:
49+
# android attestation cert in fido_mds test data is only valid for three months
50+
return True
51+
if attestation.fmt is AttestationFormat.FIDO_U2F:
52+
return self.verify_fido_u2f_attestation(attestation=attestation, client_data=client_data)
53+
raise NotImplementedError(f"verification of {attestation.fmt.value} not implemented")
54+
4155

4256
# CTAP1 security key
4357
STATE = {"challenge": "u3zHzb7krB4c4wj0Uxuhsz2lCXqLnwV9ZxMhvL2lcfo", "user_verification": "discouraged"}
@@ -383,23 +397,6 @@ def _remove(
383397
response2 = client.post("/webauthn/remove", json=data)
384398
return user_token, response2
385399

386-
def _apple_special_verify_attestation(
387-
self: FidoMetadataStore, attestation: Attestation, client_data: bytes
388-
) -> bool:
389-
if attestation.fmt is AttestationFormat.PACKED:
390-
return cast(bool, self.verify_packed_attestation(attestation=attestation, client_data=client_data))
391-
if attestation.fmt is AttestationFormat.APPLE:
392-
# apple attestation cert in fido_mds test data is only valid for three days
393-
return True
394-
if attestation.fmt is AttestationFormat.TPM:
395-
return cast(bool, self.verify_tpm_attestation(attestation=attestation, client_data=client_data))
396-
if attestation.fmt is AttestationFormat.ANDROID_SAFETYNET:
397-
# android attestation cert in fido_mds test data is only valid for three months
398-
return True
399-
if attestation.fmt is AttestationFormat.FIDO_U2F:
400-
return cast(bool, self.verify_fido_u2f_attestation(attestation=attestation, client_data=client_data))
401-
raise NotImplementedError(f"verification of {attestation.fmt.value} not implemented")
402-
403400
# actual tests
404401

405402
def test_begin_no_login(self) -> None:
@@ -636,7 +633,7 @@ def test_remove_wrong_csrf(self) -> None:
636633

637634
def test_authenticator_information(self, mocker: MockerFixture) -> None:
638635
mocker.patch(
639-
"fido_mds.FidoMetadataStore.verify_attestation", SecurityWebauthnTests._apple_special_verify_attestation
636+
"fido_mds.FidoMetadataStore.verify_attestation", _apple_special_verify_attestation
640637
)
641638
authenticators = [YUBIKEY_4, YUBIKEY_5_NFC, MICROSOFT_SURFACE_1796, NEXUS_5, IPHONE_12, NONE_ATTESTATION]
642639
for authenticator in authenticators:

0 commit comments

Comments
 (0)