From dad8ac498cecbc319c67ec87e95c0f9c75ebff0e Mon Sep 17 00:00:00 2001 From: Maple Date: Sun, 1 Feb 2026 21:31:32 +0100 Subject: [PATCH] fix having fixed size key --- rnex-core/src/kerberos/mod.rs | 4 ++-- rnex-core/src/nex/account.rs | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/rnex-core/src/kerberos/mod.rs b/rnex-core/src/kerberos/mod.rs index 88700a6..4b56f56 100644 --- a/rnex-core/src/kerberos/mod.rs +++ b/rnex-core/src/kerberos/mod.rs @@ -26,7 +26,7 @@ pub const SESSION_KEY_LENGTH: usize = SESSION_KEY_LENGTH_TY::USIZE; type Md5Hmac = Hmac; pub fn derive_key(pid: u32, password: &[u8]) -> [u8; 16] { - let iteration_count = 65000 + pid % 1024 - 1; + let iteration_count = 65000 + pid % 1024; // we do one iteration out here to ensure the key is always 16 bytes let mut key: [u8; 16] = { @@ -35,7 +35,7 @@ pub fn derive_key(pid: u32, password: &[u8]) -> [u8; 16] { md5.finalize().try_into().unwrap() }; - for _ in 0..iteration_count { + for _ in 1..iteration_count { let mut md5 = Md5::new(); md5.update(key); key = md5.finalize().try_into().unwrap(); diff --git a/rnex-core/src/nex/account.rs b/rnex-core/src/nex/account.rs index 0c7a6f0..b3a5bb6 100644 --- a/rnex-core/src/nex/account.rs +++ b/rnex-core/src/nex/account.rs @@ -4,29 +4,23 @@ use macros::RmcSerialize; pub struct Account { pub pid: u32, pub username: String, - pub kerbros_password: [u8; 16], + pub kerbros_password: Box<[u8]>, } impl Account { pub fn new(pid: u32, username: &str, passwd: &str) -> Self { let passwd_data = passwd.as_bytes(); - let mut passwd = [0u8; 16]; - - for (idx, byte) in passwd_data.iter().enumerate() { - passwd[idx] = *byte; - } - Self { - kerbros_password: passwd, + kerbros_password: passwd.as_bytes().into(), username: username.into(), pid, } } - pub fn new_raw_password(pid: u32, username: &str, passwd: [u8; 16]) -> Self { + pub fn new_raw_password(pid: u32, username: &str, passwd: &[u8]) -> Self { Self { - kerbros_password: passwd, + kerbros_password: passwd.into(), username: username.into(), pid, }