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

Require authentication for partial restore #554

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion pynitrokey/cli/nethsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import click
import nethsm as nethsm_sdk
from click import Context
from nethsm import Authentication, Base64, NetHSM
from nethsm import Authentication, Base64, NetHSM, State
from nethsm.backup import EncryptedBackup

from pynitrokey.cli.exceptions import CliException
Expand Down Expand Up @@ -1446,7 +1446,13 @@ def restore(
support_hint=False,
)

require_auth = False
with connect(ctx, require_auth=False) as nethsm:
state = nethsm.get_state()
if state == State.OPERATIONAL:
require_auth = True

with connect(ctx, require_auth=require_auth) as nethsm:
with open(filename, "rb") as f:
nethsm.restore(data, backup_passphrase, system_time)
print(f"Backup restored on NetHSM {nethsm.host}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [
"protobuf >=3.17.3, < 4.0.0",
"click-aliases",
"semver",
"nethsm >=1.2.0, <2",
"nethsm >=1.2.1, <2",
]
dynamic = ["version", "description"]

Expand Down