progress
Some checks failed
Build and Test / friends (push) Successful in 9m35s
Build and Test / wii-u-chat (push) Has been cancelled
Build and Test / puyopuyo (push) Has been cancelled
Build and Test / sonic-transformed (push) Has been cancelled
Build and Test / super-mario-maker (push) Has been cancelled
Build and Test / minecraft-wiiu (push) Has been cancelled
Build and Test / wii-sports-club (push) Has been cancelled
Build and Test / splatoon (push) Has been cancelled
Build and Test / splatoon-testfire (push) Has been cancelled
Build and Test / fast-racing-neo (push) Has been cancelled
Build and Test / mario-tennis (push) Has been cancelled

This commit is contained in:
Maple Nebel 2026-07-14 17:27:30 +02:00
commit 47f7dea859
27 changed files with 160 additions and 170 deletions

View file

@ -7,21 +7,21 @@ edition = "2024"
workspace = true
[dependencies]
bytemuck = { version = "1.23.1", features = ["derive"] }
tokio = { version = "1.47.0", features = ["full"] }
hmac = "0.12.1"
md-5 = "^0.10.6"
rc4 = "0.1.0"
hmac = "0.13.0"
md-5 = "0.11.0"
rc4 = "0.2.0"
v-byte-helpers = { git = "https://github.com/RusticMaple/VByteMacros", version = "0.1.1" }
thiserror = "2.0.12"
async-trait = "0.1.88"
typenum = "1.18.0"
once_cell = "1.21.3"
# once_cell = "1.21.3"
rnex-prudp = { path = "../rnex-prudp" }
rnex-util = { path = "../rnex-util" }
proxy-common = {path = "../proxy-common"}
cfg-if = "1.0.4"
tracing = "0.1.44"
[features]
prudpv1 = []

View file

@ -1,2 +0,0 @@
pub mod proxy_insecure;
pub mod proxy_secure;

View file

@ -1,89 +0,0 @@
use crate::prudp::router::Router;
use crate::prudp::unsecure::Unsecure;
use tracing::error;
use tracing::warn;
use proxy_common::{ProxyStartupParam, RNEX_ACCESS_KEY};
use rnex_core::executables::common::SECURE_SERVER_ACCOUNT;
use rnex_prudp::virtual_port::VirtualPort;
use rnex_util::{UnitPacketRead, UnitPacketWrite};
use rnex_core::rnex_proxy_common::ConnectionInitData;
use rnex_server::ConnectionInitData;
use rnex_util::{UnitPacketRead, UnitPacketWrite};
use std::time::Duration;
use tokio::net::TcpStream;
use tokio::task;
use tokio::time::sleep;
pub async fn start(param: ProxyStartupParam) {
let (router_secure, _) = Router::new(param.self_private)
.await
.expect("unable to start router");
let mut socket_secure = router_secure
.add_socket(VirtualPort::new(1, 10), Unsecure(RNEX_ACCESS_KEY))
.await
.expect("unable to add socket");
loop {
let Some(mut conn) = socket_secure.accept().await else {
error!("server crashed");
return;
};
task::spawn(async move {
let mut stream = match TcpStream::connect(param.forward_destination).await {
Ok(v) => v,
Err(e) => {
error!("unable to connect: {}", e);
return;
}
};
if let Err(e) = stream
.send_buffer(
&ConnectionInitData {
prudpsock_addr: conn.socket_addr,
pid: conn.user_id,
}
.to_data()
.unwrap(),
)
.await
{
error!("error connecting to backend: {}", e);
return;
};
loop {
tokio::select! {
data = conn.recv() => {
let Some(data) = data else {
return;
};
if let Err(e) = stream.send_buffer(&data[..]).await{
error!("error sending data to backend: {}", e);
return;
}
},
data = stream.read_buffer() => {
let data = match data{
Ok(d) => d,
Err(e) => {
error!("error reveiving data from backend: {}", e);
return;
}
};
if conn.send(data).await == None{
return;
}
},
_ = sleep(Duration::from_secs(10)) => {
conn.send([0,0,0,0,0].to_vec()).await;
}
}
}
});
}
}

View file

