Handle aes encrypt during deser too

This commit is contained in:
QuantumEntangledAndy authored and Andrew King committed 2023-02-24 07:25:37 +07:00
1 parent f253100ea7
commit a3aa3c4556
4 files changed
+17 -4

No files matched your search

+9 -1
View File
@@ -27,7 +27,15 @@ impl Encoder<Bc> for BcCodex {
fn encode(&mut self, item: Bc, dst: &mut BytesMut) -> Result<()> {
// let context = self.context.read().unwrap();
let buf: Vec<u8> = Default::default();
let buf = item.serialize(buf, self.context.get_encrypted())?;
let enc_protocol: EncryptionProtocol = match self.context.get_encrypted() {
EncryptionProtocol::Aes(_) if item.meta.msg_id == 1 => {
// During login the encyption protocol cannot go higher than BCEncrypt
// even if we support AES. (BUt it can go lower i.e. None)
EncryptionProtocol::BCEncrypt
}
n => *n,
};
let buf = item.serialize(buf, &enc_protocol)?;
dst.reserve(buf.len());
dst.extend_from_slice(buf.as_slice());
Ok(())
+7 -1
View File
@@ -160,7 +160,13 @@ fn bc_modern_msg<'a>(
response_code,
..
} if (response_code & 0xff) == 0x02 => EncryptionProtocol::BCEncrypt, // This is AES but the first packet with the NONCE is BCEcrypt, since the NONCE in this packet is required to build the AES key
_ => context.get_encrypted().clone(),
BcHeader { msg_id: 1, .. }
if matches!(context.get_encrypted(), EncryptionProtocol::Aes(_)) =>
{
// Maximum encryption level is BCEncrypt during login... Not sure why Reolink did it like that
EncryptionProtocol::BCEncrypt
}
_ => *context.get_encrypted(),
};
let processed_payload_buf =
+1 -1
View File
@@ -169,7 +169,7 @@ pub(super) struct BcSendInfo {
/// These are the encyption modes supported by the camera
///
/// The mode is negotiated during login
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy)]
pub enum EncryptionProtocol {
/// Older camera use no encryption
Unencrypted,
@@ -50,7 +50,6 @@ impl<'a> Stream for BcPayloadStream<'a> {
) -> Poll<Option<IoResult<Vec<u8>>>> {
match Pin::new(&mut self.rx).poll_next(cx) {
Poll::Ready(Some(bc)) => {
log::info!("Got Bc Packet");
match bc {
Bc {
body: