|
10 | 10 | RegistrationResponse, |
11 | 11 | UserVerificationRequirement, |
12 | 12 | ) |
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 |
14 | 16 | from future.backports.datetime import timedelta |
15 | 17 | from pytest_mock import MockerFixture |
16 | 18 | from werkzeug.test import TestResponse |
|
34 | 36 |
|
35 | 37 | # CTAP1 test data |
36 | 38 |
|
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 | + |
41 | 55 |
|
42 | 56 | # CTAP1 security key |
43 | 57 | STATE = {"challenge": "u3zHzb7krB4c4wj0Uxuhsz2lCXqLnwV9ZxMhvL2lcfo", "user_verification": "discouraged"} |
@@ -383,23 +397,6 @@ def _remove( |
383 | 397 | response2 = client.post("/webauthn/remove", json=data) |
384 | 398 | return user_token, response2 |
385 | 399 |
|
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 | | - |
403 | 400 | # actual tests |
404 | 401 |
|
405 | 402 | def test_begin_no_login(self) -> None: |
@@ -636,7 +633,7 @@ def test_remove_wrong_csrf(self) -> None: |
636 | 633 |
|
637 | 634 | def test_authenticator_information(self, mocker: MockerFixture) -> None: |
638 | 635 | mocker.patch( |
639 | | - "fido_mds.FidoMetadataStore.verify_attestation", SecurityWebauthnTests._apple_special_verify_attestation |
| 636 | + "fido_mds.FidoMetadataStore.verify_attestation", _apple_special_verify_attestation |
640 | 637 | ) |
641 | 638 | authenticators = [YUBIKEY_4, YUBIKEY_5_NFC, MICROSOFT_SURFACE_1796, NEXUS_5, IPHONE_12, NONE_ATTESTATION] |
642 | 639 | for authenticator in authenticators: |
|
0 commit comments