Skip to content

Commit

Permalink
Implement per-app factory reset
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Nov 15, 2023
1 parent 47d7522 commit 92e6a3a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pynitrokey/cli/nk3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,14 @@ def factory_reset(ctx: Context) -> None:
with ctx.connect_device() as device:
device.factory_reset()

@nk3.command()
@click.pass_obj
@click.argument("application", type=click.STRING, required=True)
def factory_reset_app(ctx: Context, application: str) -> None:
"""Factory reset all functionnality of the device"""
with ctx.connect_device() as device:
device.factory_reset_app(application)


@nk3.command()
@click.pass_obj
Expand Down
5 changes: 5 additions & 0 deletions pynitrokey/nk3/admin_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AdminCommand(Enum):
GET_CONFIG = 0x82
SET_CONFIG = 0x83
FACTORY_RESET = 0x84
FACTORY_RESET_APP = 0x85


@enum.unique
Expand Down Expand Up @@ -186,3 +187,7 @@ def factory_reset(self) -> None:
else:
raise e
FactoryResetStatus.check(reply[0], "Failed to factory reset the device")
def factory_reset_app(self, application) -> None:
reply = self._call(AdminCommand.FACTORY_RESET_APP, data=application.encode("ascii"), response_len=1)
assert reply
FactoryResetStatus.check(reply[0], "Failed to factory reset the device")
3 changes: 3 additions & 0 deletions pynitrokey/nk3/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def version(self) -> Version:
def factory_reset(self) -> None:
self.admin.factory_reset()

def factory_reset_app(self, app: str) -> None:
self.admin.factory_reset_app(app)

def wink(self) -> None:
self.device.wink()

Expand Down

0 comments on commit 92e6a3a

Please sign in to comment.