Skip to content

Commit

Permalink
Decide based on state if authentication is required for restore
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerklinger committed Jul 24, 2024
1 parent 174d462 commit cc4cdf1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 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 @@ -1416,6 +1416,13 @@ def restore(
)

with connect(ctx, require_auth=False) as nethsm:
state = nethsm.get_state()
if state == State.UNPROVISIONED:
require_auth = False
elif 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

0 comments on commit cc4cdf1

Please sign in to comment.