Compare commits
2 Commits
322f473671
...
d74d8184c3
Author | SHA1 | Date | |
---|---|---|---|
d74d8184c3 | |||
e20cb7e996 |
12
config.toml
12
config.toml
@ -2,7 +2,13 @@ server = "irc.supernets.org"
|
||||
port = 6697
|
||||
use_ssl = true
|
||||
nickname = "g1r"
|
||||
channel = "#dev"
|
||||
sasl_username = "g1r"
|
||||
sasl_password = "fuckyou.lol"
|
||||
channel = "#superbowl"
|
||||
sasl_username = ""
|
||||
sasl_password = ""
|
||||
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, AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::io::{split, AsyncRead, AsyncWrite, AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_native_tls::native_tls::TlsConnector as NTlsConnector;
|
||||
use tokio_native_tls::TlsConnector;
|
||||
@ -7,6 +7,7 @@ use serde::Deserialize;
|
||||
use std::fs;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use colored::*;
|
||||
use tokio_socks::tcp::Socks5Stream;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Config {
|
||||
@ -18,6 +19,14 @@ 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 {
|
||||
@ -35,16 +44,34 @@ 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 {
|
||||
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();
|
||||
|
||||
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");
|
||||
handler(tls_stream, config).await.unwrap();
|
||||
}
|
||||
} else {
|
||||
println!("Non-SSL connection not implemented.");
|
||||
}
|
||||
@ -60,12 +87,37 @@ 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>> {
|
||||
let tls_builder = NTlsConnector::builder().danger_accept_invalid_certs(true).build()?;
|
||||
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();
|
||||
let tls_connector = TlsConnector::from(tls_builder);
|
||||
Ok(tls_connector.connect(&config.server, tcp_stream).await?)
|
||||
Ok(tls_connector.connect(&config.server, tcp_stream).await.unwrap())
|
||||
|
||||
}
|
||||
|
||||
/// 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