@ -1,112 +0,0 @@
use crate::prudp::router::Router;
use crate::prudp::secure::Secure;
use tracing::error;
use tracing::warn;
use proxy_common::{ProxyStartupParam, RNEX_ACCESS_KEY};
use rnex_core::executables::common::SECURE_SERVER_ACCOUNT;
use rnex_prudp::virtual_port::VirtualPort;
use rnex_util::{UnitPacketRead, UnitPacketWrite};
use rnex_core::rnex_proxy_common::ConnectionInitData;
use rnex_server::ConnectionInitData;
use rnex_util::{UnitPacketRead, UnitPacketWrite};
use std::ops::Deref;
use std::time::Duration;
use tokio::net::TcpStream;
use tokio::task;
use tokio::time::sleep;
pub async fn start(param: ProxyStartupParam) {
let (router_secure, _) = Router::new(param.self_private)
.await
.expect("unable to start router");
let mut socket_secure = router_secure
.add_socket(
VirtualPort::new(1, 10),
Secure(RNEX_ACCESS_KEY, SECURE_SERVER_ACCOUNT.clone()),
)
.await
.expect("unable to add socket");
loop {
let Some(mut conn) = socket_secure.accept().await else {
error!("server crashed");
return;
};
task::spawn(async move {
let Ok(mut c) = rnex_core::grpc::account::Client::new().await else {
error!("failed to initialize gql client");
return;
};
let v = match c.get_user_level(conn.user_id).await {
Ok(v) => v,
Err(e) => {
error!("failed to get user level: {}", e);
return;
}
};
if v < 0 {
warn!("person with too low account level joined");
return;
}
let mut stream = match TcpStream::connect(param.forward_destination).await {
Ok(v) => v,
Err(e) => {
error!("unable to connect: {}", e);
return;
}
};
if let Err(e) = stream
.send_buffer(
&ConnectionInitData {
prudpsock_addr: conn.socket_addr,
pid: conn.user_id,
}
.to_data()
.unwrap(),
)
.await
{
error!("error connecting to backend: {}", e);
return;
};
'a: loop {
tokio::select! {
data = conn.recv() => {
let Some(data) = data else {
break 'a;
};
if let Err(e) = stream.send_buffer(&data[..]).await{
error!("error sending data to backend: {}", e);
break 'a;
}
},
data = stream.read_buffer() => {
let data = match data{
Ok(d) => d,
Err(e) => {
error!("error reveiving data from backend: {}", e);
break 'a;
}
};
if conn.send(data).await == None{
break 'a;
}
},
_ = sleep(Duration::from_secs(10)) => {
conn.send([0,0,0,0,0].to_vec()).await;
}
}
}
conn.deref().close_connection().await;
});
}
}

View file

@ -1,14 +1,5 @@
cfg_if::cfg_if! {
if #[cfg(feature = "prudpv1")]{
use proxy_common::ProxyStartupParam;
pub mod executables;
pub mod prudp;
pub async fn start_secure(param: ProxyStartupParam) {
executables::proxy_secure::start(param).await;
}
pub async fn start_insecure(param: ProxyStartupParam) {
executables::proxy_insecure::start(param).await;
}
}
}

View file

