chore(core): allow DebugLinkGetState to access data from specific thp channel

[no changelog]
M1nd3r/thp1
M1nd3r 1 month ago
parent 1f8bb906d3
commit 38cc5de6f3

@ -92,6 +92,7 @@ message DebugLinkGetState {
optional bool wait_word_list = 1; // Trezor T only - wait until mnemonic words are shown optional bool wait_word_list = 1; // Trezor T only - wait until mnemonic words are shown
optional bool wait_word_pos = 2; // Trezor T only - wait until reset word position is requested optional bool wait_word_pos = 2; // Trezor T only - wait until reset word position is requested
optional bool wait_layout = 3; // wait until current layout changes optional bool wait_layout = 3; // wait until current layout changes
optional uint32 thp_channel_id=4; // THP only - used to get information from particular channel
} }
/** /**

@ -206,12 +206,21 @@ if __debug__:
m.passphrase_protection = passphrase.is_enabled() m.passphrase_protection = passphrase.is_enabled()
m.reset_entropy = storage.reset_internal_entropy m.reset_entropy = storage.reset_internal_entropy
if utils.USE_THP: channel_id = msg.thp_channel_id
from trezor.wire.context import get_context if utils.USE_THP and channel_id is not None:
from trezor.wire.thp.pairing_context import PairingContext
ctx = get_context() from trezor.wire.thp.channel import Channel
if isinstance(ctx, PairingContext): from trezor.wire.thp.pairing_context import PairingContext
from trezor.wire.thp_main import _CHANNELS
channel: Channel | None = None
ctx: PairingContext | None = None
try:
channel = _CHANNELS[channel_id]
ctx = channel.connection_context
except KeyError:
pass
if ctx is not None and isinstance(ctx, PairingContext):
m.thp_pairing_secret = ctx.secret m.thp_pairing_secret = ctx.secret
m.thp_pairing_code_entry_code = ctx.display_data.code_code_entry m.thp_pairing_code_entry_code = ctx.display_data.code_code_entry

@ -2832,6 +2832,7 @@ if TYPE_CHECKING:
wait_word_list: "bool | None" wait_word_list: "bool | None"
wait_word_pos: "bool | None" wait_word_pos: "bool | None"
wait_layout: "bool | None" wait_layout: "bool | None"
thp_channel_id: "int | None"
def __init__( def __init__(
self, self,
@ -2839,6 +2840,7 @@ if TYPE_CHECKING:
wait_word_list: "bool | None" = None, wait_word_list: "bool | None" = None,
wait_word_pos: "bool | None" = None, wait_word_pos: "bool | None" = None,
wait_layout: "bool | None" = None, wait_layout: "bool | None" = None,
thp_channel_id: "int | None" = None,
) -> None: ) -> None:
pass pass

@ -4055,6 +4055,7 @@ class DebugLinkGetState(protobuf.MessageType):
1: protobuf.Field("wait_word_list", "bool", repeated=False, required=False, default=None), 1: protobuf.Field("wait_word_list", "bool", repeated=False, required=False, default=None),
2: protobuf.Field("wait_word_pos", "bool", repeated=False, required=False, default=None), 2: protobuf.Field("wait_word_pos", "bool", repeated=False, required=False, default=None),
3: protobuf.Field("wait_layout", "bool", repeated=False, required=False, default=None), 3: protobuf.Field("wait_layout", "bool", repeated=False, required=False, default=None),
4: protobuf.Field("thp_channel_id", "uint32", repeated=False, required=False, default=None),
} }
def __init__( def __init__(
@ -4063,10 +4064,12 @@ class DebugLinkGetState(protobuf.MessageType):
wait_word_list: Optional["bool"] = None, wait_word_list: Optional["bool"] = None,
wait_word_pos: Optional["bool"] = None, wait_word_pos: Optional["bool"] = None,
wait_layout: Optional["bool"] = None, wait_layout: Optional["bool"] = None,
thp_channel_id: Optional["int"] = None,
) -> None: ) -> None:
self.wait_word_list = wait_word_list self.wait_word_list = wait_word_list
self.wait_word_pos = wait_word_pos self.wait_word_pos = wait_word_pos
self.wait_layout = wait_layout self.wait_layout = wait_layout
self.thp_channel_id = thp_channel_id
class DebugLinkState(protobuf.MessageType): class DebugLinkState(protobuf.MessageType):

@ -1128,6 +1128,8 @@ pub struct DebugLinkGetState {
pub wait_word_pos: ::std::option::Option<bool>, pub wait_word_pos: ::std::option::Option<bool>,
// @@protoc_insertion_point(field:hw.trezor.messages.debug.DebugLinkGetState.wait_layout) // @@protoc_insertion_point(field:hw.trezor.messages.debug.DebugLinkGetState.wait_layout)
pub wait_layout: ::std::option::Option<bool>, pub wait_layout: ::std::option::Option<bool>,
// @@protoc_insertion_point(field:hw.trezor.messages.debug.DebugLinkGetState.thp_channel_id)
pub thp_channel_id: ::std::option::Option<u32>,
// special fields // special fields
// @@protoc_insertion_point(special_field:hw.trezor.messages.debug.DebugLinkGetState.special_fields) // @@protoc_insertion_point(special_field:hw.trezor.messages.debug.DebugLinkGetState.special_fields)
pub special_fields: ::protobuf::SpecialFields, pub special_fields: ::protobuf::SpecialFields,
@ -1201,8 +1203,27 @@ impl DebugLinkGetState {
self.wait_layout = ::std::option::Option::Some(v); self.wait_layout = ::std::option::Option::Some(v);
} }
// optional uint32 thp_channel_id = 4;
pub fn thp_channel_id(&self) -> u32 {
self.thp_channel_id.unwrap_or(0)
}
pub fn clear_thp_channel_id(&mut self) {
self.thp_channel_id = ::std::option::Option::None;
}
pub fn has_thp_channel_id(&self) -> bool {
self.thp_channel_id.is_some()
}
// Param is passed by value, moved
pub fn set_thp_channel_id(&mut self, v: u32) {
self.thp_channel_id = ::std::option::Option::Some(v);
}
fn generated_message_descriptor_data() -> ::protobuf::reflect::GeneratedMessageDescriptorData { fn generated_message_descriptor_data() -> ::protobuf::reflect::GeneratedMessageDescriptorData {
let mut fields = ::std::vec::Vec::with_capacity(3); let mut fields = ::std::vec::Vec::with_capacity(4);
let mut oneofs = ::std::vec::Vec::with_capacity(0); let mut oneofs = ::std::vec::Vec::with_capacity(0);
fields.push(::protobuf::reflect::rt::v2::make_option_accessor::<_, _>( fields.push(::protobuf::reflect::rt::v2::make_option_accessor::<_, _>(
"wait_word_list", "wait_word_list",
@ -1219,6 +1240,11 @@ impl DebugLinkGetState {
|m: &DebugLinkGetState| { &m.wait_layout }, |m: &DebugLinkGetState| { &m.wait_layout },
|m: &mut DebugLinkGetState| { &mut m.wait_layout }, |m: &mut DebugLinkGetState| { &mut m.wait_layout },
)); ));
fields.push(::protobuf::reflect::rt::v2::make_option_accessor::<_, _>(
"thp_channel_id",
|m: &DebugLinkGetState| { &m.thp_channel_id },
|m: &mut DebugLinkGetState| { &mut m.thp_channel_id },
));
::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<DebugLinkGetState>( ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<DebugLinkGetState>(
"DebugLinkGetState", "DebugLinkGetState",
fields, fields,
@ -1246,6 +1272,9 @@ impl ::protobuf::Message for DebugLinkGetState {
24 => { 24 => {
self.wait_layout = ::std::option::Option::Some(is.read_bool()?); self.wait_layout = ::std::option::Option::Some(is.read_bool()?);
}, },
32 => {
self.thp_channel_id = ::std::option::Option::Some(is.read_uint32()?);
},
tag => { tag => {
::protobuf::rt::read_unknown_or_skip_group(tag, is, self.special_fields.mut_unknown_fields())?; ::protobuf::rt::read_unknown_or_skip_group(tag, is, self.special_fields.mut_unknown_fields())?;
}, },
@ -1267,6 +1296,9 @@ impl ::protobuf::Message for DebugLinkGetState {
if let Some(v) = self.wait_layout { if let Some(v) = self.wait_layout {
my_size += 1 + 1; my_size += 1 + 1;
} }
if let Some(v) = self.thp_channel_id {
my_size += ::protobuf::rt::uint32_size(4, v);
}
my_size += ::protobuf::rt::unknown_fields_size(self.special_fields.unknown_fields()); my_size += ::protobuf::rt::unknown_fields_size(self.special_fields.unknown_fields());
self.special_fields.cached_size().set(my_size as u32); self.special_fields.cached_size().set(my_size as u32);
my_size my_size
@ -1282,6 +1314,9 @@ impl ::protobuf::Message for DebugLinkGetState {
if let Some(v) = self.wait_layout { if let Some(v) = self.wait_layout {
os.write_bool(3, v)?; os.write_bool(3, v)?;
} }
if let Some(v) = self.thp_channel_id {
os.write_uint32(4, v)?;
}
os.write_unknown_fields(self.special_fields.unknown_fields())?; os.write_unknown_fields(self.special_fields.unknown_fields())?;
::std::result::Result::Ok(()) ::std::result::Result::Ok(())
} }
@ -1302,6 +1337,7 @@ impl ::protobuf::Message for DebugLinkGetState {
self.wait_word_list = ::std::option::Option::None; self.wait_word_list = ::std::option::Option::None;
self.wait_word_pos = ::std::option::Option::None; self.wait_word_pos = ::std::option::Option::None;
self.wait_layout = ::std::option::Option::None; self.wait_layout = ::std::option::Option::None;
self.thp_channel_id = ::std::option::Option::None;
self.special_fields.clear(); self.special_fields.clear();
} }
@ -1310,6 +1346,7 @@ impl ::protobuf::Message for DebugLinkGetState {
wait_word_list: ::std::option::Option::None, wait_word_list: ::std::option::Option::None,
wait_word_pos: ::std::option::Option::None, wait_word_pos: ::std::option::Option::None,
wait_layout: ::std::option::Option::None, wait_layout: ::std::option::Option::None,
thp_channel_id: ::std::option::Option::None,
special_fields: ::protobuf::SpecialFields::new(), special_fields: ::protobuf::SpecialFields::new(),
}; };
&instance &instance
@ -3668,25 +3705,26 @@ static file_descriptor_proto_data: &'static [u8] = b"\
\x03(\tR\x06tokens\"-\n\x15DebugLinkReseedRandom\x12\x14\n\x05value\x18\ \x03(\tR\x06tokens\"-\n\x15DebugLinkReseedRandom\x12\x14\n\x05value\x18\
\x01\x20\x01(\rR\x05value\"j\n\x15DebugLinkRecordScreen\x12)\n\x10target\ \x01\x20\x01(\rR\x05value\"j\n\x15DebugLinkRecordScreen\x12)\n\x10target\
_directory\x18\x01\x20\x01(\tR\x0ftargetDirectory\x12&\n\rrefresh_index\ _directory\x18\x01\x20\x01(\tR\x0ftargetDirectory\x12&\n\rrefresh_index\
\x18\x02\x20\x01(\r:\x010R\x0crefreshIndex\"~\n\x11DebugLinkGetState\x12\ \x18\x02\x20\x01(\r:\x010R\x0crefreshIndex\"\xa4\x01\n\x11DebugLinkGetSt\
$\n\x0ewait_word_list\x18\x01\x20\x01(\x08R\x0cwaitWordList\x12\"\n\rwai\ ate\x12$\n\x0ewait_word_list\x18\x01\x20\x01(\x08R\x0cwaitWordList\x12\"\
t_word_pos\x18\x02\x20\x01(\x08R\x0bwaitWordPos\x12\x1f\n\x0bwait_layout\ \n\rwait_word_pos\x18\x02\x20\x01(\x08R\x0bwaitWordPos\x12\x1f\n\x0bwait\
\x18\x03\x20\x01(\x08R\nwaitLayout\"\x83\x05\n\x0eDebugLinkState\x12\x16\ _layout\x18\x03\x20\x01(\x08R\nwaitLayout\x12$\n\x0ethp_channel_id\x18\
\n\x06layout\x18\x01\x20\x01(\x0cR\x06layout\x12\x10\n\x03pin\x18\x02\ \x04\x20\x01(\rR\x0cthpChannelId\"\x83\x05\n\x0eDebugLinkState\x12\x16\n\
\x20\x01(\tR\x03pin\x12\x16\n\x06matrix\x18\x03\x20\x01(\tR\x06matrix\ \x06layout\x18\x01\x20\x01(\x0cR\x06layout\x12\x10\n\x03pin\x18\x02\x20\
\x12'\n\x0fmnemonic_secret\x18\x04\x20\x01(\x0cR\x0emnemonicSecret\x129\ \x01(\tR\x03pin\x12\x16\n\x06matrix\x18\x03\x20\x01(\tR\x06matrix\x12'\n\
\n\x04node\x18\x05\x20\x01(\x0b2%.hw.trezor.messages.common.HDNodeTypeR\ \x0fmnemonic_secret\x18\x04\x20\x01(\x0cR\x0emnemonicSecret\x129\n\x04no\
\x04node\x123\n\x15passphrase_protection\x18\x06\x20\x01(\x08R\x14passph\ de\x18\x05\x20\x01(\x0b2%.hw.trezor.messages.common.HDNodeTypeR\x04node\
raseProtection\x12\x1d\n\nreset_word\x18\x07\x20\x01(\tR\tresetWord\x12#\ \x123\n\x15passphrase_protection\x18\x06\x20\x01(\x08R\x14passphraseProt\
\n\rreset_entropy\x18\x08\x20\x01(\x0cR\x0cresetEntropy\x12,\n\x12recove\ ection\x12\x1d\n\nreset_word\x18\x07\x20\x01(\tR\tresetWord\x12#\n\rrese\
ry_fake_word\x18\t\x20\x01(\tR\x10recoveryFakeWord\x12*\n\x11recovery_wo\ t_entropy\x18\x08\x20\x01(\x0cR\x0cresetEntropy\x12,\n\x12recovery_fake_\
rd_pos\x18\n\x20\x01(\rR\x0frecoveryWordPos\x12$\n\x0ereset_word_pos\x18\ word\x18\t\x20\x01(\tR\x10recoveryFakeWord\x12*\n\x11recovery_word_pos\
\x0b\x20\x01(\rR\x0cresetWordPos\x12N\n\rmnemonic_type\x18\x0c\x20\x01(\ \x18\n\x20\x01(\rR\x0frecoveryWordPos\x12$\n\x0ereset_word_pos\x18\x0b\
\x0e2).hw.trezor.messages.management.BackupTypeR\x0cmnemonicType\x12\x16\ \x20\x01(\rR\x0cresetWordPos\x12N\n\rmnemonic_type\x18\x0c\x20\x01(\x0e2\
\n\x06tokens\x18\r\x20\x03(\tR\x06tokens\x12<\n\x1bthp_pairing_code_entr\ ).hw.trezor.messages.management.BackupTypeR\x0cmnemonicType\x12\x16\n\
y_code\x18\x0e\x20\x01(\rR\x17thpPairingCodeEntryCode\x12,\n\x12thp_pair\ \x06tokens\x18\r\x20\x03(\tR\x06tokens\x12<\n\x1bthp_pairing_code_entry_\
ing_secret\x18\x0f\x20\x01(\x0cR\x10thpPairingSecret\"\x0f\n\rDebugLinkS\ code\x18\x0e\x20\x01(\rR\x17thpPairingCodeEntryCode\x12,\n\x12thp_pairin\
top\"P\n\x0cDebugLinkLog\x12\x14\n\x05level\x18\x01\x20\x01(\rR\x05level\ g_secret\x18\x0f\x20\x01(\x0cR\x10thpPairingSecret\"\x0f\n\rDebugLinkSto\
p\"P\n\x0cDebugLinkLog\x12\x14\n\x05level\x18\x01\x20\x01(\rR\x05level\
\x12\x16\n\x06bucket\x18\x02\x20\x01(\tR\x06bucket\x12\x12\n\x04text\x18\ \x12\x16\n\x06bucket\x18\x02\x20\x01(\tR\x06bucket\x12\x12\n\x04text\x18\
\x03\x20\x01(\tR\x04text\"G\n\x13DebugLinkMemoryRead\x12\x18\n\x07addres\ \x03\x20\x01(\tR\x04text\"G\n\x13DebugLinkMemoryRead\x12\x18\n\x07addres\
s\x18\x01\x20\x01(\rR\x07address\x12\x16\n\x06length\x18\x02\x20\x01(\rR\ s\x18\x01\x20\x01(\rR\x07address\x12\x16\n\x06length\x18\x02\x20\x01(\rR\

Loading…
Cancel
Save