fix forgetting to save file
This commit is contained in:
parent
3b6de6968d
commit
7e3cade00e
11 changed files with 124 additions and 121 deletions
|
|
@ -1,10 +1,18 @@
|
|||
use hmac::Mac;
|
||||
use rc4::{Rc4, StreamCipher};
|
||||
use rnex_core::prudp::{
|
||||
encryption::EncryptionPair,
|
||||
types_flags::{TypesFlags, types::DATA},
|
||||
use md5::{Digest, Md5};
|
||||
use rc4::{KeyInit, Rc4, StreamCipher};
|
||||
use rnex_core::{
|
||||
executables::common::SECURE_SERVER_ACCOUNT,
|
||||
nex::account::Account,
|
||||
prudp::{
|
||||
encryption::EncryptionPair,
|
||||
ticket::read_secure_connection_data,
|
||||
types_flags::{TypesFlags, types::DATA},
|
||||
},
|
||||
rmc::structures::RmcSerialize,
|
||||
};
|
||||
use typenum::U32;
|
||||
use std::io::Write;
|
||||
use typenum::U16;
|
||||
|
||||
use crate::crypto::{
|
||||
Crypto, CryptoInstance,
|
||||
|
|
@ -13,7 +21,7 @@ use crate::crypto::{
|
|||
};
|
||||
|
||||
pub struct SecureInstance {
|
||||
pair: EncryptionPair<Rc4<U32>>,
|
||||
pair: EncryptionPair<Rc4<U16>>,
|
||||
uid: u32,
|
||||
self_signat: [u8; 4],
|
||||
remote_signat: [u8; 4],
|
||||
|
|
@ -34,7 +42,9 @@ impl CryptoInstance for SecureInstance {
|
|||
if data.len() == 0 {
|
||||
[0x78, 0x56, 0x34, 0x12]
|
||||
} else {
|
||||
let mut hmac = <HmacMd5 as Mac>::new_from_slice(ACCESS_KEY.as_bytes())
|
||||
let mut hash = Md5::new();
|
||||
hash.write(ACCESS_KEY.as_bytes()).unwrap();
|
||||
let mut hmac = <HmacMd5 as Mac>::new_from_slice(&hash.finalize().as_slice())
|
||||
.expect("unable to create hmac md5");
|
||||
hmac.update(data);
|
||||
hmac.finalize().into_bytes()[0..4].try_into().unwrap()
|
||||
|
|
@ -45,12 +55,12 @@ impl CryptoInstance for SecureInstance {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Secure();
|
||||
pub struct Secure(&'static Account);
|
||||
|
||||
impl Crypto for Secure {
|
||||
type Instance = SecureInstance;
|
||||
fn new() -> Self {
|
||||
Self()
|
||||
Self(&SECURE_SERVER_ACCOUNT)
|
||||
}
|
||||
fn calculate_checksum(&self, data: &[u8]) -> u8 {
|
||||
common_checksum(ACCESS_KEY, data)
|
||||
|
|
@ -60,7 +70,27 @@ impl Crypto for Secure {
|
|||
data: &[u8],
|
||||
self_signat: [u8; 4],
|
||||
remote_signat: [u8; 4],
|
||||
) -> Self::Instance {
|
||||
todo!()
|
||||
) -> Option<(Self::Instance, Vec<u8>)> {
|
||||
let (session_key, pid, check_value) = read_secure_connection_data(data, &self.0)?;
|
||||
|
||||
let check_value_response = check_value + 1;
|
||||
|
||||
let data = bytemuck::bytes_of(&check_value_response);
|
||||
|
||||
let mut response = Vec::new();
|
||||
|
||||
data.serialize(&mut response).ok()?;
|
||||
|
||||
Some((
|
||||
SecureInstance {
|
||||
pair: EncryptionPair::init_both(|| {
|
||||
Rc4::new_from_slice(&session_key).expect("unable to initialize rc4 stream")
|
||||
}),
|
||||
self_signat,
|
||||
remote_signat,
|
||||
uid: pid,
|
||||
},
|
||||
response,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue