diff --git a/pynitrokey/nk3/admin_app.py b/pynitrokey/nk3/admin_app.py index 8cc44999..88681a85 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 @@ -6,6 +7,7 @@ from fido2 import cbor from fido2.ctap import CtapError +from pynitrokey.helpers import local_critical, local_print from pynitrokey.nk3.device import Command, Nitrokey3Device from .device import VERSION_LEN @@ -178,8 +180,15 @@ 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 + ) + return except OSError as e: if e.errno == 5: self.device.logger.debug("ignoring OSError after reboot", exc_info=e) @@ -189,10 +198,16 @@ 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, + ) + return FactoryResetStatus.check(reply[0], "Failed to factory reset the device")