Skip to content

Commit

Permalink
Refactor to/from dict serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Oct 10, 2024
1 parent cf209d7 commit 9d67961
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 196 deletions.
7 changes: 4 additions & 3 deletions fido2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
AuthenticatorAttestationResponse,
AuthenticatorAssertionResponse,
AttestationConveyancePreference,
_as_cbor,
)
from .cose import ES256
from .rpid import verify_rp_id
Expand Down Expand Up @@ -444,7 +445,7 @@ def _get_extension_results(self, assertion):
def _cbor_list(values):
if not values:
return None
return [v._to_cbor() for v in values]
return [_as_cbor(v) for v in values]


class _Ctap2ClientBackend(_ClientBackend):
Expand Down Expand Up @@ -620,8 +621,8 @@ def do_make_credential(

att_obj = self.ctap2.make_credential(
client_data.hash,
rp._to_cbor(),
user._to_cbor(),
_as_cbor(rp),
_as_cbor(user),
_cbor_list(key_params),
_cbor_list(exclude_list),
extension_inputs or None,
Expand Down
12 changes: 8 additions & 4 deletions fido2/ctap2/credman.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@

from .. import cbor
from ..ctap import CtapError
from ..webauthn import PublicKeyCredentialDescriptor, PublicKeyCredentialUserEntity
from ..webauthn import (
PublicKeyCredentialDescriptor,
PublicKeyCredentialUserEntity,
_as_cbor,
)
from .base import Ctap2, Info
from .pin import PinProtocol, _PinUv

Expand Down Expand Up @@ -221,7 +225,7 @@ def delete_cred(self, cred_id: PublicKeyCredentialDescriptor) -> None:
logger.debug(f"Deleting credential with ID: {cred_id}")
self._call(
CredentialManagement.CMD.DELETE_CREDENTIAL,
{CredentialManagement.PARAM.CREDENTIAL_ID: cred_id._to_cbor()},
{CredentialManagement.PARAM.CREDENTIAL_ID: _as_cbor(cred_id)},
)
logger.info("Credential deleted")

Expand All @@ -244,8 +248,8 @@ def update_user_info(
self._call(
CredentialManagement.CMD.UPDATE_USER_INFO,
{
CredentialManagement.PARAM.CREDENTIAL_ID: cred_id._to_cbor(),
CredentialManagement.PARAM.USER: user_info._to_cbor(),
CredentialManagement.PARAM.CREDENTIAL_ID: _as_cbor(cred_id),
CredentialManagement.PARAM.USER: _as_cbor(user_info),
},
)
logger.info("Credential user info updated")
32 changes: 16 additions & 16 deletions fido2/mds3.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
verify_x509_chain,
AttestationVerifier,
)
from .utils import websafe_decode, _CamelCaseDataObject
from .utils import websafe_decode, _JsonDataObject
from .cose import CoseKey

from cryptography import x509
Expand All @@ -53,19 +53,19 @@


@dataclass(eq=False, frozen=True)
class Version(_CamelCaseDataObject):
class Version(_JsonDataObject):
major: int
minor: int


@dataclass(eq=False, frozen=True)
class RogueListEntry(_CamelCaseDataObject):
class RogueListEntry(_JsonDataObject):
sk: bytes
date: int


@dataclass(eq=False, frozen=True)
class BiometricStatusReport(_CamelCaseDataObject):
class BiometricStatusReport(_JsonDataObject):
cert_level: int
modality: str
effective_date: int
Expand All @@ -76,15 +76,15 @@ class BiometricStatusReport(_CamelCaseDataObject):


@dataclass(eq=False, frozen=True)
class CodeAccuracyDescriptor(_CamelCaseDataObject):
class CodeAccuracyDescriptor(_JsonDataObject):
base: int
min_length: int
max_retries: Optional[int] = None
block_slowdown: Optional[int] = None


@dataclass(eq=False, frozen=True)
class BiometricAccuracyDescriptor(_CamelCaseDataObject):
class BiometricAccuracyDescriptor(_JsonDataObject):
self_attested_frr: Optional[float] = field(
default=None, metadata=dict(name="selfAttestedFRR")
)
Expand All @@ -97,29 +97,29 @@ class BiometricAccuracyDescriptor(_CamelCaseDataObject):


@dataclass(eq=False, frozen=True)
class PatternAccuracyDescriptor(_CamelCaseDataObject):
class PatternAccuracyDescriptor(_JsonDataObject):
min_complexity: int
max_retries: Optional[int] = None
block_slowdown: Optional[int] = None


@dataclass(eq=False, frozen=True)
class VerificationMethodDescriptor(_CamelCaseDataObject):
class VerificationMethodDescriptor(_JsonDataObject):
user_verification_method: Optional[str] = None
ca_desc: Optional[CodeAccuracyDescriptor] = None
ba_desc: Optional[BiometricAccuracyDescriptor] = None
pa_desc: Optional[PatternAccuracyDescriptor] = None


@dataclass(eq=False, frozen=True)
class RgbPaletteEntry(_CamelCaseDataObject):
class RgbPaletteEntry(_JsonDataObject):
r: int
g: int
b: int


@dataclass(eq=False, frozen=True)
class DisplayPngCharacteristicsDescriptor(_CamelCaseDataObject):
class DisplayPngCharacteristicsDescriptor(_JsonDataObject):
width: int
height: int
bit_depth: int
Expand All @@ -131,7 +131,7 @@ class DisplayPngCharacteristicsDescriptor(_CamelCaseDataObject):


@dataclass(eq=False, frozen=True)
class EcdaaTrustAnchor(_CamelCaseDataObject):
class EcdaaTrustAnchor(_JsonDataObject):
x: str = field(metadata=dict(name="X"))
y: str = field(metadata=dict(name="Y"))
c: str
Expand Down Expand Up @@ -160,7 +160,7 @@ class AuthenticatorStatus(str, Enum):


@dataclass(eq=False, frozen=True)
class StatusReport(_CamelCaseDataObject):
class StatusReport(_JsonDataObject):
status: AuthenticatorStatus
effective_date: Optional[date] = field(
metadata=dict(
Expand All @@ -182,15 +182,15 @@ class StatusReport(_CamelCaseDataObject):


@dataclass(eq=False, frozen=True)
class ExtensionDescriptor(_CamelCaseDataObject):
class ExtensionDescriptor(_JsonDataObject):
fail_if_unknown: bool = field(metadata=dict(name="fail_if_unknown"))
id: str
tag: Optional[int] = None
data: Optional[str] = None


@dataclass(eq=False, frozen=True)
class MetadataStatement(_CamelCaseDataObject):
class MetadataStatement(_JsonDataObject):
description: str
authenticator_version: int
schema: int
Expand Down Expand Up @@ -247,7 +247,7 @@ class MetadataStatement(_CamelCaseDataObject):


@dataclass(eq=False, frozen=True)
class MetadataBlobPayloadEntry(_CamelCaseDataObject):
class MetadataBlobPayloadEntry(_JsonDataObject):
status_reports: Sequence[StatusReport]
time_of_last_status_change: date = field(
metadata=dict(
Expand Down Expand Up @@ -285,7 +285,7 @@ class MetadataBlobPayloadEntry(_CamelCaseDataObject):


@dataclass(eq=False, frozen=True)
class MetadataBlobPayload(_CamelCaseDataObject):
class MetadataBlobPayload(_JsonDataObject):
legal_header: str
no: int
next_update: date = field(
Expand Down
Loading

0 comments on commit 9d67961

Please sign in to comment.