1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 16:48:09 +00:00
trezor-firmware/src/apps/common/request_passphrase.py

56 lines
1.7 KiB
Python
Raw Normal View History

from trezor import res, ui, wire
2016-10-20 13:04:54 +00:00
async def request_passphrase_on_display(ctx):
from trezor.messages.FailureType import ActionCancelled
2018-02-06 02:01:04 +00:00
from trezor.ui.passphrase import PassphraseKeyboard, CANCELLED
ui.display.clear()
2018-02-06 02:01:04 +00:00
passphrase = await PassphraseKeyboard('Enter passphrase')
if passphrase == CANCELLED:
raise wire.FailureError(ActionCancelled, 'Passphrase cancelled')
return passphrase
async def request_passphrase_on_host(ctx):
2017-01-24 13:10:36 +00:00
from trezor.messages.FailureType import ActionCancelled
2016-10-20 13:04:54 +00:00
from trezor.messages.PassphraseRequest import PassphraseRequest
2017-01-24 13:10:36 +00:00
from trezor.messages.wire_types import PassphraseAck, Cancel
2016-10-20 13:04:54 +00:00
from trezor.ui.text import Text
text = Text(
'Passphrase entry', ui.ICON_RESET,
'Please, type passphrase', 'on connected host.')
ui.display.clear()
text.render()
ack = await ctx.call(PassphraseRequest(), PassphraseAck, Cancel)
if ack.MESSAGE_WIRE_TYPE == Cancel:
raise wire.FailureError(ActionCancelled, 'Passphrase cancelled')
return ack.passphrase
async def request_passphrase(ctx):
from trezor.ui.text import Text
from trezor.ui.entry_select import EntrySelector
2016-10-20 13:04:54 +00:00
ui.display.clear()
text = Text(
'Enter passphrase', ui.ICON_RESET,
'Where to enter your', 'passphrase?')
entry = EntrySelector(text)
entry_type = await entry
if entry_type == 1:
return await request_passphrase_on_host(ctx)
else:
return await request_passphrase_on_display(ctx)
2017-01-24 13:10:36 +00:00
2017-08-15 13:09:09 +00:00
async def protect_by_passphrase(ctx):
2017-01-24 13:10:36 +00:00
from apps.common import storage
2017-10-24 11:58:40 +00:00
if storage.has_passphrase():
2017-08-15 13:09:09 +00:00
return await request_passphrase(ctx)
2017-01-24 13:10:36 +00:00
else:
return ''