Fixed identity and check for Tor availability

debug-remodel-tor
Daniel Karzel 3 years ago committed by Thomas Eizinger
parent 6fd36dbeb5
commit b51c7bcd36
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96

@ -25,3 +25,4 @@ tempfile = "3"
testcontainers = "0.12"
tokio = { version = "1", features = [ "full" ] }
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "chrono", "tracing-log" ] }
reqwest = { version = "0.11", features = [ "rustls-tls", "stream", "socks" ], default-features = false }

@ -6,14 +6,30 @@ use libp2p::{identity, noise, yamux, Multiaddr, Swarm, Transport};
use libp2p_tor::dial_only;
use std::time::Duration;
use libp2p::mplex::MplexConfig;
use anyhow::{anyhow, bail, Result};
use tracing_subscriber::util::SubscriberInitExt;
#[tokio::main]
async fn main() {
let arg = std::env::args()
.last()
.unwrap();
async fn main() -> Result<()> {
let _guard = tracing_subscriber::fmt()
.with_env_filter("debug,libp2p_tor=debug") // add `reqwest::connect::verbose=trace` if you want to logs of the RPC clients
.with_test_writer()
.set_default();
let proxy = reqwest::Proxy::all("socks5h://127.0.0.1:9050")
.map_err(|_| anyhow!("tor proxy should be there"))?;
let client = reqwest::Client::builder().proxy(proxy).build()?;
let res = client.get("https://check.torproject.org").send().await?;
let text = res.text().await?;
if !text.contains("Congratulations. This browser is configured to use Tor.") {
bail!("Tor is currently not running")
}
let addr_to_dial = arg
let addr_to_dial = "/onion3/jpclybnowuibjexya3qggzvzkoeruuav4nyjlxpnkrosldsvykfbn6qd:7654/p2p/12D3KooWHKqGyK4hVtf5BQY8GpbY6fSGKDZ8eBXMQ3H2RsdnKVzC"
.parse::<Multiaddr>()
.unwrap();

@ -6,17 +6,26 @@ use libp2p::{identity, noise, yamux, Swarm, Transport, Multiaddr};
use libp2p_tor::duplex;
use libp2p_tor::torut_ext::AuthenticatedConnectionExt;
use noise::NoiseConfig;
use rand::Rng;
use std::time::Duration;
use torut::control::AuthenticatedConn;
use torut::onion::TorSecretKeyV3;
use std::str::FromStr;
use libp2p::mplex::MplexConfig;
use libp2p::identity::Keypair;
use tracing_subscriber::util::SubscriberInitExt;
#[tokio::main]
async fn main() {
let key = random_onion_identity();
let _guard = tracing_subscriber::fmt()
.with_env_filter("debug,libp2p_tor=debug") // add `reqwest::connect::verbose=trace` if you want to logs of the RPC clients
.with_test_writer()
.set_default();
tracing::debug!("test");
let key = fixed_onion_identity();
let onion_address = key.public().get_onion_address().get_address_without_dot_onion();
let onion_port = 7654;
@ -66,7 +75,7 @@ async fn main() {
/// In particular, this swarm can create ephemeral hidden services on the
/// configured Tor node.
async fn new_swarm(key: TorSecretKeyV3) -> Swarm<Ping> {
let identity = identity::Keypair::generate_ed25519();
let identity = fixed_libp2p_identity();
SwarmBuilder::new(
duplex::TorConfig::new(
@ -100,9 +109,16 @@ async fn new_swarm(key: TorSecretKeyV3) -> Swarm<Ping> {
.build()
}
fn random_onion_identity() -> TorSecretKeyV3 {
let mut onion_key_bytes = [0u8; 64];
rand::thread_rng().fill(&mut onion_key_bytes);
fn fixed_onion_identity() -> TorSecretKeyV3 {
// randomly generated bytes, corresponding onion address: jpclybnowuibjexya3qggzvzkoeruuav4nyjlxpnkrosldsvykfbn6qd
let fixed_onion_bytes = [7, 164, 217, 80, 139, 239, 11, 110, 37, 77, 191, 158, 206, 252, 178, 188, 147, 98, 54, 13, 35, 183, 114, 231, 202, 38, 30, 29, 245, 8, 118, 153, 55, 141, 228, 109, 78, 189, 120, 28, 172, 131, 198, 55, 113, 47, 131, 135, 139, 117, 182, 195, 46, 34, 234, 169, 85, 96, 203, 215, 7, 155, 209, 211];
fixed_onion_bytes.into()
}
fn fixed_libp2p_identity() -> Keypair {
// randomly venerated bytes, corresponding peer-id: 12D3KooWHKqGyK4hVtf5BQY8GpbY6fSGKDZ8eBXMQ3H2RsdnKVzC
let fixed_identity = [75,146,26,107,50,252,71,2,238,224,92,112,216,238,131,57,84,9,218,120,195,9,129,102,42,206,165,102,32,238,158,248];
onion_key_bytes.into()
let key = identity::ed25519::SecretKey::from_bytes(fixed_identity).expect("we always pass 32 bytes");
identity::Keypair::Ed25519(key.into())
}

@ -11,7 +11,7 @@ pub mod torut_ext;
async fn dial_via_tor(onion_address: String, socks_port: u16) -> anyhow::Result<TcpStream, Error> {
let sock = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, socks_port));
let stream = Socks5Stream::connect(sock, onion_address)
let stream = Socks5Stream::connect(sock, dbg!(onion_address))
.await
.map_err(Error::UnreachableProxy)?;
let stream = TcpStream(stream.into_inner());

Loading…
Cancel
Save