Exemplo n.º 1
0
async def request_passphrase(ctx):
    from trezor.ui.text import Text
    from trezor.ui.entry_select import EntrySelector

    ui.display.clear()
    text = Text('Enter passphrase', ui.ICON_RESET, 'Where to enter your',
                'passphrase?')
    entry = EntrySelector(text)
    entry_type = await entry

    on_device = (entry_type == 0)

    from trezor.messages.FailureType import ActionCancelled, ProcessError
    from trezor.messages.PassphraseRequest import PassphraseRequest
    from trezor.messages.wire_types import PassphraseAck, Cancel

    ui.display.clear()

    pass_req = PassphraseRequest()

    if on_device:
        pass_req.on_device = True
    else:
        from trezor.ui.text import Text
        text = Text('Passphrase entry', ui.ICON_RESET,
                    'Please, type passphrase', 'on connected host.')
        text.render()

    ack = await ctx.call(pass_req, PassphraseAck, Cancel)
    if ack.MESSAGE_WIRE_TYPE == Cancel:
        raise wire.FailureError(ActionCancelled, 'Passphrase cancelled')

    if on_device:
        if ack.passphrase is not None:
            raise wire.FailureError(
                ProcessError, 'Passphrase provided when it should not be')
        from trezor.ui.passphrase import PassphraseKeyboard, CANCELLED
        passphrase = await PassphraseKeyboard('Enter passphrase')
        if passphrase == CANCELLED:
            raise wire.FailureError(ActionCancelled, 'Passphrase cancelled')
    else:
        if ack.passphrase is None:
            raise wire.FailureError(ProcessError, 'Passphrase not provided')
        passphrase = ack.passphrase

    # TODO: process ack.state and check against the current device state, throw error if different

    return passphrase
Exemplo n.º 2
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
async def _request_on_host(ctx: wire.Context) -> str:
    _entry_dialog()

    request = PassphraseRequest()
    ack = await ctx.call(request, PassphraseAck)
    if ack.on_device:
        if ack.passphrase is not None:
            raise wire.DataError("Passphrase provided when it should not be")
        return await _request_on_device(ctx)

    if ack.passphrase is None:
        raise wire.DataError(
            "Passphrase not provided and on_device is False. Use empty string to set an empty passphrase."
        )

    # non-empty passphrase
    if ack.passphrase:
        text = Text("Hidden wallet", ICON_CONFIG)
        text.normal("Access hidden wallet?")
        text.br()
        text.normal("Next screen will show")
        text.normal("the passphrase!")
        await require_confirm(ctx, text, ButtonRequestType.Other)

        text = Text("Hidden wallet", ICON_CONFIG)
        text.normal("Use this passphrase?")
        text.br()
        text.mono(ack.passphrase)
        await require_confirm(ctx, text, ButtonRequestType.Other)

    return ack.passphrase
Exemplo n.º 6
0
async def _request_on_host(ctx: wire.Context) -> str:
    _entry_dialog()

    request = PassphraseRequest()
    ack = await ctx.call(request, PassphraseAck)
    if ack.on_device:
        if ack.passphrase is not None:
            raise wire.DataError("Passphrase provided when it should not be")
        return await _request_on_device(ctx)

    if ack.passphrase is None:
        raise wire.DataError(
            "Passphrase not provided and on_device is False. Use empty string to set an empty passphrase."
        )
    return ack.passphrase
Exemplo n.º 7
0
async def request_passphrase_on_host(ctx):
    from trezor.messages.FailureType import ActionCancelled
    from trezor.messages.PassphraseRequest import PassphraseRequest
    from trezor.messages.wire_types import PassphraseAck, Cancel
    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
Exemplo n.º 8
0
async def request_passphrase(session_id):
    from trezor.messages.FailureType import ActionCancelled
    from trezor.messages.PassphraseRequest import PassphraseRequest
    from trezor.messages.wire_types import PassphraseAck, Cancel
    from trezor.ui.text import Text

    ui.display.clear()
    text = Text('Enter passphrase', ui.ICON_RESET,
                'Please enter passphrase', 'on your computer.')
    text.render()

    ack = await wire.call(session_id, PassphraseRequest(), PassphraseAck, Cancel)
    if ack.MESSAGE_WIRE_TYPE == Cancel:
        raise wire.FailureError(ActionCancelled, 'Passphrase cancelled')

    return ack.passphrase