Crates.io | tor-interface |
lib.rs | tor-interface |
version | 0.4.0 |
source | src |
created_at | 2023-12-03 22:14:49.096351 |
updated_at | 2024-08-24 21:48:12.294993 |
description | A library providing a Rust interface to interact with the legacy tor daemon |
homepage | |
repository | https://github.com/blueprint-freespeech/gosling |
max_upload_size | |
id | 1057105 |
size | 245,030 |
Developer-friendly crate providing connectivity to the Tor Network and functionality for interacting with Tor-specific cryptographic types.
This crate is not meant to be a general purpose Tor Controller nor does it aim to expose all of the functionality of the underlying Tor implementations. This crate also does not implement any of the Tor Network functionality itself, instead wrapping lower-level implementations.
The tor-interface
crate provides the TorProvider
trait with 3 concrete implementations:
arti-client
crate; enabled using the arti-client-tor-provider feature flag.The TorProvider
trait defines methods for connecting to various types of target addresses (ip, domains, and onion-services) and for creating onion-services.
The arti-client-tor-provider feature is experimental is not fully implemented. It also depends on the arti-client
crate which is still under active development and is generally not yet ready for production use.
The following code snippet creates a LegacyTorClient
which starts a bundled tor daemon, bootstraps, and attempts to connect to www.example.com.
# use std::str::FromStr;
# use std::net::TcpStream;
# use tor_interface::legacy_tor_client::{LegacyTorClient, LegacyTorClientConfig};
# use tor_interface::tor_provider::{OnionStream, TargetAddr, TorEvent, TorProvider};
# return;
// construct legacy tor client config
let tor_path = std::path::PathBuf::from_str("/usr/bin/tor").unwrap();
let mut data_path = std::env::temp_dir();
data_path.push("tor_data");
let tor_config = LegacyTorClientConfig::BundledTor {
tor_bin_path: tor_path,
data_directory: data_path,
proxy_settings: None,
allowed_ports: None,
pluggable_transports: None,
bridge_lines: None,
};
// create client from config
let mut tor_client = LegacyTorClient::new(tor_config).unwrap();
// bootstrap tor
let mut bootstrap_complete = false;
while !bootstrap_complete {
for event in tor_client.update().unwrap().iter() {
match event {
TorEvent::BootstrapComplete => {
bootstrap_complete = true;
},
_ => {},
}
}
}
// connect to example.com
let target_addr = TargetAddr::from_str("www.example.com:80").unwrap();
let mut stream: OnionStream = tor_client.connect(target_addr, None).unwrap();
// and convert to a std::net::TcpStream
let stream: TcpStream = stream.into();