Skip to content

Commit

Permalink
all compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwample committed Mar 26, 2024
1 parent 180f25f commit 91d3eb3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 33 deletions.
13 changes: 1 addition & 12 deletions crates/obfs4/src/bin/fwd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*};

Expand Down Expand Up @@ -362,7 +351,7 @@ async fn server_setup<A: ToSocketAddrs>(

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();
<obfs4::obfs4::ServerBuilder as ptrs::ServerBuilder<TcpStream>>::options(
Expand Down
5 changes: 4 additions & 1 deletion crates/obfs4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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]));
Expand Down
4 changes: 1 addition & 3 deletions crates/obfs4/src/obfs4/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! # obfs4 - The obfourscator

use crate::{traits::*, Result};
// use crate::{traits::*, Result};

pub mod client;
pub mod server;
Expand All @@ -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),
Expand Down
29 changes: 15 additions & 14 deletions crates/obfs4/src/obfs4/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ impl ServerBuilder {
Ok(())
}

pub fn parse_state(
statedir: Option<impl AsRef<str>>,
args: Args,
) -> Result<RequiredServerState> {
fn parse_state(statedir: Option<impl AsRef<str>>, args: Args) -> Result<RequiredServerState> {
let mut required_args = args.clone();

// if the provided arguments do not satisfy all required arguments, we
Expand Down Expand Up @@ -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<String>,
#[serde(rename = "private-key")]
private_key: Option<String>,
#[serde(rename = "public-key")]
public_key: Option<String>,
#[serde(rename = "drbg-seed")]
drbg_seed: Option<String>,
#[serde(rename = "iat-mode")]
iat_mode: Option<String>,
}

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);
}
}
}
Expand Down Expand Up @@ -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(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/obfs4/src/pt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion crates/ptrs/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Args {
}

pub fn retrieve(&self, key: impl AsRef<str>) -> Option<String> {
let v = self.get(key.as_ref().into())?;
let v = self.get(key.as_ref())?;
if v.is_empty() {
return None;
}
Expand Down

0 comments on commit 91d3eb3

Please sign in to comment.