@ -8,8 +8,8 @@ use crate::prudp::packet::PacketOption::{
};
use bytemuck::{Pod, Zeroable};
use hmac::{Hmac, Mac};
use tracing::{error, warn};
use md5::{Digest, Md5};
use rc4::KeyInit;
use rnex_prudp::socket_addr::PRUDPSockAddr;
use rnex_prudp::types_flags::TypesFlags;
use rnex_prudp::types_flags::flags::ACK;
@ -20,6 +20,7 @@ use std::io::{Cursor, Read, Seek, Write};
use std::net::SocketAddr;
use std::net::SocketAddrV4;
use thiserror::Error;
use tracing::{error, warn};
use v_byte_helpers::SwapEndian;
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
@ -320,24 +321,17 @@ impl PRUDPV1Packet {
let mut hmac = Md5Hmac::new_from_slice(&key).expect("fuck");
hmac.write(&header_data)
.expect("error during hmac calculation");
hmac.update(&header_data);
if let Some(session_key) = session_key {
hmac.write(&session_key)
.expect("error during hmac calculation");
hmac.update(&session_key);
}
hmac.write(&access_key_sum_bytes)
.expect("error during hmac calculation");
hmac.update(&access_key_sum_bytes);
if let Some(connection_signature) = connection_signature {
hmac.write(&connection_signature)
.expect("error during hmac calculation");
hmac.update(&connection_signature);
}
hmac.write(&option_bytes)
.expect("error during hmac calculation");
hmac.write_all(&self.payload)
.expect("error during hmac calculation");
hmac.update(&option_bytes);
hmac.update(&self.payload);
hmac.finalize().into_bytes()[0..16]
.try_into()

View file

@ -1,24 +1,22 @@
use crate::prudp::packet::PRUDPV1Packet;
use crate::prudp::socket::{CryptoHandler, CryptoHandlerConnectionInstance};
use hmac::digest::consts::U32;
use rc4::cipher::StreamCipherCoreWrapper;
use rc4::{KeyInit, Rc4, Rc4Core, StreamCipher};
use typenum::U5;
use rnex_util::PID;
use rc4::{KeyInit, Rc4, StreamCipher};
use rnex_prudp::encryption::EncryptionPair;
use rnex_prudp::ticket::read_secure_connection_data;
use serde_core::ser::Serialize;
use rnex_util::PID;
use rnex_util::account::Account;
type Rc4U32 = StreamCipherCoreWrapper<Rc4Core<U32>>;
//type Rc4U32 = StreamCipherCoreWrapper<Rc4Core<U32>>;
pub fn generate_secure_encryption_pairs(
mut session_key: [u8; 32],
count: u8,
) -> Vec<EncryptionPair<Rc4<U32>>> {
) -> Vec<EncryptionPair<Rc4>> {
let mut vec = Vec::with_capacity(count as usize);
vec.push(EncryptionPair {
send: Rc4U32::new_from_slice(&session_key).expect("unable to create rc4"),
recv: Rc4U32::new_from_slice(&session_key).expect("unable to create rc4"),
send: Rc4::new_from_slice(&session_key).expect("unable to create rc4"),
recv: Rc4::new_from_slice(&session_key).expect("unable to create rc4"),
});
for _ in 1..=count {
@ -31,8 +29,8 @@ pub fn generate_secure_encryption_pairs(
}
vec.push(EncryptionPair {
send: Rc4U32::new_from_slice(&session_key).expect("unable to create rc4"),
recv: Rc4U32::new_from_slice(&session_key).expect("unable to create rc4"),
send: Rc4::new_from_slice(&session_key).expect("unable to create rc4"),
recv: Rc4::new_from_slice(&session_key).expect("unable to create rc4"),
});
}
@ -44,7 +42,7 @@ pub struct Secure(pub &'static str, pub Account);
pub struct SecureInstance {
access_key: &'static str,
session_key: [u8; 32],
streams: Vec<EncryptionPair<Rc4<U32>>>,
streams: Vec<EncryptionPair<Rc4>>,
self_signature: [u8; 16],
#[allow(dead_code)]
remote_signature: [u8; 16],
@ -69,7 +67,10 @@ impl CryptoHandler for Secure {
let mut response = Vec::new();
data.serialize(&mut response).ok()?;
response.extend_from_slice(&(response.len() as u32).to_le_bytes());
response.extend_from_slice(&data[..]);
//data.serialize(&mut response).ok()?;
let encryption_pairs = generate_secure_encryption_pairs(session_key, substream_count);
@ -93,7 +94,7 @@ impl CryptoHandler for Secure {
}
impl CryptoHandlerConnectionInstance for SecureInstance {
type Encryption = Rc4<U5>;
type Encryption = Rc4;
fn decrypt_incoming(&mut self, substream: u8, data: &mut [u8]) {
if let Some(crypt_pair) = self.streams.get_mut(substream as usize) {

View file

@ -3,24 +3,23 @@ use crate::prudp::packet::PacketOption::{
};
use crate::prudp::packet::{PRUDPV1Header, PRUDPV1Packet};
use async_trait::async_trait;
use tracing::error;
use tracing::{info, warn};
use rc4::StreamCipher;
use rnex_prudp::socket_addr::PRUDPSockAddr;
use rnex_prudp::types_flags::TypesFlags;
use rnex_prudp::types_flags::flags::{ACK, HAS_SIZE, MULTI_ACK, NEED_ACK, RELIABLE};
use rnex_prudp::types_flags::types::{CONNECT, DATA, DISCONNECT, PING, SYN};
use rnex_prudp::virtual_port::VirtualPort;
use rnex_util::PID;
use std::collections::{BTreeMap, HashMap};
use std::io::Cursor;
use std::marker::PhantomData;
use std::ops::Deref;
use std::sync::{Arc, Weak};
use tokio::spawn;
use tracing::error;
use tracing::{info, warn};
use v_byte_helpers::ReadExtensions;
use v_byte_helpers::little_endian::read_u16;
use rnex_util::{PID, account::Account};
use rnex_prudp::encryption::EncryptionPair;
use rnex_prudp::types_flags::types::{SYN, CONNECT, PING, DISCONNECT, DATA};
use rnex_prudp::types_flags::flags::{ACK, HAS_SIZE, NEED_ACK, MULTI_ACK, RELIABLE};
use rnex_prudp::types_flags::TypesFlags;
use rnex_prudp::socket_addr::PRUDPSockAddr;
use rnex_prudp::virtual_port::VirtualPort;
use std::time::Duration;
use tokio::net::UdpSocket;

View file

@ -2,7 +2,6 @@ use crate::prudp::packet::PRUDPV1Packet;
use crate::prudp::socket::{CryptoHandler, CryptoHandlerConnectionInstance};
use rc4::{KeyInit, Rc4, StreamCipher};
use rnex_prudp::encryption::{DEFAULT_KEY, EncryptionPair};
use typenum::U5;
pub struct Unsecure(pub &'static str);
@ -52,7 +51,7 @@ impl CryptoHandler for Unsecure {
}
impl CryptoHandlerConnectionInstance for UnsecureInstance {
type Encryption = Rc4<U5>;
type Encryption = Rc4;
fn decrypt_incoming(&mut self, substream: u8, data: &mut [u8]) {
if let Some(crypt_pair) = self.streams.get_mut(substream as usize) {