diff --git a/crates/obfs4/src/bin/fwd/main.rs b/crates/obfs4/src/bin/fwd/main.rs index 3251575..34b9c79 100644 --- a/crates/obfs4/src/bin/fwd/main.rs +++ b/crates/obfs4/src/bin/fwd/main.rs @@ -27,17 +27,6 @@ use tokio::{ }; use tokio::{net::ToSocketAddrs, task::JoinSet}; use tokio_util::sync::CancellationToken; -// use tokio_stream::StreamExt; -// use tor_chanmgr::transport::proxied::{settings_to_protocol, Protocol}; -// use tor_linkspec::PtTransportName; -// use tor_ptmgr::ipc::{ -// PtClientParameters, -// PtCommonParameters, -// PtServerParameters, -// // PluggableClientTransport, PluggableServerTransport, // PluggableTransport -// }; -// use tor_rtcompat::PreferredRuntime; -// use tor_socksproto::{SocksAuth, SocksVersion}; use tracing::{debug, error, info, warn, Level}; use tracing_subscriber::{filter::LevelFilter, prelude::*}; @@ -362,7 +351,7 @@ async fn server_setup( let mut listeners = Vec::new(); - let options = ptrs::args::Args::new(); + let options = ptrs::args::Args::parse_client_parameters(obfs4::dev::SERVER_ARGS)?; let mut builder = Obfs4PT::server_builder(); >::options( diff --git a/crates/obfs4/src/lib.rs b/crates/obfs4/src/lib.rs index 665e49c..94d126f 100644 --- a/crates/obfs4/src/lib.rs +++ b/crates/obfs4/src/lib.rs @@ -18,6 +18,8 @@ pub use pt::{Obfs4PT, Transport}; mod error; pub use error::{Error, Result}; +pub const NAME: &str = "obfs4"; + #[cfg(test)] pub(crate) mod test_utils; @@ -34,7 +36,8 @@ pub mod dev { pub const CLIENT_ARGS: &str = "cert=AAAAAAAAAAAAAAAAAAAAAAAAAADTSFvsGKxNFPBcGdOCBSgpEtJInG9zCYZezBPVBuBWag;iat-mode=0"; - pub const SERVER_ARGS: &str = ""; + pub const SERVER_ARGS: &str = "drbg-seed=abcdefabcdefabcdefabcdef;iat-mode=0;node-id=00112233445566778899;private-key=0123456789abcdeffedcba9876543210"; + pub fn print_dev_args() { let static_secret = StaticSecret::from(*DEV_PRIV_KEY); let sk = Obfs4NtorSecretKey::new(static_secret, RsaIdentity::from([0u8; NODE_ID_LENGTH])); diff --git a/crates/obfs4/src/obfs4/mod.rs b/crates/obfs4/src/obfs4/mod.rs index 731f09c..cefc13a 100644 --- a/crates/obfs4/src/obfs4/mod.rs +++ b/crates/obfs4/src/obfs4/mod.rs @@ -1,6 +1,6 @@ //! # obfs4 - The obfourscator -use crate::{traits::*, Result}; +// use crate::{traits::*, Result}; pub mod client; pub mod server; @@ -14,8 +14,6 @@ pub(crate) mod constants; pub(crate) mod handshake; pub(crate) mod sessions; -const NAME: &str = "obfs4"; - #[allow(non_camel_case_types)] pub enum Builder { client(ClientBuilder), diff --git a/crates/obfs4/src/obfs4/server.rs b/crates/obfs4/src/obfs4/server.rs index a8e4a22..f48a5a3 100644 --- a/crates/obfs4/src/obfs4/server.rs +++ b/crates/obfs4/src/obfs4/server.rs @@ -114,10 +114,7 @@ impl ServerBuilder { Ok(()) } - pub fn parse_state( - statedir: Option>, - args: Args, - ) -> Result { + fn parse_state(statedir: Option>, args: Args) -> Result { let mut required_args = args.clone(); // if the provided arguments do not satisfy all required arguments, we @@ -151,31 +148,36 @@ impl ServerBuilder { } } -#[derive(serde::Serialize, serde::Deserialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] struct JsonServerState { + #[serde(rename = "node-id")] node_id: Option, + #[serde(rename = "private-key")] private_key: Option, + #[serde(rename = "public-key")] public_key: Option, + #[serde(rename = "drbg-seed")] drbg_seed: Option, + #[serde(rename = "iat-mode")] iat_mode: Option, } impl JsonServerState { fn extend_args(self, args: &mut Args) { if let Some(id) = self.node_id { - args.add(NODE_ID_ARG.into(), &id); + args.add(NODE_ID_ARG, &id); } if let Some(sk) = self.private_key { - args.add(PRIVATE_KEY_ARG.into(), &sk); + args.add(PRIVATE_KEY_ARG, &sk); } if let Some(pubkey) = self.public_key { - args.add(PUBLIC_KEY_ARG.into(), &pubkey); + args.add(PUBLIC_KEY_ARG, &pubkey); } if let Some(seed) = self.drbg_seed { - args.add(SEED_ARG.into(), &seed); + args.add(SEED_ARG, &seed); } if let Some(mode) = self.iat_mode { - args.add(IAT_ARG.into(), &mode); + args.add(IAT_ARG, &mode); } } } @@ -360,11 +362,10 @@ mod tests { let mut args = Args::new(); let test_state = format!( - r#"{{"{NODE_ID_ARG}": "00112233445566778899", "{PRIVATE_KEY_ARG}":"0123456789abcdeffedcba9876543210", "{IAT_ARG}": "0", "{SEED_ARG}": "abcdefabcdefabcdefabcdef" }}"# + r#"{{"{NODE_ID_ARG}": "00112233445566778899", "{PRIVATE_KEY_ARG}":"0123456789abcdeffedcba9876543210", "{IAT_ARG}": "0", "{SEED_ARG}": "abcdefabcdefabcdefabcdef"}}"# ); - let state = ServerBuilder::server_state_from_json(test_state.as_bytes(), &mut args)?; - - trace!("ARGS ARGS {}", args.encode_smethod_args()); + ServerBuilder::server_state_from_json(test_state.as_bytes(), &mut args)?; + debug!("{:?}\n{}", args.encode_smethod_args(), test_state); Ok(()) } diff --git a/crates/obfs4/src/pt.rs b/crates/obfs4/src/pt.rs index 1710a74..552597c 100644 --- a/crates/obfs4/src/pt.rs +++ b/crates/obfs4/src/pt.rs @@ -141,14 +141,14 @@ where let node_id_strs = opts .retrieve(NODE_ID_ARG) .ok_or(format!("missing argument '{NODE_ID_ARG}'"))?; - let id = <[u8; NODE_ID_LENGTH]>::from_hex(&node_id_strs) + let id = <[u8; NODE_ID_LENGTH]>::from_hex(node_id_strs) .map_err(|e| format!("malformed node id: {e}"))?; let public_key_strs = opts .retrieve(PUBLIC_KEY_ARG) .ok_or(format!("missing argument '{PUBLIC_KEY_ARG}'"))?; - let pk = <[u8; 32]>::from_hex(&public_key_strs) + let pk = <[u8; 32]>::from_hex(public_key_strs) .map_err(|e| format!("malformed public key: {e}"))?; // Obfs4NtorPublicKey::new(pk, node_id) (pk, id) diff --git a/crates/ptrs/src/args.rs b/crates/ptrs/src/args.rs index db970c5..81d3079 100644 --- a/crates/ptrs/src/args.rs +++ b/crates/ptrs/src/args.rs @@ -96,7 +96,7 @@ impl Args { } pub fn retrieve(&self, key: impl AsRef) -> Option { - let v = self.get(key.as_ref().into())?; + let v = self.get(key.as_ref())?; if v.is_empty() { return None; }