Skip to content

Commit

Permalink
fido2: Apply flake8 lints
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-nitrokey committed Dec 9, 2024
1 parent d55b9cf commit e65d9a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ PYTHON3=python3
PYTHON3_VENV=venv/bin/python3

# whitelist of directories for flake8
FLAKE8_DIRS=pynitrokey/cli/fido2.py pynitrokey/cli/nk3 pynitrokey/cli/nkfido2.py pynitrokey/cli/nkpk.py pynitrokey/cli/trussed
FLAKE8_DIRS=\
pynitrokey/cli/fido2.py \
pynitrokey/cli/nk3 \
pynitrokey/cli/nkfido2.py \
pynitrokey/cli/nkpk.py \
pynitrokey/cli/trussed \
pynitrokey/fido2/__init__.py \
pynitrokey/fido2/client.py

all: init

Expand Down
6 changes: 3 additions & 3 deletions pynitrokey/fido2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import time
from typing import Any, Callable, List, Optional, Union
from typing import List, Optional, Union

import usb
from fido2.hid import CtapHidDevice, open_device
from fido2.hid import CtapHidDevice

from pynitrokey.exceptions import NonUniqueDeviceError, NoSoloFoundError
from pynitrokey.exceptions import NoSoloFoundError

# from pynitrokey.fido2 import hmac_secret
from pynitrokey.fido2.client import NKFido2Client
Expand Down
29 changes: 6 additions & 23 deletions pynitrokey/fido2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,23 @@
# copied, modified, or distributed except according to those terms.

import base64
import binascii
import hashlib
import json
import secrets
import struct
import sys
import tempfile
import time
from typing import Any, Callable, List, Optional, Tuple, Union
from typing import Optional, Tuple, Union

from fido2.client import Fido2Client
from fido2.cose import ES256, EdDSA
from fido2.ctap import CtapError
from fido2.ctap1 import Ctap1
from fido2.ctap2.base import Ctap2
from fido2.ctap2.pin import ClientPin
from fido2.hid import CTAPHID, CtapHidDevice, open_device
from fido2.webauthn import (
AuthenticatorSelectionCriteria,
PublicKeyCredentialCreationOptions,
PublicKeyCredentialParameters,
PublicKeyCredentialRpEntity,
PublicKeyCredentialType,
PublicKeyCredentialUserEntity,
ResidentKeyRequirement,
UserVerificationRequirement,
)
from intelhex import IntelHex

import pynitrokey.exceptions
import pynitrokey.fido2 as nkfido2
from pynitrokey import helpers
from pynitrokey.fido2.commands import SoloBootloader, SoloExtension
from pynitrokey.helpers import local_critical, local_print
from pynitrokey.helpers import local_critical


class NKFido2Client:
Expand Down Expand Up @@ -104,7 +87,7 @@ def find_device(

try:
self.ctap2: Optional[Ctap2] = Ctap2(self.dev)
except CtapError as e:
except CtapError:
self.ctap2 = None

if self.exchange == self.exchange_hid:
Expand Down Expand Up @@ -253,7 +236,7 @@ def is_bootloader(self) -> bool:
pass
else:
raise (e)
except Exception as e:
except Exception:
# exception during bootloader version check, assume no bootloader
# local_print("could not get bootloader version")
pass
Expand All @@ -273,7 +256,7 @@ def enter_st_dfu(self) -> None:
else:
self.send_only_hid(SoloBootloader.HIDCommandEnterSTBoot, b"")

def program_file(self, name: str) -> bytes:
def program_file(self, name: str) -> bytes: # noqa: C901
def parseField(f: str) -> bytes:
return base64.b64decode(helpers.from_websafe(f).encode())

Expand Down Expand Up @@ -308,7 +291,7 @@ def isCorrectVersion(current: Tuple[int, int, int], target: str) -> bool:
if "versions" in firmware_file_data:
current = (0, 0, 0)
try:
current = self.bootloader_version()
current = self.bootloader_version() # noqa: F841
except CtapError as e:
if e.code == CtapError.ERR.INVALID_COMMAND:
pass
Expand Down

0 comments on commit e65d9a2

Please sign in to comment.