diff --git a/fido2/client.py b/fido2/client.py index b921abd..41fff3e 100644 --- a/fido2/client.py +++ b/fido2/client.py @@ -47,10 +47,10 @@ ) from .cose import ES256 from .rpid import verify_rp_id -from .utils import sha256 +from .utils import sha256, _DataClassMapping from enum import IntEnum, unique from urllib.parse import urlparse -from dataclasses import replace +from dataclasses import replace, asdict from threading import Timer, Event from typing import ( Type, @@ -69,6 +69,16 @@ logger = logging.getLogger(__name__) +def ascbor(data): + if data is None: + return None + if isinstance(data, Sequence): + return [ascbor(d) for d in data] + if isinstance(data, _DataClassMapping): + # Remove empty values and do not serialize value + return {k: v for k, v in asdict(data).items() if v is not None} # type: ignore + + class ClientError(Exception): @unique class ERR(IntEnum): @@ -803,10 +813,10 @@ def make_credential( try: return self._backend.do_make_credential( client_data, - rp, - options.user, - options.pub_key_cred_params, - options.exclude_credentials, + ascbor(rp), + ascbor(options.user), + ascbor(options.pub_key_cred_params), + ascbor(options.exclude_credentials), options.extensions, selection.require_resident_key, selection.user_verification, @@ -848,7 +858,7 @@ def get_assertion( return self._backend.do_get_assertion( client_data, options.rp_id, - options.allow_credentials, + ascbor(options.allow_credentials), options.extensions, options.user_verification, event,