Skip to content

Commit

Permalink
Add option to list available configs
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Oct 3, 2024
1 parent 4fa7307 commit 3e60a66
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/nitrokey/trussed/admin_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AdminCommand(Enum):
SET_CONFIG = 0x83
FACTORY_RESET = 0x84
FACTORY_RESET_APP = 0x85
LIST_AVAILABLE_CONFIG = 0x86

def is_legacy_command(self) -> bool:
if self == AdminCommand.UPDATE:
Expand Down Expand Up @@ -150,6 +151,21 @@ def check(cls, i: int, msg: str) -> None:
raise Exception(f"{msg}: {error}")


class ConfigField:
name: str
requires_touch: bool
requires_reboot: bool
destructive: bool

def __init__(
self, name: str, requires_touch: bool, requires_reboot: bool, destructive: bool
):
self.name = name
self.requires_touch = requires_touch
self.requires_reboot = requires_reboot
self.destructive = destructive


class AdminApp:
def __init__(self, device: TrussedDevice) -> None:
self.device = device
Expand Down Expand Up @@ -266,6 +282,22 @@ def set_config(self, key: str, value: str) -> None:
assert reply
ConfigStatus.check(reply[0], "Failed to set config value")

def list_available_config(self) -> list[ConfigField]:
reply = self._call(AdminCommand.LIST_AVAILABLE_CONFIG)
parsed = cbor.decode(reply)
print(parsed)
ret = []
for field in parsed:
ret.append(
ConfigField(
field["name"],
field["requires_touch"],
field["requires_reboot"],
field["destructive"],
)
)
return ret

def factory_reset(self) -> bool:
try:
reply = self._call(AdminCommand.FACTORY_RESET, response_len=1)
Expand Down

0 comments on commit 3e60a66

Please sign in to comment.