async def respond_Features(ctx, msg): if msg.__qualname__ == 'Initialize': if msg.state is None or msg.state != cache.get_state(salt=msg.state[:32]): cache.clear() f = Features() f.vendor = 'trezor.io' f.major_version = symbol('VERSION_MAJOR') f.minor_version = symbol('VERSION_MINOR') f.patch_version = symbol('VERSION_PATCH') f.device_id = storage.get_device_id() f.pin_protection = config.has_pin() f.passphrase_protection = storage.has_passphrase() f.language = 'english' f.label = storage.get_label() f.coins = coins.COINS f.initialized = storage.is_initialized() f.revision = symbol('GITREV') f.pin_cached = config.has_pin() f.passphrase_cached = cache.has_passphrase() f.needs_backup = storage.needs_backup() f.flags = storage.get_flags() f.model = 'T' f.state = cache.get_state() return f
async def respond_Features(ctx, msg): from apps.common import storage, coins, cache from trezor.messages.Features import Features if msg.__qualname__ == 'Initialize': if msg.state is None or msg.state != cache.get_state(): cache.clear() f = Features() f.vendor = 'trezor.io' f.revision = '0123456789' f.bootloader_hash = '0123456789' f.major_version = 2 f.minor_version = 0 f.patch_version = 0 f.model = 'T' f.coins = coins.COINS f.device_id = storage.get_device_id() f.label = storage.get_label() f.initialized = storage.is_initialized() f.passphrase_protection = storage.has_passphrase() f.pin_protection = config.has_pin() f.language = 'english' f.state = cache.get_state() return f
async def request_passphrase_ack(ctx: wire.Context, on_device: bool) -> str: if not on_device: text = Text("Passphrase entry", ui.ICON_CONFIG) text.normal("Please, type passphrase", "on connected host.") await Popup(text) req = PassphraseRequest(on_device=on_device) ack = await ctx.call(req, PassphraseAck) if on_device: if ack.passphrase is not None: raise wire.ProcessError( "Passphrase provided when it should not be") keyboard = PassphraseKeyboard("Enter passphrase", _MAX_PASSPHRASE_LEN) if __debug__: passphrase = await ctx.wait(keyboard, input_signal()) else: passphrase = await ctx.wait(keyboard) if passphrase is CANCELLED: raise wire.ActionCancelled("Passphrase cancelled") else: if ack.passphrase is None: raise wire.ProcessError("Passphrase not provided") passphrase = ack.passphrase state = cache.get_state(prev_state=ack.state, passphrase=passphrase) req = PassphraseStateRequest(state=state) ack = await ctx.call(req, PassphraseStateAck) return passphrase
async def request_passphrase_ack(ctx, on_device): if not on_device: text = Text('Passphrase entry', ui.ICON_CONFIG, 'Please, type passphrase', 'on connected host.') text.render() req = PassphraseRequest(on_device=on_device) ack = await ctx.call(req, wire_types.PassphraseAck, wire_types.Cancel) if ack.MESSAGE_WIRE_TYPE == wire_types.Cancel: raise wire.ActionCancelled('Passphrase cancelled') if on_device: if ack.passphrase is not None: raise wire.ProcessError( 'Passphrase provided when it should not be') keyboard = PassphraseKeyboard('Enter passphrase') passphrase = await ctx.wait(keyboard) if passphrase == CANCELLED: raise wire.ActionCancelled('Passphrase cancelled') else: if ack.passphrase is None: raise wire.ProcessError('Passphrase not provided') passphrase = ack.passphrase req = PassphraseStateRequest( state=get_state(prev_state=ack.state, passphrase=passphrase)) ack = await ctx.call(req, wire_types.PassphraseStateAck, wire_types.Cancel) return passphrase
async def handle_Initialize(ctx: wire.Context, msg: Initialize) -> Features: if msg.state is None or msg.state != cache.get_state( prev_state=bytes(msg.state)): cache.clear() if msg.skip_passphrase: cache.set_passphrase("") return get_features()
async def request_passphrase_ack(ctx, on_device): if not on_device: text = Text("Passphrase entry", ui.ICON_CONFIG) text.normal("Please, type passphrase", "on connected host.") text.render() req = PassphraseRequest(on_device=on_device) ack = await ctx.call(req, MessageType.PassphraseAck, MessageType.Cancel) if ack.MESSAGE_WIRE_TYPE == MessageType.Cancel: raise wire.ActionCancelled("Passphrase cancelled") if on_device: if ack.passphrase is not None: raise wire.ProcessError( "Passphrase provided when it should not be") keyboard = PassphraseKeyboard("Enter passphrase") passphrase = await ctx.wait(keyboard) if passphrase == CANCELLED: raise wire.ActionCancelled("Passphrase cancelled") else: if ack.passphrase is None: raise wire.ProcessError("Passphrase not provided") passphrase = ack.passphrase req = PassphraseStateRequest( state=get_state(prev_state=ack.state, passphrase=passphrase)) ack = await ctx.call(req, MessageType.PassphraseStateAck, MessageType.Cancel) return passphrase
async def respond_Features(ctx, msg): if msg.__qualname__ == 'Initialize': if msg.state is None or bytes( msg.state) != cache.get_state(state=bytes(msg.state)): cache.clear() f = Features() f.vendor = 'trezor.io' f.major_version = symbol('VERSION_MAJOR') f.minor_version = symbol('VERSION_MINOR') f.patch_version = symbol('VERSION_PATCH') f.device_id = storage.get_device_id() f.pin_protection = config.has_pin() f.passphrase_protection = storage.has_passphrase() f.language = 'english' f.label = storage.get_label() f.initialized = storage.is_initialized() f.revision = symbol('GITREV') f.pin_cached = config.has_pin() f.passphrase_cached = cache.has_passphrase() f.needs_backup = storage.needs_backup() f.flags = storage.get_flags() if model() in ['T', 'EMU']: # emulator currently emulates model T f.model = 'T' f.unfinished_backup = storage.unfinished_backup() return f
async def request_passphrase(ctx): on_device = await request_passphrase_entry(ctx) == DEVICE state, passphrase = await request_passphrase_ack(ctx, on_device) if state is not None: if state != get_state(salt=state[:32], passphrase=passphrase): raise wire.FailureError(ProcessError, 'Passphrase mismatch') return passphrase
async def handle_Initialize(ctx, msg): if msg.state is None or msg.state != cache.get_state( prev_state=bytes(msg.state)): cache.clear(msg.skip_passphrase) return get_features()