Start implementing security

This commit is contained in:
hodasemi 2023-09-22 14:14:46 +02:00
parent 7f62fd65e1
commit 383bcb4383
2 changed files with 17 additions and 9 deletions

View file

@ -4,9 +4,13 @@
# devices = midea_core,discover() # devices = midea_core,discover()
import discover import security;
devices = discover.discover()
secure = security.LocalSecurity()
result = secure.encode_8370(None, security.MSGTYPE_HANDSHAKE_REQUEST)
print(result)
print(devices) print(devices)

View file

@ -17,14 +17,18 @@ pub enum MsgType {
ENCRYPTED_REQUEST = 0x6, ENCRYPTED_REQUEST = 0x6,
} }
pub struct Security; #[derive(Debug, Default)]
pub struct Security {
request_count: u32,
response_count: u32,
}
impl Security { impl Security {
pub fn decrypt(data: &mut [u8]) -> &[u8] { const N: u128 = 141661095494369103254425781617665632877;
const N: u128 = 141661095494369103254425781617665632877; const KEY: [u8; 16] = Self::N.to_be_bytes();
const KEY: [u8; 16] = N.to_be_bytes();
let array = GenericArray::from(KEY); pub fn decrypt(&self, data: &mut [u8]) -> &[u8] {
let array = GenericArray::from(Self::KEY);
let cipher = Aes128::new(&array); let cipher = Aes128::new(&array);
for chunk in data.chunks_mut(16) { for chunk in data.chunks_mut(16) {
@ -35,7 +39,7 @@ impl Security {
data data
} }
pub fn encode_8370(msg_type: MsgType) -> Result<String> { pub fn encode_8370(&mut self, msg_type: MsgType) -> Result<String> {
let mut header = hex("83,70")?; let mut header = hex("83,70")?;
let mut data: Vec<u8> = Vec::new(); let mut data: Vec<u8> = Vec::new();