mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-09 15:00:58 +00:00
Merge pull request #555 from trezor/andrewkozlik/pin-dialogs
Show success and failure dialogs in change-pin.
This commit is contained in:
commit
3b7ea25eeb
@ -112,3 +112,11 @@ async def verify_user_pin(
|
|||||||
prompt = "Wrong PIN, enter again"
|
prompt = "Wrong PIN, enter again"
|
||||||
|
|
||||||
raise PinInvalid
|
raise PinInvalid
|
||||||
|
|
||||||
|
|
||||||
|
async def show_pin_invalid(ctx: wire.Context) -> None:
|
||||||
|
from apps.common.confirm import confirm
|
||||||
|
|
||||||
|
text = Text("Wrong PIN", ui.ICON_WRONG, ui.RED)
|
||||||
|
text.normal("The PIN you entered is", "invalid.")
|
||||||
|
await confirm(ctx, text, confirm=None, cancel="Close")
|
||||||
|
@ -29,9 +29,9 @@ async def wrong_card_dialog(ctx: Optional[wire.Context]) -> None:
|
|||||||
text.br_half()
|
text.br_half()
|
||||||
text.normal("Please unplug the", "device and insert a", "different card.")
|
text.normal("Please unplug the", "device and insert a", "different card.")
|
||||||
if ctx is None:
|
if ctx is None:
|
||||||
await Confirm(text, confirm=None)
|
await Confirm(text, confirm=None, cancel="Close")
|
||||||
else:
|
else:
|
||||||
await require_confirm(ctx, text, confirm=None)
|
await require_confirm(ctx, text, confirm=None, cancel="Close")
|
||||||
|
|
||||||
|
|
||||||
async def insert_card_dialog(ctx: Optional[wire.Context]) -> None:
|
async def insert_card_dialog(ctx: Optional[wire.Context]) -> None:
|
||||||
@ -40,9 +40,9 @@ async def insert_card_dialog(ctx: Optional[wire.Context]) -> None:
|
|||||||
text.br_half()
|
text.br_half()
|
||||||
text.normal("Please unplug the", "device and insert your", "SD card.")
|
text.normal("Please unplug the", "device and insert your", "SD card.")
|
||||||
if ctx is None:
|
if ctx is None:
|
||||||
await Confirm(text, confirm=None)
|
await Confirm(text, confirm=None, cancel="Close")
|
||||||
else:
|
else:
|
||||||
await require_confirm(ctx, text, confirm=None)
|
await require_confirm(ctx, text, confirm=None, cancel="Close")
|
||||||
|
|
||||||
|
|
||||||
async def request_sd_salt(
|
async def request_sd_salt(
|
||||||
|
@ -4,7 +4,12 @@ from trezor.pin import pin_to_int
|
|||||||
from trezor.ui.text import Text
|
from trezor.ui.text import Text
|
||||||
|
|
||||||
from apps.common.confirm import require_confirm
|
from apps.common.confirm import require_confirm
|
||||||
from apps.common.request_pin import request_pin_and_sd_salt, request_pin_confirm
|
from apps.common.layout import show_success
|
||||||
|
from apps.common.request_pin import (
|
||||||
|
request_pin_and_sd_salt,
|
||||||
|
request_pin_confirm,
|
||||||
|
show_pin_invalid,
|
||||||
|
)
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from trezor.messages.ChangePin import ChangePin
|
from trezor.messages.ChangePin import ChangePin
|
||||||
@ -20,6 +25,7 @@ async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
|
|||||||
# if changing pin, pre-check the entered pin before getting new pin
|
# if changing pin, pre-check the entered pin before getting new pin
|
||||||
if curpin and not msg.remove:
|
if curpin and not msg.remove:
|
||||||
if not config.check_pin(pin_to_int(curpin), salt):
|
if not config.check_pin(pin_to_int(curpin), salt):
|
||||||
|
await show_pin_invalid(ctx)
|
||||||
raise wire.PinInvalid("PIN invalid")
|
raise wire.PinInvalid("PIN invalid")
|
||||||
|
|
||||||
# get new pin
|
# get new pin
|
||||||
@ -30,12 +36,22 @@ async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
|
|||||||
|
|
||||||
# write into storage
|
# write into storage
|
||||||
if not config.change_pin(pin_to_int(curpin), pin_to_int(newpin), salt, salt):
|
if not config.change_pin(pin_to_int(curpin), pin_to_int(newpin), salt, salt):
|
||||||
|
await show_pin_invalid(ctx)
|
||||||
raise wire.PinInvalid("PIN invalid")
|
raise wire.PinInvalid("PIN invalid")
|
||||||
|
|
||||||
if newpin:
|
if newpin:
|
||||||
return Success(message="PIN changed")
|
if curpin:
|
||||||
|
msg_screen = "changed your PIN."
|
||||||
|
msg_wire = "PIN changed"
|
||||||
else:
|
else:
|
||||||
return Success(message="PIN removed")
|
msg_screen = "enabled PIN protection."
|
||||||
|
msg_wire = "PIN enabled"
|
||||||
|
else:
|
||||||
|
msg_screen = "disabled PIN protection."
|
||||||
|
msg_wire = "PIN removed"
|
||||||
|
|
||||||
|
await show_success(ctx, ("You have successfully", msg_screen))
|
||||||
|
return Success(message=msg_wire)
|
||||||
|
|
||||||
|
|
||||||
def require_confirm_change_pin(ctx: wire.Context, msg: ChangePin) -> None:
|
def require_confirm_change_pin(ctx: wire.Context, msg: ChangePin) -> None:
|
||||||
|
@ -6,7 +6,11 @@ from trezor.ui.text import Text
|
|||||||
|
|
||||||
from apps.common import storage
|
from apps.common import storage
|
||||||
from apps.common.confirm import require_confirm
|
from apps.common.confirm import require_confirm
|
||||||
from apps.common.request_pin import request_pin_and_sd_salt, request_pin_confirm
|
from apps.common.request_pin import (
|
||||||
|
request_pin_and_sd_salt,
|
||||||
|
request_pin_confirm,
|
||||||
|
show_pin_invalid,
|
||||||
|
)
|
||||||
from apps.management.recovery_device.homescreen import recovery_process
|
from apps.management.recovery_device.homescreen import recovery_process
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
@ -28,6 +32,7 @@ async def recovery_device(ctx: wire.Context, msg: RecoveryDevice) -> Success:
|
|||||||
if msg.dry_run:
|
if msg.dry_run:
|
||||||
curpin, salt = await request_pin_and_sd_salt(ctx, "Enter PIN")
|
curpin, salt = await request_pin_and_sd_salt(ctx, "Enter PIN")
|
||||||
if not config.check_pin(pin_to_int(curpin), salt):
|
if not config.check_pin(pin_to_int(curpin), salt):
|
||||||
|
await show_pin_invalid(ctx)
|
||||||
raise wire.PinInvalid("PIN invalid")
|
raise wire.PinInvalid("PIN invalid")
|
||||||
|
|
||||||
# set up pin if requested
|
# set up pin if requested
|
||||||
|
@ -7,7 +7,12 @@ from trezor.pin import pin_to_int
|
|||||||
from trezor.ui.text import Text
|
from trezor.ui.text import Text
|
||||||
|
|
||||||
from apps.common.confirm import require_confirm
|
from apps.common.confirm import require_confirm
|
||||||
from apps.common.request_pin import request_pin_ack, request_pin_and_sd_salt
|
from apps.common.layout import show_success
|
||||||
|
from apps.common.request_pin import (
|
||||||
|
request_pin_ack,
|
||||||
|
request_pin_and_sd_salt,
|
||||||
|
show_pin_invalid,
|
||||||
|
)
|
||||||
from apps.common.sd_salt import (
|
from apps.common.sd_salt import (
|
||||||
SD_SALT_AUTH_KEY_LEN_BYTES,
|
SD_SALT_AUTH_KEY_LEN_BYTES,
|
||||||
SD_SALT_AUTH_TAG_LEN_BYTES,
|
SD_SALT_AUTH_TAG_LEN_BYTES,
|
||||||
@ -71,10 +76,12 @@ async def sd_protect_enable(ctx: wire.Context, msg: SdProtect) -> Success:
|
|||||||
# SD-protection. If it fails for any reason, we suppress the
|
# SD-protection. If it fails for any reason, we suppress the
|
||||||
# exception, because primarily we need to raise wire.PinInvalid.
|
# exception, because primarily we need to raise wire.PinInvalid.
|
||||||
pass
|
pass
|
||||||
|
await show_pin_invalid(ctx)
|
||||||
raise wire.PinInvalid("PIN invalid")
|
raise wire.PinInvalid("PIN invalid")
|
||||||
|
|
||||||
device.set_sd_salt_auth_key(salt_auth_key)
|
device.set_sd_salt_auth_key(salt_auth_key)
|
||||||
|
|
||||||
|
await show_success(ctx, ("You have successfully", "enabled SD protection."))
|
||||||
return Success(message="SD card protection enabled")
|
return Success(message="SD card protection enabled")
|
||||||
|
|
||||||
|
|
||||||
@ -90,6 +97,7 @@ async def sd_protect_disable(ctx: wire.Context, msg: SdProtect) -> Success:
|
|||||||
|
|
||||||
# Check PIN and remove salt.
|
# Check PIN and remove salt.
|
||||||
if not config.change_pin(pin_to_int(pin), pin_to_int(pin), salt, None):
|
if not config.change_pin(pin_to_int(pin), pin_to_int(pin), salt, None):
|
||||||
|
await show_pin_invalid(ctx)
|
||||||
raise wire.PinInvalid("PIN invalid")
|
raise wire.PinInvalid("PIN invalid")
|
||||||
|
|
||||||
device.set_sd_salt_auth_key(None)
|
device.set_sd_salt_auth_key(None)
|
||||||
@ -103,6 +111,7 @@ async def sd_protect_disable(ctx: wire.Context, msg: SdProtect) -> Success:
|
|||||||
# because overall SD-protection was successfully disabled.
|
# because overall SD-protection was successfully disabled.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
await show_success(ctx, ("You have successfully", "disabled SD protection."))
|
||||||
return Success(message="SD card protection disabled")
|
return Success(message="SD card protection disabled")
|
||||||
|
|
||||||
|
|
||||||
@ -128,6 +137,7 @@ async def sd_protect_refresh(ctx: wire.Context, msg: SdProtect) -> Success:
|
|||||||
raise wire.ProcessError("Failed to write to SD card")
|
raise wire.ProcessError("Failed to write to SD card")
|
||||||
|
|
||||||
if not config.change_pin(pin_to_int(pin), pin_to_int(pin), old_salt, new_salt):
|
if not config.change_pin(pin_to_int(pin), pin_to_int(pin), old_salt, new_salt):
|
||||||
|
await show_pin_invalid(ctx)
|
||||||
raise wire.PinInvalid("PIN invalid")
|
raise wire.PinInvalid("PIN invalid")
|
||||||
|
|
||||||
device.set_sd_salt_auth_key(new_salt_auth_key)
|
device.set_sd_salt_auth_key(new_salt_auth_key)
|
||||||
@ -141,6 +151,7 @@ async def sd_protect_refresh(ctx: wire.Context, msg: SdProtect) -> Success:
|
|||||||
# SD-protection was successfully refreshed.
|
# SD-protection was successfully refreshed.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
await show_success(ctx, ("You have successfully", "refreshed SD protection."))
|
||||||
return Success(message="SD card protection refreshed")
|
return Success(message="SD card protection refreshed")
|
||||||
|
|
||||||
|
|
||||||
|
@ -599,7 +599,7 @@ class U2fConfirmRegister(U2fState):
|
|||||||
text.normal(
|
text.normal(
|
||||||
"Another U2F device", "was used to register", "in this application."
|
"Another U2F device", "was used to register", "in this application."
|
||||||
)
|
)
|
||||||
return await confirm(text, confirm=None)
|
return await confirm(text, confirm=None, cancel="Close")
|
||||||
else:
|
else:
|
||||||
content = ConfirmContent(self)
|
content = ConfirmContent(self)
|
||||||
return await confirm(content)
|
return await confirm(content)
|
||||||
@ -724,7 +724,7 @@ class Fido2ConfirmExcluded(Fido2ConfirmMakeCredential):
|
|||||||
|
|
||||||
text = Text("FIDO2 Register", ui.ICON_WRONG, ui.RED)
|
text = Text("FIDO2 Register", ui.ICON_WRONG, ui.RED)
|
||||||
text.normal("This device is already", "registered with", self._cred.rp_id + ".")
|
text.normal("This device is already", "registered with", self._cred.rp_id + ".")
|
||||||
await confirm(text, confirm=None)
|
await confirm(text, confirm=None, cancel="Close")
|
||||||
|
|
||||||
|
|
||||||
class Fido2ConfirmGetAssertion(Fido2State, ConfirmInfo, Pageable):
|
class Fido2ConfirmGetAssertion(Fido2State, ConfirmInfo, Pageable):
|
||||||
@ -797,7 +797,7 @@ class Fido2ConfirmNoPin(State):
|
|||||||
async def confirm_dialog(self) -> bool:
|
async def confirm_dialog(self) -> bool:
|
||||||
text = Text("FIDO2 Verify User", ui.ICON_WRONG, ui.RED)
|
text = Text("FIDO2 Verify User", ui.ICON_WRONG, ui.RED)
|
||||||
text.normal("Unable to verify user.", "Please enable PIN", "protection.")
|
text.normal("Unable to verify user.", "Please enable PIN", "protection.")
|
||||||
return await confirm(text, confirm=None)
|
return await confirm(text, confirm=None, cancel="Close")
|
||||||
|
|
||||||
|
|
||||||
class Fido2ConfirmNoCredentials(Fido2ConfirmGetAssertion):
|
class Fido2ConfirmNoCredentials(Fido2ConfirmGetAssertion):
|
||||||
@ -814,7 +814,7 @@ class Fido2ConfirmNoCredentials(Fido2ConfirmGetAssertion):
|
|||||||
text.normal(
|
text.normal(
|
||||||
"This device is not", "registered with", self._creds[0].app_name() + "."
|
"This device is not", "registered with", self._creds[0].app_name() + "."
|
||||||
)
|
)
|
||||||
await confirm(text, confirm=None)
|
await confirm(text, confirm=None, cancel="Close")
|
||||||
|
|
||||||
|
|
||||||
class Fido2ConfirmReset(Fido2State):
|
class Fido2ConfirmReset(Fido2State):
|
||||||
|
@ -42,7 +42,7 @@ async def add_resident_credential(
|
|||||||
"not belong to this",
|
"not belong to this",
|
||||||
"authenticator.",
|
"authenticator.",
|
||||||
)
|
)
|
||||||
await require_confirm(ctx, text, confirm=None)
|
await require_confirm(ctx, text, confirm=None, cancel="Close")
|
||||||
raise wire.ActionCancelled("Cancelled")
|
raise wire.ActionCancelled("Cancelled")
|
||||||
|
|
||||||
content = ConfirmContent(ConfirmAddCredential(cred))
|
content = ConfirmContent(ConfirmAddCredential(cred))
|
||||||
|
@ -35,6 +35,9 @@ def _input_flow_set_pin(debug, pin):
|
|||||||
yield # enter new pin again
|
yield # enter new pin again
|
||||||
print(f"reenter pin {pin}")
|
print(f"reenter pin {pin}")
|
||||||
debug.input(pin)
|
debug.input(pin)
|
||||||
|
yield # success
|
||||||
|
print("success")
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
|
||||||
def _input_flow_change_pin(debug, old_pin, new_pin):
|
def _input_flow_change_pin(debug, old_pin, new_pin):
|
||||||
@ -46,6 +49,8 @@ def _input_flow_change_pin(debug, old_pin, new_pin):
|
|||||||
debug.input(new_pin)
|
debug.input(new_pin)
|
||||||
yield # enter new pin again
|
yield # enter new pin again
|
||||||
debug.input(new_pin)
|
debug.input(new_pin)
|
||||||
|
yield # success
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
|
||||||
def _input_flow_clear_pin(debug, old_pin):
|
def _input_flow_clear_pin(debug, old_pin):
|
||||||
@ -53,6 +58,8 @@ def _input_flow_clear_pin(debug, old_pin):
|
|||||||
debug.press_yes()
|
debug.press_yes()
|
||||||
yield # enter current pin
|
yield # enter current pin
|
||||||
debug.input(old_pin)
|
debug.input(old_pin)
|
||||||
|
yield # success
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
|
||||||
def _check_pin(client, pin):
|
def _check_pin(client, pin):
|
||||||
@ -61,7 +68,7 @@ def _check_pin(client, pin):
|
|||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 4 + [messages.Success(), messages.Features()]
|
[messages.ButtonRequest()] * 5 + [messages.Success(), messages.Features()]
|
||||||
)
|
)
|
||||||
client.set_input_flow(_input_flow_change_pin(client.debug, pin, pin))
|
client.set_input_flow(_input_flow_change_pin(client.debug, pin, pin))
|
||||||
device.change_pin(client)
|
device.change_pin(client)
|
||||||
@ -77,9 +84,9 @@ def _check_no_pin(client):
|
|||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 3
|
[messages.ButtonRequest()] * 4
|
||||||
+ [messages.Success(), messages.Features()]
|
+ [messages.Success(), messages.Features()]
|
||||||
+ [messages.ButtonRequest()] * 2
|
+ [messages.ButtonRequest()] * 3
|
||||||
+ [messages.Success(), messages.Features()]
|
+ [messages.Success(), messages.Features()]
|
||||||
)
|
)
|
||||||
client.set_input_flow(input_flow)
|
client.set_input_flow(input_flow)
|
||||||
@ -98,7 +105,7 @@ def test_set_pin(client):
|
|||||||
# Let's set new PIN
|
# Let's set new PIN
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 3 + [messages.Success(), messages.Features()]
|
[messages.ButtonRequest()] * 4 + [messages.Success(), messages.Features()]
|
||||||
)
|
)
|
||||||
client.set_input_flow(_input_flow_set_pin(client.debug, PIN6))
|
client.set_input_flow(_input_flow_set_pin(client.debug, PIN6))
|
||||||
|
|
||||||
@ -119,7 +126,7 @@ def test_change_pin(client):
|
|||||||
# Let's change PIN
|
# Let's change PIN
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 4 + [messages.Success(), messages.Features()]
|
[messages.ButtonRequest()] * 5 + [messages.Success(), messages.Features()]
|
||||||
)
|
)
|
||||||
client.set_input_flow(_input_flow_change_pin(client.debug, PIN4, PIN6))
|
client.set_input_flow(_input_flow_change_pin(client.debug, PIN4, PIN6))
|
||||||
|
|
||||||
@ -142,7 +149,7 @@ def test_remove_pin(client):
|
|||||||
# Let's remove PIN
|
# Let's remove PIN
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 2 + [messages.Success(), messages.Features()]
|
[messages.ButtonRequest()] * 3 + [messages.Success(), messages.Features()]
|
||||||
)
|
)
|
||||||
client.set_input_flow(_input_flow_clear_pin(client.debug, PIN4))
|
client.set_input_flow(_input_flow_clear_pin(client.debug, PIN4))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user