feat(secure): a bunch of stuff
This commit is contained in:
parent
4f26aae1d7
commit
81f7a0a738
15 changed files with 480 additions and 49 deletions
|
|
@ -2,6 +2,7 @@ use std::io::Cursor;
|
|||
use log::error;
|
||||
use crate::nex::account::Account;
|
||||
use crate::protocols::auth::AuthProtocolConfig;
|
||||
use crate::prudp::socket::ConnectionData;
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponseResult};
|
||||
use crate::rmc::structures::RmcSerialize;
|
||||
|
|
@ -12,7 +13,7 @@ pub async fn login(rmcmessage: &RMCMessage, _name: &str) -> RMCResponseResult{
|
|||
rmcmessage.error_result_with_code(ErrorCode::Core_NotImplemented)
|
||||
}
|
||||
|
||||
pub async fn login_raw_params(rmcmessage: &RMCMessage, data: AuthProtocolConfig) -> RMCResponseResult{
|
||||
pub async fn login_raw_params(rmcmessage: &RMCMessage, _: &mut ConnectionData, data: AuthProtocolConfig) -> RMCResponseResult{
|
||||
let mut reader = Cursor::new(&rmcmessage.rest_of_data);
|
||||
|
||||
let Ok(str) = String::deserialize(&mut reader) else {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@ use crate::kerberos::KerberosDateTime;
|
|||
use crate::nex::account::Account;
|
||||
use crate::protocols::auth::AuthProtocolConfig;
|
||||
use crate::protocols::auth::ticket_generation::generate_ticket;
|
||||
use crate::prudp::socket::ConnectionData;
|
||||
use crate::rmc;
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponseResult};
|
||||
use crate::rmc::structures::{RmcSerialize};
|
||||
use crate::rmc::structures::any::Any;
|
||||
use crate::rmc::structures::connection_data::ConnectionData;
|
||||
use crate::rmc::structures::qresult::QResult;
|
||||
|
||||
pub async fn login_ex(rmcmessage: &RMCMessage, proto_data: AuthProtocolConfig, pid: u32) -> RMCResponseResult{
|
||||
|
|
@ -32,7 +33,7 @@ pub async fn login_ex(rmcmessage: &RMCMessage, proto_data: AuthProtocolConfig, p
|
|||
|
||||
let result = QResult::success(ErrorCode::Core_Unknown);
|
||||
|
||||
let connection_data = ConnectionData{
|
||||
let connection_data = rmc::structures::connection_data::ConnectionData{
|
||||
station_url: proto_data.station_url,
|
||||
special_station_url: "",
|
||||
date_time: KerberosDateTime::now(),
|
||||
|
|
@ -50,7 +51,7 @@ pub async fn login_ex(rmcmessage: &RMCMessage, proto_data: AuthProtocolConfig, p
|
|||
return rmcmessage.success_with_data(response);
|
||||
}
|
||||
|
||||
pub async fn login_ex_raw_params(rmcmessage: &RMCMessage, data: AuthProtocolConfig) -> RMCResponseResult{
|
||||
pub async fn login_ex_raw_params(rmcmessage: &RMCMessage, _: &mut ConnectionData, data: AuthProtocolConfig) -> RMCResponseResult{
|
||||
let mut reader = Cursor::new(&rmcmessage.rest_of_data);
|
||||
|
||||
let Ok(str) = String::deserialize(&mut reader) else {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use crate::grpc::account;
|
|||
use crate::protocols::auth::{AuthProtocolConfig, get_login_data_by_pid};
|
||||
use crate::protocols::auth::method_login_ex::login_ex;
|
||||
use crate::protocols::auth::ticket_generation::generate_ticket;
|
||||
use crate::prudp::socket::ConnectionData;
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponseResult};
|
||||
use crate::rmc::response::ErrorCode::Core_Unknown;
|
||||
|
|
@ -38,7 +39,7 @@ pub async fn request_ticket(rmcmessage: &RMCMessage, data: AuthProtocolConfig, s
|
|||
rmcmessage.success_with_data(response)
|
||||
}
|
||||
|
||||
pub async fn request_ticket_raw_params(rmcmessage: &RMCMessage, data: AuthProtocolConfig) -> RMCResponseResult{
|
||||
pub async fn request_ticket_raw_params(rmcmessage: &RMCMessage, _: &mut ConnectionData, data: AuthProtocolConfig) -> RMCResponseResult{
|
||||
let mut reader = Cursor::new(&rmcmessage.rest_of_data);
|
||||
|
||||
let Ok(source_pid) = reader.read_struct(IS_BIG_ENDIAN) else {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
use crate::prudp::socket::ConnectionData;
|
||||
|
||||
pub mod auth;
|
||||
pub mod server;
|
||||
pub mod secure;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! define_protocol {
|
||||
($id:literal ($($varname:ident : $ty:ty),*) => {$($func_id:literal => $func:path),*} ) => {
|
||||
#[allow(unused_parens)]
|
||||
async fn protocol (rmcmessage: &RMCMessage, $($varname : $ty),*) -> Option<RMCResponse>{
|
||||
async fn protocol (rmcmessage: &crate::RMCMessage, connection: &mut crate::protocols::ConnectionData, $($varname : $ty),*) -> Option<crate::rmc::response::RMCResponse>{
|
||||
if rmcmessage.protocol_id != $id{
|
||||
return None;
|
||||
}
|
||||
|
|
@ -13,33 +17,34 @@ macro_rules! define_protocol {
|
|||
|
||||
let response_result = match rmcmessage.method_id{
|
||||
$(
|
||||
$func_id => $func ( rmcmessage, self_data).await,
|
||||
$func_id => $func ( rmcmessage, connection, self_data).await,
|
||||
)*
|
||||
_ => {
|
||||
error!("invalid method id sent to protocol {}: {:?}", $id, rmcmessage.method_id);
|
||||
log::error!("invalid method id sent to protocol {}: {:?}", $id, rmcmessage.method_id);
|
||||
return Some(
|
||||
RMCResponse{
|
||||
crate::rmc::response::RMCResponse{
|
||||
protocol_id: $id,
|
||||
response_result: rmcmessage.error_result_with_code(ErrorCode::Core_NotImplemented)
|
||||
response_result: rmcmessage.error_result_with_code(crate::rmc::response::ErrorCode::Core_NotImplemented)
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Some(RMCResponse{
|
||||
Some(crate::rmc::response::RMCResponse{
|
||||
protocol_id: $id,
|
||||
response_result
|
||||
})
|
||||
}
|
||||
#[allow(unused_parens)]
|
||||
pub fn bound_protocol($($varname : $ty,)*) -> Box<dyn for<'message_lifetime> Fn(&'message_lifetime RMCMessage) -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = Option<RMCResponse>> + Send + 'message_lifetime>> + Send + Sync>{
|
||||
pub fn bound_protocol($($varname : $ty,)*) -> Box<dyn for<'message_lifetime> Fn(&'message_lifetime crate::RMCMessage, &'message_lifetime mut crate::protocols::ConnectionData)
|
||||
-> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = Option<crate::rmc::response::RMCResponse>> + Send + 'message_lifetime>> + Send + Sync>{
|
||||
Box::new(
|
||||
move |v| {
|
||||
move |v, cd| {
|
||||
Box::pin(async move {
|
||||
$(
|
||||
let $varname = $varname.clone();
|
||||
)*
|
||||
protocol(v, $($varname,)*).await
|
||||
protocol(v, cd, $($varname,)*).await
|
||||
})
|
||||
}
|
||||
)
|
||||
|
|
|
|||
65
src/protocols/secure/method_register.rs
Normal file
65
src/protocols/secure/method_register.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use bytemuck::bytes_of;
|
||||
use log::{error, warn};
|
||||
use crate::protocols::auth::AuthProtocolConfig;
|
||||
use crate::prudp::socket::ConnectionData;
|
||||
use crate::prudp::station_url::{nat_types, StationUrl};
|
||||
use crate::prudp::station_url::Type::PRUDPS;
|
||||
use crate::prudp::station_url::UrlOptions::{Address, NatFiltering, NatMapping, NatType, Port, PrincipalID, RVConnectionID};
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponseResult};
|
||||
use crate::rmc::structures::any::Any;
|
||||
use crate::rmc::structures::qresult::QResult;
|
||||
use crate::rmc::structures::RmcSerialize;
|
||||
|
||||
type StringList = Vec<String>;
|
||||
|
||||
pub async fn register(rmcmessage: &RMCMessage, station_urls: Vec<StationUrl>, conn_data: &mut ConnectionData) -> RMCResponseResult{
|
||||
|
||||
let Some(active_connection_data) = conn_data.active_connection_data.as_ref() else {
|
||||
return rmcmessage.error_result_with_code(ErrorCode::RendezVous_NotAuthenticated)
|
||||
};
|
||||
|
||||
let Some(active_secure_connection_data) = active_connection_data.active_secure_connection_data.as_ref() else {
|
||||
return rmcmessage.error_result_with_code(ErrorCode::RendezVous_NotAuthenticated)
|
||||
};
|
||||
|
||||
let public_station = StationUrl{
|
||||
url_type: PRUDPS,
|
||||
options: vec![
|
||||
RVConnectionID(active_connection_data.connection_id),
|
||||
Address(*conn_data.sock_addr.regular_socket_addr.ip()),
|
||||
Port(conn_data.sock_addr.regular_socket_addr.port()),
|
||||
NatFiltering(0),
|
||||
NatMapping(0),
|
||||
NatType(nat_types::BEHIND_NAT),
|
||||
PrincipalID(active_secure_connection_data.pid),
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
let result = QResult::success(ErrorCode::Core_Unknown);
|
||||
|
||||
let mut response = Vec::new();
|
||||
|
||||
result.serialize(&mut response).expect("unable to serialize result");
|
||||
response.write_all(bytes_of(&active_connection_data.connection_id)).expect("unable to serialize connection id");
|
||||
public_station.to_string().serialize(&mut response).expect("unable to serialize station id");
|
||||
|
||||
rmcmessage.success_with_data(response)
|
||||
}
|
||||
|
||||
pub async fn register_raw_params(rmcmessage: &RMCMessage, conn_data: &mut ConnectionData, _: ()) -> RMCResponseResult{
|
||||
let mut reader = Cursor::new(&rmcmessage.rest_of_data);
|
||||
|
||||
let Ok(station_urls) = StringList::deserialize(&mut reader) else {
|
||||
return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
|
||||
};
|
||||
|
||||
let Ok(station_urls): Result<Vec<StationUrl>, _> = station_urls.iter().map(|c| StationUrl::try_from((&c) as &str)).collect() else {
|
||||
return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
|
||||
};
|
||||
|
||||
register(rmcmessage, station_urls, conn_data).await
|
||||
}
|
||||
10
src/protocols/secure/mod.rs
Normal file
10
src/protocols/secure/mod.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
mod method_register;
|
||||
|
||||
use crate::define_protocol;
|
||||
use crate::protocols::secure::method_register::register_raw_params;
|
||||
|
||||
define_protocol!{
|
||||
11() => {
|
||||
0x01 => register_raw_params
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ use crate::rmc::message::RMCMessage;
|
|||
use crate::rmc::response::{RMCResponse, RMCResponseResult, send_response};
|
||||
use crate::rmc::response::ErrorCode::Core_NotImplemented;
|
||||
|
||||
type ContainedProtocolList = Box<[Box<dyn for<'a> Fn(&'a RMCMessage) -> Pin<Box<dyn Future<Output = Option<RMCResponse>> + Send + 'a>> + Send + Sync>]>;
|
||||
type ContainedProtocolList = Box<[Box<dyn for<'a> Fn(&'a RMCMessage, &'a mut ConnectionData) -> Pin<Box<dyn Future<Output = Option<RMCResponse>> + Send + 'a>> + Send + Sync>]>;
|
||||
|
||||
pub struct RMCProtocolServer(ContainedProtocolList);
|
||||
|
||||
|
|
@ -27,12 +27,14 @@ impl RMCProtocolServer{
|
|||
println!("recieved rmc message: {{ protocol: {}, method: {}}}", rmc.protocol_id, rmc.method_id);
|
||||
|
||||
for proto in &self.0 {
|
||||
if let Some(response) = proto(&rmc).await {
|
||||
if let Some(response) = proto(&rmc, connection).await {
|
||||
send_response(&packet, &socket, connection, response).await;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
error!("tried to send message to unimplemented protocol {} with method id {}", rmc.protocol_id, rmc.method_id);
|
||||
|
||||
send_response(&packet, &socket, connection, RMCResponse{
|
||||
protocol_id: rmc.protocol_id as u8,
|
||||
response_result: RMCResponseResult::Error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue