You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/src/apps/management/change_pin.py

61 lines
2.0 KiB

from trezor import config, ui, wire
from trezor.messages.Success import Success
from trezor.pin import pin_to_int
from trezor.ui.text import Text
6 years ago
from apps.common.confirm import require_confirm
from apps.common.request_pin import request_pin_and_sd_salt, request_pin_confirm
if False:
from trezor.messages.ChangePin import ChangePin
async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
# confirm that user wants to change the pin
await require_confirm_change_pin(ctx, msg)
# get old pin
curpin, salt = await request_pin_and_sd_salt(ctx, "Enter old PIN")
# if changing pin, pre-check the entered pin before getting new pin
if curpin and not msg.remove:
if not config.check_pin(pin_to_int(curpin), salt):
raise wire.PinInvalid("PIN invalid")
# get new pin
if not msg.remove:
newpin = await request_pin_confirm(ctx)
else:
6 years ago
newpin = ""
# write into storage
if not config.change_pin(pin_to_int(curpin), pin_to_int(newpin), salt, salt):
6 years ago
raise wire.PinInvalid("PIN invalid")
if newpin:
6 years ago
return Success(message="PIN changed")
else:
6 years ago
return Success(message="PIN removed")
def require_confirm_change_pin(ctx: wire.Context, msg: ChangePin) -> None:
has_pin = config.has_pin()
if msg.remove and has_pin: # removing pin
6 years ago
text = Text("Remove PIN", ui.ICON_CONFIG)
text.normal("Do you really want to")
text.bold("disable PIN protection?")
return require_confirm(ctx, text)
if not msg.remove and has_pin: # changing pin
text = Text("Change PIN", ui.ICON_CONFIG)
6 years ago
text.normal("Do you really want to")
text.bold("change your PIN?")
return require_confirm(ctx, text)
if not msg.remove and not has_pin: # setting new pin
text = Text("Enable PIN", ui.ICON_CONFIG)
6 years ago
text.normal("Do you really want to")
text.bold("enable PIN protection?")
return require_confirm(ctx, text)