diff --git a/pynitrokey/cli/nk3/test.py b/pynitrokey/cli/nk3/test.py index d78001e7..cc1bf2fc 100644 --- a/pynitrokey/cli/nk3/test.py +++ b/pynitrokey/cli/nk3/test.py @@ -19,6 +19,7 @@ from types import TracebackType from typing import Any, Callable, Iterable, Optional, Tuple, Type, Union +from fido2.ctap import CtapError from tqdm import tqdm from pynitrokey.cli.exceptions import CliException @@ -353,6 +354,10 @@ def select(conn: CardConnection, aid: list[int]) -> bool: ] +class NotSupported: + pass + + @test_case("se050", "SE050") def test_se050(ctx: TestContext, device: Nitrokey3Base) -> TestResult: from queue import Queue @@ -369,8 +374,16 @@ def test_se050(ctx: TestContext, device: Nitrokey3Base) -> TestResult: que: Queue[Optional[bytes]] = Queue() - def internal_se050_run(q: Queue[Optional[bytes]]) -> None: - q.put(AdminApp(device).se050_tests()) + def internal_se050_run(q: Queue[Optional[bytes] | NotSupported]) -> None: + try: + q.put(AdminApp(device).se050_tests()) + except CtapError as e: + if e.code == CtapError.ERR.INVALID_LENGTH: + q.put(NotSupported) + else: + q.put(None) + except: + q.put(None) t = Thread(target=internal_se050_run, args=[que]) t.start() @@ -394,7 +407,14 @@ def internal_se050_run(q: Queue[Optional[bytes]]) -> None: bar.close() result = que.get() - if result is None or len(result) < 11: + print(result) + if result is NotSupported: + # This means that the device responded with `NotAvailable`, so either it is a version that doesn't support this feature or it was disabled at compile time + return TestResult( + TestStatus.SKIPPED, + "Testing SE050 functionality is not supported by the device", + ) + elif result is None or len(result) < 11: return TestResult(TestStatus.FAILURE, "Did not get test run data") major = result[0] minor = result[1]