Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to list available configs #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 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,38 @@ 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)
# Function not supported, return values for 1.7.0 release
if not reply:
return [
ConfigField(
"fido.disable_skip_up_timeout",
False,
False,
False,
),
ConfigField(
"opcard.use_se050_backend",
True,
True,
True,
),
]
parsed = cbor.decode(reply)
assert isinstance(parsed, list)
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