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

Update nethsm dependency #469

Merged
merged 2 commits into from
Nov 24, 2023
Merged

Update nethsm dependency #469

merged 2 commits into from
Nov 24, 2023

Conversation

robin-nitrokey
Copy link
Member

@robin-nitrokey robin-nitrokey commented Nov 14, 2023

This update pulls in multiple relevant changes, mainly:

  • The auto-generated client is only loaded if required. This improves execution times significantly, especially for simple commands.
  • Key certificates are now always stored as raw bytes, not as strings, so the get-certificate and set-certificate commands had to be updated.
  • Changing the backup and unlock passphrases now requires passing the current passphrase.
  • Using enums instead of strings.
  • Using stronger types and dataclasses for some methods.
  • NetHSM API changes that are not visible in the public Python API.

On my machine, this reduces the execution time for simple commands like version or --help from 0.9 s to 0.3 s.

This update pulls in multiple relevant changes, mainly:
- The auto-generated client is only loaded if required.  This improves
  execution times significantly, especially for simple commands.
- Key certificates are now always stored as raw bytes, not as strings,
  so the get-certificate and set-certificate commands had to be updated.
- Changing the backup and unlock passphrases now requires passing the
  current passphrase.
- Using enums instead of strings.
- Using stronger types and dataclasses for some methods.
- NetHSM API changes that are not visible in the public Python API.

On my machine, this reduces the execution time for simple commands like
version or --help from 0.9 s to 0.3 s.
@robin-nitrokey
Copy link
Member Author

This also enables strict typing checks for the nethsm CLI module so that updates will hopefully be easier in the future.

@jans23
Copy link
Member

jans23 commented Nov 24, 2023

The latest API Spec contains three warnings. Could these or similar warnings be shown when calling the appropriate commands?

This patch adds warnings to the provision, set-backup-passphrase and
set-unlock-passphrase commands that explain that the passphrases cannot
be reset without knowing the old value.

It also adds confirmation prompts to set-backup-passphrase and
set-unlock-passphrase after the warning is shown.
@@ -835,6 +849,18 @@ def set_backup_passphrase(

This command requires authentication as a user with the Administrator
role."""

print(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this warning should only be printed if the force flag is false. But may this is more a matter of taste.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be conservative here: Always printing the warning doesn’t cost us anything, but it could still help to prevent mistakes.

) -> None:
"""Set the unlock passphrase of a NetHSM.

Changing the unlock passphrase requires the current passphrase.

This command requires authentication as a user with the Administrator
role."""

print(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this warning should only be printed if the force flag is false. But may this is more a matter of taste.

@@ -983,9 +1059,12 @@ def get_certificate(ctx, api, key_id):
with connect(ctx) as nethsm:
if key_id:
cert = nethsm.get_key_certificate(key_id)
try:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A user should be able to store arbitrary byte strings for which the .decode() call may not necessarily succeeds.
Using .decode() here limits the byte strings the user can store.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If decode fails, we print the raw bytes (see the except block). The alternative would be to always print e. g. the hex representation, but I think that would be confusing for most use cases.

@robin-nitrokey robin-nitrokey merged commit e5100cd into master Nov 24, 2023
10 checks passed
@robin-nitrokey robin-nitrokey deleted the nethsm branch November 24, 2023 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants