1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 23:38:09 +00:00

Revert "feat(core): implement firmware dumping"

This reverts commit 37c61c1381.
This commit is contained in:
matejcik 2022-08-01 16:29:46 +02:00 committed by matejcik
parent 4df7f2f6b0
commit a6410693b3
13 changed files with 2 additions and 198 deletions

View File

@ -252,28 +252,6 @@ message FirmwareHash {
required bytes hash = 1;
}
/**
* Request: get firmware image. The firmware will send all chunks in sequence.
* @start
* @next FirmwareChunk
*/
message GetFirmware {}
/**
* Response: firmware chunk.
* @next FirmwareChunkAck
*/
message FirmwareChunk {
required bytes chunk = 1;
}
/**
* Request: acknowledge firmware chunk.
* @next FirmwareChunk
* @next Success
*/
message FirmwareChunkAck {}
/**
* Request: Request device to wipe all sensitive data and settings
* @start

View File

@ -116,9 +116,7 @@ enum MessageType {
MessageType_RebootToBootloader = 87 [(bitcoin_only) = true, (wire_in) = true];
MessageType_GetFirmwareHash = 88 [(bitcoin_only) = true, (wire_in) = true];
MessageType_FirmwareHash = 89 [(bitcoin_only) = true, (wire_out) = true];
MessageType_GetFirmware = 90 [(bitcoin_only) = true, (wire_in) = true];
MessageType_FirmwareChunk = 91 [(bitcoin_only) = true, (wire_out) = true];
MessageType_FirmwareChunkAck = 92 [(bitcoin_only) = true, (wire_in) = true];
reserved 90 to 92;
MessageType_SetU2FCounter = 63 [(wire_in) = true];
MessageType_GetNextU2FCounter = 80 [(wire_in) = true];

View File

@ -0,0 +1 @@
Remove firmware dumping capability.

View File

@ -208,46 +208,6 @@ STATIC mp_obj_t mod_trezorutils_firmware_vendor(void) {
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_firmware_vendor_obj,
mod_trezorutils_firmware_vendor);
/// def firmware_sector_size(sector: int) -> int:
/// """
/// Returns the size of the firmware sector.
/// """
STATIC mp_obj_t mod_trezorutils_firmware_sector_size(mp_obj_t sector) {
mp_uint_t sector_id = trezor_obj_get_uint(sector);
if (sector_id >= FIRMWARE_SECTORS_COUNT) {
mp_raise_msg(&mp_type_ValueError, "Invalid sector.");
}
return mp_obj_new_int(flash_sector_size(FIRMWARE_SECTORS[sector_id]));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_firmware_sector_size_obj,
mod_trezorutils_firmware_sector_size);
/// def get_firmware_chunk(index: int, offset: int, buffer: bytearray) -> None:
/// """
/// Reads a chunk of the firmware into `buffer`.
/// """
STATIC mp_obj_t mod_trezorutils_get_firmware_chunk(const mp_obj_t index_obj,
const mp_obj_t offset_obj,
const mp_obj_t buffer) {
mp_uint_t index = trezor_obj_get_uint(index_obj);
if (index >= FIRMWARE_SECTORS_COUNT) {
mp_raise_msg(&mp_type_ValueError, "Invalid sector.");
}
int sector = FIRMWARE_SECTORS[index];
mp_uint_t offset = trezor_obj_get_uint(offset_obj);
mp_buffer_info_t buf = {0};
mp_get_buffer_raise(buffer, &buf, MP_BUFFER_WRITE);
const void *data = flash_get_address(sector, offset, buf.len);
if (data == NULL) {
mp_raise_msg(&mp_type_ValueError, "Invalid read.");
}
memcpy(buf.buf, data, buf.len);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorutils_get_firmware_chunk_obj,
mod_trezorutils_get_firmware_chunk);
/// def reboot_to_bootloader() -> None:
/// """
/// Reboots to bootloader.
@ -271,7 +231,6 @@ STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
/// MODEL: str
/// EMULATOR: bool
/// BITCOIN_ONLY: bool
/// FIRMWARE_SECTORS_COUNT: int
STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorutils)},
@ -282,12 +241,6 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
MP_ROM_PTR(&mod_trezorutils_firmware_hash_obj)},
{MP_ROM_QSTR(MP_QSTR_firmware_vendor),
MP_ROM_PTR(&mod_trezorutils_firmware_vendor_obj)},
{MP_ROM_QSTR(MP_QSTR_get_firmware_chunk),
MP_ROM_PTR(&mod_trezorutils_get_firmware_chunk_obj)},
{MP_ROM_QSTR(MP_QSTR_firmware_sector_size),
MP_ROM_PTR(&mod_trezorutils_firmware_sector_size_obj)},
{MP_ROM_QSTR(MP_QSTR_FIRMWARE_SECTORS_COUNT),
MP_ROM_INT(FIRMWARE_SECTORS_COUNT)},
{MP_ROM_QSTR(MP_QSTR_reboot_to_bootloader),
MP_ROM_PTR(&mod_trezorutils_reboot_to_bootloader_obj)},
// various built-in constants

View File

@ -60,20 +60,6 @@ def firmware_vendor() -> str:
"""
# extmod/modtrezorutils/modtrezorutils.c
def firmware_sector_size(sector: int) -> int:
"""
Returns the size of the firmware sector.
"""
# extmod/modtrezorutils/modtrezorutils.c
def get_firmware_chunk(index: int, offset: int, buffer: bytearray) -> None:
"""
Reads a chunk of the firmware into `buffer`.
"""
# extmod/modtrezorutils/modtrezorutils.c
def reboot_to_bootloader() -> None:
"""
@ -86,4 +72,3 @@ VERSION_PATCH: int
MODEL: str
EMULATOR: bool
BITCOIN_ONLY: bool
FIRMWARE_SECTORS_COUNT: int

View File

@ -401,8 +401,6 @@ apps.misc.get_ecdh_session_key
import apps.misc.get_ecdh_session_key
apps.misc.get_entropy
import apps.misc.get_entropy
apps.misc.get_firmware
import apps.misc.get_firmware
apps.misc.get_firmware_hash
import apps.misc.get_firmware_hash
apps.misc.sign_identity

View File

@ -1,47 +0,0 @@
from micropython import const
from typing import TYPE_CHECKING
from trezor import utils, wire, workflow
from trezor.messages import FirmwareChunk, FirmwareChunkAck, GetFirmware, Success
from trezor.ui.layouts import confirm_action, draw_simple_text
from .get_firmware_hash import _render_progress
if TYPE_CHECKING:
from trezor.wire import Context
CHUNK_SIZE = const(1024 * 4)
# assuming that all sectors are of size 128 kB
PROGRESS_TOTAL = utils.FIRMWARE_SECTORS_COUNT * 128 * 1024
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.")

View File

@ -84,8 +84,6 @@ def find_message_handler_module(msg_type: int) -> str:
return "apps.misc.cipher_key_value"
if msg_type == MessageType.GetFirmwareHash:
return "apps.misc.get_firmware_hash"
if msg_type == MessageType.GetFirmware:
return "apps.misc.get_firmware"
if not utils.BITCOIN_ONLY:
if msg_type == MessageType.SetU2FCounter:

View File

@ -43,9 +43,6 @@ CancelAuthorization = 86
RebootToBootloader = 87
GetFirmwareHash = 88
FirmwareHash = 89
GetFirmware = 90
FirmwareChunk = 91
FirmwareChunkAck = 92
FirmwareErase = 6
FirmwareUpload = 7
FirmwareRequest = 8

View File

@ -60,9 +60,6 @@ if TYPE_CHECKING:
RebootToBootloader = 87
GetFirmwareHash = 88
FirmwareHash = 89
GetFirmware = 90
FirmwareChunk = 91
FirmwareChunkAck = 92
SetU2FCounter = 63
GetNextU2FCounter = 80
NextU2FCounter = 81

View File

@ -2276,32 +2276,6 @@ if TYPE_CHECKING:
def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["FirmwareHash"]:
return isinstance(msg, cls)
class GetFirmware(protobuf.MessageType):
@classmethod
def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["GetFirmware"]:
return isinstance(msg, cls)
class FirmwareChunk(protobuf.MessageType):
chunk: "bytes"
def __init__(
self,
*,
chunk: "bytes",
) -> None:
pass
@classmethod
def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["FirmwareChunk"]:
return isinstance(msg, cls)
class FirmwareChunkAck(protobuf.MessageType):
@classmethod
def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["FirmwareChunkAck"]:
return isinstance(msg, cls)
class WipeDevice(protobuf.MessageType):
@classmethod

View File

@ -3,7 +3,6 @@ import sys
from trezorutils import ( # noqa: F401
BITCOIN_ONLY,
EMULATOR,
FIRMWARE_SECTORS_COUNT,
MODEL,
SCM_REVISION,
VERSION_MAJOR,
@ -11,9 +10,7 @@ from trezorutils import ( # noqa: F401
VERSION_PATCH,
consteq,
firmware_hash,
firmware_sector_size,
firmware_vendor,
get_firmware_chunk,
halt,
memcpy,
reboot_to_bootloader,

View File

@ -68,9 +68,6 @@ class MessageType(IntEnum):
RebootToBootloader = 87
GetFirmwareHash = 88
FirmwareHash = 89
GetFirmware = 90
FirmwareChunk = 91
FirmwareChunkAck = 92
SetU2FCounter = 63
GetNextU2FCounter = 80
NextU2FCounter = 81
@ -3333,28 +3330,6 @@ class FirmwareHash(protobuf.MessageType):
self.hash = hash
class GetFirmware(protobuf.MessageType):
MESSAGE_WIRE_TYPE = 90
class FirmwareChunk(protobuf.MessageType):
MESSAGE_WIRE_TYPE = 91
FIELDS = {
1: protobuf.Field("chunk", "bytes", repeated=False, required=True),
}
def __init__(
self,
*,
chunk: "bytes",
) -> None:
self.chunk = chunk
class FirmwareChunkAck(protobuf.MessageType):
MESSAGE_WIRE_TYPE = 92
class WipeDevice(protobuf.MessageType):
MESSAGE_WIRE_TYPE = 5