Only decrypt bcmecia packets where encrypt len is set

This commit is contained in:
QuantumEntangledAndy committed 2023-08-06 19:05:04 +07:00
1 parent b90d6d7eed
commit 5109dbba9e
2 files changed
+22 -3

No files matched your search

+18 -3
View File
@@ -113,8 +113,13 @@ fn bc_modern_msg<'a>(
};
let mut in_binary = false;
let mut encrypted_len = None;
// Now we'll take the buffer that Nom gave a ref to and parse it.
let extension = if ext_len > 0 {
log::trace!(
"Extension Txt: {:?}",
String::from_utf8(processed_ext_buf.to_vec()).unwrap_or("Not Text".to_string())
);
// Apply the XML parse function, but throw away the reference to decrypted in the Ok and
// Err case. This error-error-error thing is the same idiom Nom uses internally.
let parsed = Extension::try_parse(processed_ext_buf).map_err(|_| {
@@ -126,11 +131,13 @@ fn bc_modern_msg<'a>(
})?;
if let Extension {
binary_data: Some(1),
encrypt_len,
..
} = parsed
{
// In binary so tell the current context that we need to treat the payload as binary
in_binary = true;
encrypted_len = encrypt_len;
}
Some(parsed)
} else {
@@ -173,13 +180,21 @@ fn bc_modern_msg<'a>(
let processed_payload_buf =
xml_crypto::decrypt(header.channel_id as u32, payload_buf, &encryption_protocol);
if context.in_bin_mode.contains(&(header.msg_num)) || in_binary {
payload = match context.get_encrypted() {
EncryptionProtocol::FullAes(_) => {
Some(BcPayloads::Binary(processed_payload_buf.to_vec()))
payload = match (context.get_encrypted(), encrypted_len) {
(EncryptionProtocol::FullAes(_), Some(encrypted_len)) => {
log::trace!("Binary: {:X?}", &processed_payload_buf[0..30]);
Some(BcPayloads::Binary(
processed_payload_buf[0..(encrypted_len as usize)].to_vec(),
))
}
_ => Some(BcPayloads::Binary(payload_buf.to_vec())),
};
} else {
log::trace!(
"Payload Txt: {:?}",
String::from_utf8(processed_payload_buf.to_vec()).unwrap_or("Not Text".to_string())
);
let xml = BcXml::try_parse(processed_payload_buf.as_slice()).map_err(|_| {
error!("header.msg_id: {}", header.msg_id);
error!(
+4
View File
@@ -265,6 +265,9 @@ pub struct Extension {
/// Encrypted binary has this to verify successful decryption
#[yaserde(rename = "checkValue")]
pub check_value: Option<u32>,
/// Used in newer encrypted payload packets
#[yaserde(rename = "encryptLen")]
pub encrypt_len: Option<u32>,
}
impl Default for Extension {
@@ -278,6 +281,7 @@ impl Default for Extension {
rf_id: None,
check_pos: None,
check_value: None,
encrypt_len: None,
}
}
}