mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-25 14:50:57 +00:00
apps.common: add protect_by_passphrase
This commit is contained in:
parent
d8f1b1397c
commit
059315feb4
@ -2,8 +2,9 @@ from trezor import ui, wire
|
|||||||
|
|
||||||
|
|
||||||
async def request_passphrase(session_id):
|
async def request_passphrase(session_id):
|
||||||
|
from trezor.messages.FailureType import ActionCancelled
|
||||||
from trezor.messages.PassphraseRequest import PassphraseRequest
|
from trezor.messages.PassphraseRequest import PassphraseRequest
|
||||||
from trezor.messages.wire_types import PassphraseAck
|
from trezor.messages.wire_types import PassphraseAck, Cancel
|
||||||
from trezor.ui.text import Text
|
from trezor.ui.text import Text
|
||||||
|
|
||||||
ui.display.clear()
|
ui.display.clear()
|
||||||
@ -11,5 +12,17 @@ async def request_passphrase(session_id):
|
|||||||
'Please enter passphrase', 'on your computer.')
|
'Please enter passphrase', 'on your computer.')
|
||||||
text.render()
|
text.render()
|
||||||
|
|
||||||
ack = await wire.call(session_id, PassphraseRequest(), PassphraseAck)
|
ack = await wire.call(session_id, PassphraseRequest(), PassphraseAck, Cancel)
|
||||||
|
if ack.MESSAGE_WIRE_TYPE == Cancel:
|
||||||
|
raise wire.FailureError(ActionCancelled, 'Passphrase cancelled')
|
||||||
|
|
||||||
return ack.passphrase
|
return ack.passphrase
|
||||||
|
|
||||||
|
|
||||||
|
async def protect_by_passphrase(session_id):
|
||||||
|
from apps.common import storage
|
||||||
|
|
||||||
|
if storage.is_protected_by_passphrase():
|
||||||
|
return await request_passphrase(session_id)
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
@ -22,7 +22,7 @@ async def get_seed(session_id: int) -> bytes:
|
|||||||
|
|
||||||
async def compute_seed(session_id: int) -> bytes:
|
async def compute_seed(session_id: int) -> bytes:
|
||||||
from trezor.messages.FailureType import Other
|
from trezor.messages.FailureType import Other
|
||||||
from .request_passphrase import request_passphrase
|
from .request_passphrase import protect_by_passphrase
|
||||||
from .request_pin import protect_by_pin
|
from .request_pin import protect_by_pin
|
||||||
from . import storage
|
from . import storage
|
||||||
|
|
||||||
@ -31,8 +31,5 @@ async def compute_seed(session_id: int) -> bytes:
|
|||||||
|
|
||||||
await protect_by_pin(session_id)
|
await protect_by_pin(session_id)
|
||||||
|
|
||||||
if storage.is_protected_by_passphrase():
|
passphrase = await protect_by_passphrase(session_id)
|
||||||
passphrase = await request_passphrase(session_id)
|
|
||||||
else:
|
|
||||||
passphrase = ''
|
|
||||||
return bip39.seed(storage.get_mnemonic(), passphrase)
|
return bip39.seed(storage.get_mnemonic(), passphrase)
|
||||||
|
Loading…
Reference in New Issue
Block a user