Ejemplo n.º 1
0
def _start_progress() -> None:
    from trezor.ui.layouts import draw_simple_text

    # Because we are drawing to the screen manually, without a layout, we
    # should make sure that no other layout is running.
    workflow.close_others()
    draw_simple_text("Please wait")
Ejemplo n.º 2
0
async def get_firmware(ctx: Context, _msg: GetFirmware) -> Success:
    await confirm_action(
        ctx,
        "dump_firmware",
        title="Extract firmware",
        action="Do you want to extract device firmware?",
        description="Your seed will not be revealed.",
    )
    sector_buffer = bytearray(CHUNK_SIZE)
    packet = FirmwareChunk(chunk=sector_buffer)

    workflow.close_others()
    draw_simple_text("Please wait")

    progress = 0
    _render_progress(progress, PROGRESS_TOTAL)
    for i in range(utils.FIRMWARE_SECTORS_COUNT):
        size = utils.firmware_sector_size(i)
        try:
            for ofs in range(0, size, CHUNK_SIZE):
                utils.get_firmware_chunk(i, ofs, sector_buffer)
                await ctx.call(packet, FirmwareChunkAck)
                progress += CHUNK_SIZE
                _render_progress(progress, PROGRESS_TOTAL)
            # reset progress to known point, in case some sectors are not 128 kB
            progress = (i + 1) * 128 * 1024
            _render_progress(progress, PROGRESS_TOTAL)
        except ValueError:
            raise wire.DataError("Failed to dump firmware.")
    return Success(message="Firmware dumped.")
Ejemplo n.º 3
0
async def button_request(
    ctx: wire.GenericContext,
    br_type: str,
    code: ButtonRequestType = ButtonRequestType.Other,
) -> None:
    if __debug__:
        log.debug(__name__, "ButtonRequest.type=%s", br_type)
    workflow.close_others()
    await ctx.call(ButtonRequest(code=code), ButtonAck)
Ejemplo n.º 4
0
async def interact(
    ctx: wire.GenericContext,
    layout: LayoutType,
    brtype: str,
    brcode: EnumTypeButtonRequestType = ButtonRequestType.Other,
) -> Any:
    log.debug(__name__, "ButtonRequest.type={}".format(brtype))
    workflow.close_others()
    await ctx.call(ButtonRequest(code=brcode), ButtonAck)
    return await ctx.wait(layout)
Ejemplo n.º 5
0
async def get_firmware_hash(ctx: Context, msg: GetFirmwareHash) -> FirmwareHash:
    workflow.close_others()
    draw_simple_text("Please wait")

    try:
        hash = firmware_hash(msg.challenge, _render_progress)
    except ValueError as e:
        raise wire.DataError(str(e))

    return FirmwareHash(hash=hash)
Ejemplo n.º 6
0
async def _request_from_user(ctx: wire.Context) -> str:
    workflow.close_others()  # request exclusive UI access
    if storage.device.get_passphrase_always_on_device():
        passphrase = await _request_on_device(ctx)
    else:
        passphrase = await _request_on_host(ctx)
    if len(passphrase.encode()) > _MAX_PASSPHRASE_LEN:
        raise wire.DataError("Maximum passphrase length is %d bytes" %
                             _MAX_PASSPHRASE_LEN)

    return passphrase
Ejemplo n.º 7
0
    async def interact(
        self,
        ctx: wire.GenericContext,
        code: ButtonRequestType = ButtonRequestType.Other,
    ) -> Any:
        workflow.close_others()
        await ctx.call(ButtonRequest(code=code, pages=len(self.pages)),
                       ButtonAck)
        result = WAS_PAGED
        while result is WAS_PAGED:
            result = await ctx.wait(self)

        return result
Ejemplo n.º 8
0
async def button_request(
    ctx: wire.GenericContext,
    br_type: str,
    code: ButtonRequestType = ButtonRequestType.Other,
    pages: int | None = None,
) -> None:
    if __debug__:
        log.debug(__name__, "ButtonRequest.type=%s", br_type)
    workflow.close_others()
    if pages is not None:
        await ctx.call(ButtonRequest(code=code, pages=pages), ButtonAck)
    else:
        await ctx.call(ButtonRequest(code=code), ButtonAck)
Ejemplo n.º 9
0
def lock_device() -> None:
    if config.has_pin():
        config.lock()
        wire.find_handler = get_pinlocked_handler
        set_homescreen()
        workflow.close_others()
Ejemplo n.º 10
0
def _start_progress() -> None:
    # Because we are drawing to the screen manually, without a layout, we
    # should make sure that no other layout is running.
    workflow.close_others()
    t = Text("Please wait", ui.ICON_CONFIG)
    ui.draw_simple(t)
Ejemplo n.º 11
0
def report_init() -> None:
    workflow.close_others()
    ui.display.clear()
    ui.header("Signing transaction")
Ejemplo n.º 12
0
async def button_request(
        ctx: wire.GenericContext,
        code: EnumTypeButtonRequestType = ButtonRequestType.Other) -> None:
    workflow.close_others()
    await ctx.call(ButtonRequest(code=code), ButtonAck)