Compare commits
No commits in common. "d74d8184c387fa7af73fca65e2a7a655d7a70b21" and "322f473671adc736360358a2ab0bee5bd96655b7" have entirely different histories.
d74d8184c3
...
322f473671
12
config.toml
12
config.toml
@ -2,13 +2,7 @@ server = "irc.supernets.org"
|
||||
port = 6697
|
||||
use_ssl = true
|
||||
nickname = "g1r"
|
||||
channel = "#superbowl"
|
||||
sasl_username = ""
|
||||
sasl_password = ""
|
||||
channel = "#dev"
|
||||
sasl_username = "g1r"
|
||||
sasl_password = "fuckyou.lol"
|
||||
capabilities = ["sasl"]
|
||||
use_proxy = false
|
||||
proxy_type = "socks5"
|
||||
proxy_addr = "127.0.0.1"
|
||||
proxy_port = 9050
|
||||
proxy_username = ""
|
||||
proxy_password = ""
|
||||
|
76
src/main.rs
76
src/main.rs
@ -1,4 +1,4 @@
|
||||
use tokio::io::{split, AsyncRead, AsyncWrite, AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::io::{split, AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_native_tls::native_tls::TlsConnector as NTlsConnector;
|
||||
use tokio_native_tls::TlsConnector;
|
||||
@ -7,7 +7,6 @@ use serde::Deserialize;
|
||||
use std::fs;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use colored::*;
|
||||
use tokio_socks::tcp::Socks5Stream;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Config {
|
||||
@ -19,14 +18,6 @@ struct Config {
|
||||
sasl_username: Option<String>,
|
||||
sasl_password: Option<String>,
|
||||
capabilities: Option<Vec<String>>,
|
||||
|
||||
// Proxy
|
||||
use_proxy: bool,
|
||||
proxy_type: Option<String>,
|
||||
proxy_addr: Option<String>,
|
||||
proxy_port: Option<u16>,
|
||||
proxy_username: Option<String>,
|
||||
proxy_password: Option<String>,
|
||||
}
|
||||
|
||||
mod mods {
|
||||
@ -44,34 +35,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = loaded_config().expect("Error parsing config.toml");
|
||||
println!("Config loaded!");
|
||||
|
||||
let server = format!("{}:{}", config.server, config.port);
|
||||
|
||||
if config.use_ssl {
|
||||
if config.use_proxy {
|
||||
let tcp_stream = proxy_exec(&config).await;
|
||||
match tcp_stream {
|
||||
Ok(tcp_stream) => {
|
||||
let tls_stream = tls_exec(&config, tcp_stream).await;
|
||||
match tls_stream {
|
||||
Ok(tls_stream) => {
|
||||
if let Err(e) = handler(tls_stream, config).await {
|
||||
println!("Error handling TLS connection: {}", e);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Error establishing TLS connection: {}", e);
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Error connecting to proxy: {}", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let tcp_stream = TcpStream::connect(server).await.expect("Error connecting to server");
|
||||
let tls_stream = tls_exec(&config, tcp_stream).await.expect("Error establishing TLS connection");
|
||||
let tcp_stream = TcpStream::connect(format!("{}:{}", config.server, config.port)).await;
|
||||
println!("Connected to {}!", format!("{}:{}", config.server, config.port).green());
|
||||
|
||||
println!("Establishing TLS connection...");
|
||||
let mut tls_stream = tls_exec (&config, tcp_stream.unwrap()).await.unwrap();
|
||||
println!("TLS connection established!");
|
||||
tls_stream.flush().await.unwrap();
|
||||
|
||||
handler(tls_stream, config).await.unwrap();
|
||||
}
|
||||
} else {
|
||||
println!("Non-SSL connection not implemented.");
|
||||
}
|
||||
@ -87,37 +60,12 @@ fn loaded_config() -> Result<Config, Box<dyn std::error::Error>> {
|
||||
}
|
||||
|
||||
/// Establish a TLS connection to the server
|
||||
async fn tls_exec(config: &Config, tcp_stream: TcpStream) -> Result<tokio_native_tls::TlsStream<TcpStream>, Box<dyn std::error::Error + Send>> {
|
||||
let tls_builder = NTlsConnector::builder().danger_accept_invalid_certs(true).build().unwrap();
|
||||
async fn tls_exec(config: &Config, tcp_stream: TcpStream) -> Result<tokio_native_tls::TlsStream<TcpStream>, Box<dyn std::error::Error>> {
|
||||
let tls_builder = NTlsConnector::builder().danger_accept_invalid_certs(true).build()?;
|
||||
let tls_connector = TlsConnector::from(tls_builder);
|
||||
Ok(tls_connector.connect(&config.server, tcp_stream).await.unwrap())
|
||||
|
||||
Ok(tls_connector.connect(&config.server, tcp_stream).await?)
|
||||
}
|
||||
|
||||
/// Establish a connection to the proxy
|
||||
async fn proxy_exec(config: &Config) -> Result<TcpStream, Box<dyn std::error::Error + Send>> {
|
||||
let proxy_addr = match config.proxy_addr.as_ref() {
|
||||
Some(addr) => addr,
|
||||
None => "127.0.0.1",
|
||||
};
|
||||
let proxy_port = config.proxy_port.unwrap_or(9050);
|
||||
let proxy = format!("{}:{}", proxy_addr, proxy_port);
|
||||
let server = format!("{}:{}", config.server, config.port);
|
||||
let proxy_stream = TcpStream::connect(proxy).await.unwrap();
|
||||
let username = config.proxy_username.clone().unwrap();
|
||||
let password = config.proxy_password.clone().unwrap();
|
||||
let tcp_stream = if !&username.is_empty() && !password.is_empty() {
|
||||
let tcp_stream = Socks5Stream::connect_with_password_and_socket(proxy_stream, server, &username, &password).await.unwrap();
|
||||
tcp_stream
|
||||
|
||||
} else {
|
||||
let tcp_stream = Socks5Stream::connect_with_socket(proxy_stream, server).await.unwrap();
|
||||
tcp_stream
|
||||
};
|
||||
let tcp_stream = tcp_stream.into_inner();
|
||||
|
||||
Ok(tcp_stream)
|
||||
}
|
||||
|
||||
/// Handle the connection to the server
|
||||
async fn handler(tls_stream: tokio_native_tls::TlsStream<TcpStream>, config: Config) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
Loading…
Reference in New Issue
Block a user