Skip to content

Commit

Permalink
Add CLI handling for the update command
Browse files Browse the repository at this point in the history
  • Loading branch information
szszszsz committed Aug 12, 2023
1 parent 94421b3 commit 7fd8496
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
67 changes: 66 additions & 1 deletion pynitrokey/cli/nk3/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,71 @@ def call(app: SecretsApp) -> None:
local_print("Done")


@secrets.command()
@click.pass_obj
@click.argument(
"name",
type=click.STRING,
)
@click.option(
"--login",
"login",
type=click.STRING,
help="Password Safe Login",
default=None,
)
@click.option(
"--password",
"password",
type=click.STRING,
help="Password Safe Password",
default=None,
)
@click.option(
"--metadata",
"metadata",
type=click.STRING,
help="Password Safe Metadata - additional field, to which extra information can be encoded",
default=None,
)
@click.option(
"--touch-button",
"touch_button",
type=click.BOOL,
help="Activate/deactivate touch button requirement",
default=None,
)
def update(
ctx: Context,
name: str,
new_name: Optional[bytes] = None,
login: Optional[bytes] = None,
password: Optional[bytes] = None,
metadata: Optional[bytes] = None,
touch_button: Optional[bool] = None,
) -> None:
"""
Update credential. Change Static Password fields, or touch button requirement attribute.
"""
with ctx.connect_device() as device:
app = SecretsApp(device)
ask_to_touch_if_needed()

@repeat_if_pin_needed
def call(app: SecretsApp) -> None:
app.update_credential(
name.encode(),
cred_new_id=new_name,
login=login,
password=password,
metadata=metadata,
touch_button=touch_button,
)

call(app)
local_print("Done")


@secrets.command(aliases=["register"])
@click.pass_obj
@click.argument(
Expand Down Expand Up @@ -242,7 +307,7 @@ def call(app: SecretsApp) -> None:
"--metadata",
"metadata",
type=click.STRING,
help="Password Safe Metadata - additional field, to which extra information can be encoded in the future",
help="Password Safe Metadata - additional field, to which extra information can be encoded",
default=None,
)
def add_password(
Expand Down
3 changes: 2 additions & 1 deletion pynitrokey/nk3/secrets_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def update_credential(
structure = [
tlv8.Entry(Tag.CredentialId.value, cred_id),
tlv8.Entry(Tag.CredentialId.value, cred_new_id) if cred_new_id else None,
tlv8.Entry(Tag.Properties.value, b"\x01")
tlv8.Entry(Tag.Properties.value, b"\x01" if touch_button else b"\x00")
if touch_button is not None
else None,
tlv8.Entry(Tag.PwsLogin.value, login) if login is not None else None,
Expand All @@ -516,6 +516,7 @@ def update_credential(
if metadata is not None
else None,
]
structure = list(filter(lambda x: x is not None, structure))
self._send_receive(Instruction.UpdateCredential, structure=structure)

def delete(self, cred_id: bytes) -> None:
Expand Down

0 comments on commit 7fd8496

Please sign in to comment.