Skip to content
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
2 changes: 1 addition & 1 deletion cryptnox_cli/command/change_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _execute(self, card: cryptnox_sdk_py.Card) -> int:
print("Card is in easy mode. Setting same PIN code")
pin_code = security.EASY_MODE_PIN
else:
pin_code = security.get_pin_code(card, f"Set new PIN code ({card.pin_rule}): ")
pin_code = security.confirm_pin_code(card, f"Set new PIN code ({card.pin_rule}): ")

card.change_pin(pin_code)

Expand Down
2 changes: 1 addition & 1 deletion cryptnox_cli/command/change_puk.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _execute(self, card: cryptnox_sdk_py.Card) -> int:
break
else:
puk_code = security.get_puk_code(card)
new_puk_code = security.get_puk_code(card, f"Set new PUK code ({card.puk_rule}): ")
new_puk_code = security.confirm_puk_code(card, f"Set new PUK code ({card.puk_rule}): ")

try:
card.change_puk(puk_code, new_puk_code)
Expand Down
28 changes: 28 additions & 0 deletions cryptnox_cli/command/helper/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,34 @@ def get_puk_code(card: cryptnox_sdk_py.Card, text: str = "", allowed_values: Lis
return _get_code(card.valid_puk, text, allowed_values)


def confirm_pin_code(card: cryptnox_sdk_py.Card, text: str, confirm_text: str = "") -> str:
"""Prompt for new PIN twice and return it only if both entries match."""
confirm_text = confirm_text or f"Confirm new PIN code ({card.pin_rule}): "
while True:
try:
value = get_pin_code(card, text)
confirm_value = get_pin_code(card, confirm_text)
except KeyboardInterrupt:
raise ExitException("Aborted.")
if value == confirm_value:
return value
print("The values do not match. Please try again.")


def confirm_puk_code(card: cryptnox_sdk_py.Card, text: str, confirm_text: str = "") -> str:
"""Prompt for new PUK twice and return it only if both entries match."""
confirm_text = confirm_text or f"Confirm new PUK code ({card.puk_rule}): "
while True:
try:
value = get_puk_code(card, text)
confirm_value = get_puk_code(card, confirm_text)
except KeyboardInterrupt:
raise ExitException("Aborted.")
if value == confirm_value:
return value
print("The values do not match. Please try again.")


def _get_code(
validation_method: typing.Callable,
text: str = "",
Expand Down
2 changes: 1 addition & 1 deletion cryptnox_cli/command/unlock_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def unblock_pin(card, puk):
if is_easy_mode:
pin_code = security.EASY_MODE_PIN
else:
pin_code = security.get_pin_code(card, f"Set card PIN code ({card.pin_rule}): ")
pin_code = security.confirm_pin_code(card, f"Set card PIN code ({card.pin_rule}): ")

card.unblock_pin(puk, pin_code)

Expand Down
Loading