2018-02-05 19:26:13 +00:00
|
|
|
from trezor import res, ui, wire
|
2016-10-20 13:04:54 +00:00
|
|
|
|
|
|
|
|
2018-02-05 19:26:13 +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
|
2018-02-05 19:26:13 +00:00
|
|
|
|
|
|
|
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
|
2018-02-05 19:26:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2018-02-05 19:26:13 +00:00
|
|
|
|
|
|
|
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
|
2018-01-29 18:26:42 +00:00
|
|
|
from trezor.ui.entry_select import EntrySelector
|
2016-10-20 13:04:54 +00:00
|
|
|
|
|
|
|
ui.display.clear()
|
2018-02-05 19:26:13 +00:00
|
|
|
text = Text(
|
|
|
|
'Enter passphrase', ui.ICON_RESET,
|
|
|
|
'Where to enter your', 'passphrase?')
|
2018-01-29 18:26:42 +00:00
|
|
|
entry = EntrySelector(text)
|
|
|
|
entry_type = await entry
|
|
|
|
|
|
|
|
if entry_type == 1:
|
2018-02-05 19:26:13 +00:00
|
|
|
return await request_passphrase_on_host(ctx)
|
2018-01-29 18:26:42 +00:00
|
|
|
else:
|
2018-02-05 19:26:13 +00:00
|
|
|
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 ''
|