mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-16 17:42:02 +00:00
core: Show success and failure dialogs in change-pin.
This commit is contained in:
parent
b9e7e93bcf
commit
de74750569
@ -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")
|
||||||
|
@ -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:
|
||||||
|
msg_screen = "enabled PIN protection."
|
||||||
|
msg_wire = "PIN enabled"
|
||||||
else:
|
else:
|
||||||
return Success(message="PIN removed")
|
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,11 @@ 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.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,6 +75,7 @@ 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)
|
||||||
@ -90,6 +95,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)
|
||||||
@ -128,6 +134,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)
|
||||||
|
@ -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