Start implementing security
This commit is contained in:
parent
7f62fd65e1
commit
383bcb4383
2 changed files with 17 additions and 9 deletions
10
midea.py
10
midea.py
|
@ -4,9 +4,13 @@
|
|||
|
||||
# devices = midea_core,discover()
|
||||
|
||||
import discover
|
||||
|
||||
devices = discover.discover()
|
||||
import security;
|
||||
|
||||
|
||||
|
||||
secure = security.LocalSecurity()
|
||||
|
||||
result = secure.encode_8370(None, security.MSGTYPE_HANDSHAKE_REQUEST)
|
||||
|
||||
print(result)
|
||||
print(devices)
|
|
@ -17,14 +17,18 @@ pub enum MsgType {
|
|||
ENCRYPTED_REQUEST = 0x6,
|
||||
}
|
||||
|
||||
pub struct Security;
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Security {
|
||||
request_count: u32,
|
||||
response_count: u32,
|
||||
}
|
||||
|
||||
impl Security {
|
||||
pub fn decrypt(data: &mut [u8]) -> &[u8] {
|
||||
const N: u128 = 141661095494369103254425781617665632877;
|
||||
const KEY: [u8; 16] = N.to_be_bytes();
|
||||
const N: u128 = 141661095494369103254425781617665632877;
|
||||
const KEY: [u8; 16] = Self::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);
|
||||
|
||||
for chunk in data.chunks_mut(16) {
|
||||
|
@ -35,7 +39,7 @@ impl Security {
|
|||
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 data: Vec<u8> = Vec::new();
|
||||
|
||||
|
|
Loading…
Reference in a new issue