diff --git a/pynitrokey/nk3/admin_app.py b/pynitrokey/nk3/admin_app.py index 8cc44999..7b6ca5a3 100644 --- a/pynitrokey/nk3/admin_app.py +++ b/pynitrokey/nk3/admin_app.py @@ -1,4 +1,5 @@ import enum +import sys from dataclasses import dataclass from enum import Enum, IntFlag from typing import Optional @@ -7,6 +8,7 @@ from fido2.ctap import CtapError from pynitrokey.nk3.device import Command, Nitrokey3Device +from pynitrokey.helpers import local_critical, local_print from .device import VERSION_LEN from .utils import Version @@ -178,8 +180,10 @@ def set_config(self, key: str, value: str) -> None: def factory_reset(self) -> None: try: + local_print("Please touch the device to confirm the operation", file=sys.stderr) reply = self._call(AdminCommand.FACTORY_RESET, response_len=1) - assert reply + if reply is None: + local_critical("Factory reset is not supported by the device", support_hint=False) except OSError as e: if e.errno == 5: self.device.logger.debug("ignoring OSError after reboot", exc_info=e) @@ -189,10 +193,12 @@ def factory_reset(self) -> None: FactoryResetStatus.check(reply[0], "Failed to factory reset the device") def factory_reset_app(self, application: str) -> None: + local_print("Please touch the device to confirm the operation", file=sys.stderr) reply = self._call( AdminCommand.FACTORY_RESET_APP, data=application.encode("ascii"), response_len=1, ) - assert reply + if reply is None: + local_critical("Application Factory reset is not supported by the device", support_hint=False) FactoryResetStatus.check(reply[0], "Failed to factory reset the device")