updates
This commit is contained in:
parent
fc94f655b2
commit
1b802ff33f
15 changed files with 379 additions and 74 deletions
|
|
@ -2,7 +2,10 @@ use std::rc::Rc;
|
|||
|
||||
use hmac::Mac;
|
||||
use rc4::{KeyInit, Rc4, StreamCipher};
|
||||
use rnex_core::prudp::encryption::{DEFAULT_KEY, EncryptionPair};
|
||||
use rnex_core::prudp::{
|
||||
encryption::{DEFAULT_KEY, EncryptionPair},
|
||||
types_flags::{TypesFlags, types::DATA},
|
||||
};
|
||||
use typenum::U5;
|
||||
|
||||
use crate::crypto::{
|
||||
|
|
@ -13,6 +16,8 @@ use crate::crypto::{
|
|||
|
||||
pub struct InsecureInstance {
|
||||
pair: EncryptionPair<Rc4<U5>>,
|
||||
self_signat: [u8; 4],
|
||||
remote_signat: [u8; 4],
|
||||
}
|
||||
|
||||
impl CryptoInstance for InsecureInstance {
|
||||
|
|
@ -25,11 +30,19 @@ impl CryptoInstance for InsecureInstance {
|
|||
fn get_user_id(&self) -> u32 {
|
||||
0
|
||||
}
|
||||
fn generate_signature(&self, data: &[u8]) -> [u8; 4] {
|
||||
let mut hmac = <HmacMd5 as Mac>::new_from_slice(ACCESS_KEY.as_bytes())
|
||||
.expect("unable to create hmac md5");
|
||||
hmac.update(data);
|
||||
hmac.finalize().into_bytes()[0..4].try_into().unwrap()
|
||||
fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4] {
|
||||
if types_flags.get_types() == DATA {
|
||||
if data.len() == 0 {
|
||||
[0x12, 0x34, 0x56, 0x78]
|
||||
} else {
|
||||
let mut hmac = <HmacMd5 as Mac>::new_from_slice(ACCESS_KEY.as_bytes())
|
||||
.expect("unable to create hmac md5");
|
||||
hmac.update(data);
|
||||
hmac.finalize().into_bytes()[0..4].try_into().unwrap()
|
||||
}
|
||||
} else {
|
||||
self.self_signat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,9 +57,16 @@ impl Crypto for Insecure {
|
|||
common_checksum(ACCESS_KEY, data)
|
||||
}
|
||||
|
||||
fn instantiate(&self, packet_data: &[u8]) -> Self::Instance {
|
||||
fn instantiate(
|
||||
&self,
|
||||
packet_data: &[u8],
|
||||
self_signat: [u8; 4],
|
||||
remote_signat: [u8; 4],
|
||||
) -> Self::Instance {
|
||||
InsecureInstance {
|
||||
pair: EncryptionPair::init_both(|| Rc4::new(&DEFAULT_KEY)),
|
||||
self_signat,
|
||||
remote_signat,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use hmac::Mac;
|
||||
use rc4::Rc4;
|
||||
use rnex_core::prudp::encryption::EncryptionPair;
|
||||
use rnex_core::prudp::{encryption::EncryptionPair, types_flags::TypesFlags};
|
||||
use typenum::U32;
|
||||
|
||||
use crate::crypto::{
|
||||
|
|
@ -23,7 +23,7 @@ impl CryptoInstance for SecureInstance {
|
|||
fn get_user_id(&self) -> u32 {
|
||||
todo!()
|
||||
}
|
||||
fn generate_signature(&self, data: &[u8]) -> [u8; 4] {
|
||||
fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4] {
|
||||
let mut hmac = <HmacMd5 as Mac>::new_from_slice(ACCESS_KEY.as_bytes())
|
||||
.expect("unable to create hmac md5");
|
||||
hmac.update(data);
|
||||
|
|
@ -41,7 +41,12 @@ impl Crypto for Secure {
|
|||
fn calculate_checksum(&self, data: &[u8]) -> u8 {
|
||||
common_checksum(ACCESS_KEY, data)
|
||||
}
|
||||
fn instantiate(&self, data: &[u8]) -> Self::Instance {
|
||||
fn instantiate(
|
||||
&self,
|
||||
data: &[u8],
|
||||
self_signat: [u8; 4],
|
||||
remote_signat: [u8; 4],
|
||||
) -> Self::Instance {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
use cfg_if::cfg_if;
|
||||
use rnex_core::prudp::types_flags::TypesFlags;
|
||||
|
||||
mod common_crypto;
|
||||
|
||||
pub trait CryptoInstance: Send + 'static {
|
||||
fn decrypt_incoming(&mut self, data: &mut [u8]);
|
||||
fn encrypt_outgoing(&mut self, data: &mut [u8]);
|
||||
fn generate_signature(&self, data: &[u8]) -> [u8; 4];
|
||||
fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4];
|
||||
fn get_user_id(&self) -> u32;
|
||||
}
|
||||
|
||||
|
|
@ -13,7 +14,12 @@ pub trait Crypto: Send + Sync + 'static {
|
|||
type Instance: CryptoInstance;
|
||||
fn new() -> Self;
|
||||
fn calculate_checksum(&self, data: &[u8]) -> u8;
|
||||
fn instantiate(&self, data: &[u8]) -> Self::Instance;
|
||||
fn instantiate(
|
||||
&self,
|
||||
data: &[u8],
|
||||
self_signat: [u8; 4],
|
||||
remote_signat: [u8; 4],
|
||||
) -> Self::Instance;
|
||||
}
|
||||
|
||||
cfg_if! {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue