Skip to content

Commit

Permalink
Fix CBOR serialization with webauthn_json_mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Sep 20, 2024
1 parent fb84b73 commit 68ad079
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions fido2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 68ad079

Please sign in to comment.