From e65d9a2d237145e0c589f3542c02431daf5091e0 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 9 Dec 2024 15:42:39 +0100 Subject: [PATCH] fido2: Apply flake8 lints --- Makefile | 9 ++++++++- pynitrokey/fido2/__init__.py | 6 +++--- pynitrokey/fido2/client.py | 29 ++++++----------------------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 2c66654c..b32799b6 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/pynitrokey/fido2/__init__.py b/pynitrokey/fido2/__init__.py index 57ba664a..098b477e 100644 --- a/pynitrokey/fido2/__init__.py +++ b/pynitrokey/fido2/__init__.py @@ -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 diff --git a/pynitrokey/fido2/client.py b/pynitrokey/fido2/client.py index 78d6ab4b..ea0537d6 100644 --- a/pynitrokey/fido2/client.py +++ b/pynitrokey/fido2/client.py @@ -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: @@ -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: @@ -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 @@ -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()) @@ -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