Commit 3ad203d4 authored by David Goulet's avatar David Goulet
Browse files

Packet being relayed over tor using arti



Signed-off-by: default avatarDavid Goulet <dgoulet@ev0ke.net>
parent ec1c6e28
Loading
Loading
Loading
Loading
+2437 −123

File changed.

Preview size limit exceeded, changes collapsed.

+2 −0
Original line number Diff line number Diff line
@@ -9,3 +9,5 @@ log = "0.4"
simple_logger = "1"
smoltcp = { version = "0.8.0", default-features = false, features = ["log", "phy-tuntap_interface", "phy-raw_socket", "medium-ip", "socket-udp", "socket-tcp", "proto-ipv4", "socket", "async"], git = "https://github.com/dgoulet-tor/smoltcp.git", rev = "8cb96670e672dfe6f7ef271ef1a3648734f94bfc" }
tokio = { version = "1", features = ["net", "rt", "time", "sync", "io-util", "macros"] }
arti-client = { git = "https://gitlab.torproject.org/tpo/core/arti.git" }
tor-rtcompat = { git = "https://gitlab.torproject.org/tpo/core/arti.git", features = ["tokio"] }
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ where
        }
    }

    pub fn device(&self) -> &AsyncFd<D> {
    pub fn _device(&self) -> &AsyncFd<D> {
        &self.device
    }

+2 −1
Original line number Diff line number Diff line
@@ -71,7 +71,8 @@ impl OnionTunnel {

            // Handle incoming packet. Drain packets as we process them.
            while let Some(packet) = packets.pop_front() {
                if let Some(tcp_socket) = Parser::parse(packet.clone()).take() {
                if let Some(tcp_socket) = Parser::parse(packet.clone()).take()
                {
                    let socket = TcpSocket::new(self.iface.clone(), tcp_socket);
                    self.proxy(socket);
                }
+37 −5
Original line number Diff line number Diff line
use arti_client::DangerouslyIntoTorAddr;
use arti_client::{TorClient, TorClientConfig};
use log::info;
use tokio::io::AsyncReadExt;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tor_rtcompat::tokio::TokioNativeTlsRuntime;

use crate::socket::TcpSocket;

@@ -15,13 +18,42 @@ impl ArtiProxy {
    pub async fn start(&mut self) {
        info!("Starting Arti Proxy");

        let config = TorClientConfig::default();
        let rt: TokioNativeTlsRuntime = tokio::runtime::Handle::current().into();

        let arti = TorClient::bootstrap(rt, config).await.unwrap();
        info!("Arti bootstrap finalized.");

        let dest = self.socket.dest();
        info!("Connecting to: {:?}", dest);
        let mut arti_stream = arti
            .connect(dest.into_tor_addr_dangerously().unwrap())
            .await
            .unwrap();
        info!("Connected to: {:?}", dest);

        loop {
            let mut buffer = [0; 4096];
            let mut arti_buf = Vec::new();
            let mut tun_buf = Vec::new();

            info!("Reading on socket...");
            tokio::select! {
                r = self.socket.read(&mut buffer[..]) => match r {
                    Ok(_) => break,
                r = self.socket.read_buf(&mut tun_buf) => match r {
                    Ok(n) => {
                        if n > 0 {
                            let ret = arti_stream.write_all(tun_buf.as_slice()).await;
                            let _ = arti_stream.flush().await;
                            info!("Write to arti: {:?}", ret);
                        }
                    }
                    Err(_) => break,
                },
                r = arti_stream.read_buf(&mut arti_buf) => match r {
                    Ok(n) => {
                        if n > 0 {
                            let ret = self.socket.write(arti_buf.as_slice()).await;
                            info!("Write to onioni0: {:?}", ret);
                        }
                    }
                    Err(_) => break,
                }
            };
Loading