diff --git a/0001-Switched-to-native-tls-altered-the-authentification.patch b/0001-Switched-to-native-tls-altered-the-authentification.patch new file mode 100644 index 0000000..1f405d7 --- /dev/null +++ b/0001-Switched-to-native-tls-altered-the-authentification.patch @@ -0,0 +1,425 @@ +From 2b0c2a3a698f737d87cd0dad6814d8bb1e164d22 Mon Sep 17 00:00:00 2001 +From: famfo +Date: Tue, 9 Nov 2021 16:22:10 +0100 +Subject: [PATCH] Switched to native-tls, altered the authentification + +--- + Cargo.lock | 212 +++++++++++++++++++++++++++++++++++++++++++++++++--- + Cargo.toml | 3 +- + config.toml | 3 +- + src/lib.rs | 29 +++++-- + src/main.rs | 4 +- + 5 files changed, 229 insertions(+), 22 deletions(-) + +diff --git a/Cargo.lock b/Cargo.lock +index 6c064b1..ef780e2 100644 +--- a/Cargo.lock ++++ b/Cargo.lock +@@ -30,13 +30,28 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + name = "circe" + version = "0.1.2" + dependencies = [ +- "openssl", +- "openssl-sys", ++ "native-tls", + "serde", + "serde_derive", + "toml", + ] + ++[[package]] ++name = "core-foundation" ++version = "0.9.2" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" ++dependencies = [ ++ "core-foundation-sys", ++ "libc", ++] ++ ++[[package]] ++name = "core-foundation-sys" ++version = "0.8.3" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" ++ + [[package]] + name = "foreign-types" + version = "0.3.2" +@@ -52,12 +67,56 @@ version = "0.1.1" + source = "registry+https://github.com/rust-lang/crates.io-index" + checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + ++[[package]] ++name = "getrandom" ++version = "0.2.3" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" ++dependencies = [ ++ "cfg-if", ++ "libc", ++ "wasi", ++] ++ ++[[package]] ++name = "lazy_static" ++version = "1.4.0" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" ++ + [[package]] + name = "libc" + version = "0.2.107" + source = "registry+https://github.com/rust-lang/crates.io-index" + checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" + ++[[package]] ++name = "log" ++version = "0.4.14" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" ++dependencies = [ ++ "cfg-if", ++] ++ ++[[package]] ++name = "native-tls" ++version = "0.2.8" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" ++dependencies = [ ++ "lazy_static", ++ "libc", ++ "log", ++ "openssl", ++ "openssl-probe", ++ "openssl-sys", ++ "schannel", ++ "security-framework", ++ "security-framework-sys", ++ "tempfile", ++] ++ + [[package]] + name = "once_cell" + version = "1.8.0" +@@ -79,13 +138,10 @@ dependencies = [ + ] + + [[package]] +-name = "openssl-src" +-version = "300.0.2+3.0.0" ++name = "openssl-probe" ++version = "0.1.4" + source = "registry+https://github.com/rust-lang/crates.io-index" +-checksum = "14a760a11390b1a5daf72074d4f6ff1a6e772534ae191f999f57e9ee8146d1fb" +-dependencies = [ +- "cc", +-] ++checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" + + [[package]] + name = "openssl-sys" +@@ -96,7 +152,6 @@ dependencies = [ + "autocfg", + "cc", + "libc", +- "openssl-src", + "pkg-config", + "vcpkg", + ] +@@ -107,6 +162,12 @@ version = "0.3.22" + source = "registry+https://github.com/rust-lang/crates.io-index" + checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f" + ++[[package]] ++name = "ppv-lite86" ++version = "0.2.15" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" ++ + [[package]] + name = "proc-macro2" + version = "1.0.32" +@@ -125,6 +186,97 @@ dependencies = [ + "proc-macro2", + ] + ++[[package]] ++name = "rand" ++version = "0.8.4" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" ++dependencies = [ ++ "libc", ++ "rand_chacha", ++ "rand_core", ++ "rand_hc", ++] ++ ++[[package]] ++name = "rand_chacha" ++version = "0.3.1" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" ++dependencies = [ ++ "ppv-lite86", ++ "rand_core", ++] ++ ++[[package]] ++name = "rand_core" ++version = "0.6.3" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" ++dependencies = [ ++ "getrandom", ++] ++ ++[[package]] ++name = "rand_hc" ++version = "0.3.1" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" ++dependencies = [ ++ "rand_core", ++] ++ ++[[package]] ++name = "redox_syscall" ++version = "0.2.10" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" ++dependencies = [ ++ "bitflags", ++] ++ ++[[package]] ++name = "remove_dir_all" ++version = "0.5.3" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" ++dependencies = [ ++ "winapi", ++] ++ ++[[package]] ++name = "schannel" ++version = "0.1.19" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" ++dependencies = [ ++ "lazy_static", ++ "winapi", ++] ++ ++[[package]] ++name = "security-framework" ++version = "2.4.2" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" ++dependencies = [ ++ "bitflags", ++ "core-foundation", ++ "core-foundation-sys", ++ "libc", ++ "security-framework-sys", ++] ++ ++[[package]] ++name = "security-framework-sys" ++version = "2.4.2" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" ++dependencies = [ ++ "core-foundation-sys", ++ "libc", ++] ++ + [[package]] + name = "serde" + version = "1.0.130" +@@ -153,6 +305,20 @@ dependencies = [ + "unicode-xid", + ] + ++[[package]] ++name = "tempfile" ++version = "3.2.0" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" ++dependencies = [ ++ "cfg-if", ++ "libc", ++ "rand", ++ "redox_syscall", ++ "remove_dir_all", ++ "winapi", ++] ++ + [[package]] + name = "toml" + version = "0.5.8" +@@ -173,3 +339,31 @@ name = "vcpkg" + version = "0.2.15" + source = "registry+https://github.com/rust-lang/crates.io-index" + checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" ++ ++[[package]] ++name = "wasi" ++version = "0.10.2+wasi-snapshot-preview1" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" ++ ++[[package]] ++name = "winapi" ++version = "0.3.9" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" ++dependencies = [ ++ "winapi-i686-pc-windows-gnu", ++ "winapi-x86_64-pc-windows-gnu", ++] ++ ++[[package]] ++name = "winapi-i686-pc-windows-gnu" ++version = "0.4.0" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" ++ ++[[package]] ++name = "winapi-x86_64-pc-windows-gnu" ++version = "0.4.0" ++source = "registry+https://github.com/rust-lang/crates.io-index" ++checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +diff --git a/Cargo.toml b/Cargo.toml +index 8344465..d1a6ec8 100644 +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -14,5 +14,4 @@ exclude = ["src/main.rs", "config.toml"] + toml = "0.5" + serde_derive = "1.0" + serde = "1.0" +-openssl = { version = "0.10", features = ["vendored"] } +-openssl-sys = "0.9" ++native-tls = "0.2" +diff --git a/config.toml b/config.toml +index 218d06a..ac31732 100644 +--- a/config.toml ++++ b/config.toml +@@ -1,6 +1,7 @@ + channels = ["#main", "#circe"] +-host = "192.168.1.28" ++host = "192.168.178.100" + mode = "+B" + nickname = "circe" + port = 6667 + username = "circe" ++ssl = false +diff --git a/src/lib.rs b/src/lib.rs +index 6cf2a0d..6fd0178 100644 +--- a/src/lib.rs ++++ b/src/lib.rs +@@ -21,7 +21,8 @@ + //! } + + #![warn(missing_docs)] +-use openssl::ssl::{SslConnector, SslMethod}; ++use native_tls::TlsConnector; ++ + use std::borrow::Cow; + use std::fs::File; + use std::io::{Error, Read, Write}; +@@ -34,7 +35,7 @@ use serde_derive::Deserialize; + pub struct Client { + config: Config, + stream: Option, +- sslstream: Option>, ++ sslstream: Option>, + } + + /// Config for the IRC client +@@ -261,11 +262,12 @@ impl Client { + /// Returns error if the client could not connect to the host. + pub fn new(config: Config) -> Result { + let stream = TcpStream::connect(format!("{}:{}", config.host, config.port))?; +- let sslstream: openssl::ssl::SslStream; ++ let sslstream: native_tls::TlsStream; + + if config.ssl { +- let connector = SslConnector::builder(SslMethod::tls())?.build(); ++ let connector = TlsConnector::new().unwrap(); + sslstream = connector.connect(config.host.as_str(), stream).unwrap(); ++ + return Ok(Self { + config, + stream: None, +@@ -289,7 +291,8 @@ impl Client { + /// ``` + /// Returns error if the client could not write to the stream. + pub fn identify(&mut self) -> Result<(), Error> { +- self.write_command(Command::CAP(CapMode::END))?; ++ self.write_command(Command::CAP(CapMode::LS))?; ++ + self.write_command(Command::USER( + self.config.username.clone(), + "*".into(), +@@ -303,11 +306,17 @@ impl Client { + self.write_command(Command::NICK(self.config.username.clone()))?; + } + ++ self.write_command(Command::CAP(CapMode::END))?; ++ + loop { + if let Ok(ref command) = self.read() { + match command { +- Command::PING(code) => self.write_command(Command::PONG(code.to_string()))?, ++ Command::PING(code) => { ++ println!("{}", code); ++ self.write_command(Command::PONG(code.to_string()))?; ++ } + Command::OTHER(line) => { ++ print!("{}", line); + if line.contains("001") { + break; + } +@@ -376,7 +385,8 @@ impl Client { + self.sslstream + .as_mut() + .unwrap() +- .write(formatted.as_bytes())?; ++ .write(formatted.as_bytes()) ++ .unwrap(); + } else { + self.stream.as_mut().unwrap().write(formatted.as_bytes())?; + } +@@ -677,7 +687,10 @@ impl Client { + if self.config.ssl { + self.sslstream.as_mut().unwrap().shutdown().unwrap(); + } else { +- self.stream.as_mut().unwrap().shutdown(std::net::Shutdown::Both)?; ++ self.stream ++ .as_mut() ++ .unwrap() ++ .shutdown(std::net::Shutdown::Both)?; + } + + Ok(()) +diff --git a/src/main.rs b/src/main.rs +index d440be5..0f63a35 100644 +--- a/src/main.rs ++++ b/src/main.rs +@@ -20,8 +20,8 @@ fn main() -> Result<(), std::io::Error> { + true, + "circe", + ); +- let mut client = Client::new(config)?; +- client.identify()?; ++ let mut client = Client::new(config).unwrap(); ++ client.identify().unwrap(); + + loop { + if let Ok(ref command) = client.read() { +-- +2.33.1 + diff --git a/Cargo.lock b/Cargo.lock index 6c064b1..ef780e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,13 +30,28 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" name = "circe" version = "0.1.2" dependencies = [ - "openssl", - "openssl-sys", + "native-tls", "serde", "serde_derive", "toml", ] +[[package]] +name = "core-foundation" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + [[package]] name = "foreign-types" version = "0.3.2" @@ -52,12 +67,56 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "native-tls" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "once_cell" version = "1.8.0" @@ -79,13 +138,10 @@ dependencies = [ ] [[package]] -name = "openssl-src" -version = "300.0.2+3.0.0" +name = "openssl-probe" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14a760a11390b1a5daf72074d4f6ff1a6e772534ae191f999f57e9ee8146d1fb" -dependencies = [ - "cc", -] +checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" [[package]] name = "openssl-sys" @@ -96,7 +152,6 @@ dependencies = [ "autocfg", "cc", "libc", - "openssl-src", "pkg-config", "vcpkg", ] @@ -107,6 +162,12 @@ version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f" +[[package]] +name = "ppv-lite86" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" + [[package]] name = "proc-macro2" version = "1.0.32" @@ -125,6 +186,97 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core", +] + +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + +[[package]] +name = "security-framework" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.130" @@ -153,6 +305,20 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "tempfile" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +dependencies = [ + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi", +] + [[package]] name = "toml" version = "0.5.8" @@ -173,3 +339,31 @@ name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 8344465..d1a6ec8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,5 +14,4 @@ exclude = ["src/main.rs", "config.toml"] toml = "0.5" serde_derive = "1.0" serde = "1.0" -openssl = { version = "0.10", features = ["vendored"] } -openssl-sys = "0.9" +native-tls = "0.2" diff --git a/config.toml b/config.toml index 218d06a..ac31732 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,7 @@ channels = ["#main", "#circe"] -host = "192.168.1.28" +host = "192.168.178.100" mode = "+B" nickname = "circe" port = 6667 username = "circe" +ssl = false diff --git a/src/lib.rs b/src/lib.rs index 6cf2a0d..99452e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,8 @@ //! } #![warn(missing_docs)] -use openssl::ssl::{SslConnector, SslMethod}; +use native_tls::TlsConnector; + use std::borrow::Cow; use std::fs::File; use std::io::{Error, Read, Write}; @@ -34,7 +35,7 @@ use serde_derive::Deserialize; pub struct Client { config: Config, stream: Option, - sslstream: Option>, + sslstream: Option>, } /// Config for the IRC client @@ -261,11 +262,12 @@ impl Client { /// Returns error if the client could not connect to the host. pub fn new(config: Config) -> Result { let stream = TcpStream::connect(format!("{}:{}", config.host, config.port))?; - let sslstream: openssl::ssl::SslStream; + let sslstream: native_tls::TlsStream; if config.ssl { - let connector = SslConnector::builder(SslMethod::tls())?.build(); + let connector = TlsConnector::new().unwrap(); sslstream = connector.connect(config.host.as_str(), stream).unwrap(); + return Ok(Self { config, stream: None, @@ -306,8 +308,12 @@ impl Client { loop { if let Ok(ref command) = self.read() { match command { - Command::PING(code) => self.write_command(Command::PONG(code.to_string()))?, + Command::PING(code) => { + println!("{}", code); + self.write_command(Command::PONG(code.to_string()))?; + } Command::OTHER(line) => { + print!("{}", line); if line.contains("001") { break; } @@ -372,11 +378,15 @@ impl Client { let new = format!("{}\r\n", data); Cow::Owned(new) as Cow }; + + println!("{:?}", formatted); + if self.config.ssl { self.sslstream .as_mut() .unwrap() - .write(formatted.as_bytes())?; + .write(formatted.as_bytes()) + .unwrap(); } else { self.stream.as_mut().unwrap().write(formatted.as_bytes())?; } @@ -677,7 +687,10 @@ impl Client { if self.config.ssl { self.sslstream.as_mut().unwrap().shutdown().unwrap(); } else { - self.stream.as_mut().unwrap().shutdown(std::net::Shutdown::Both)?; + self.stream + .as_mut() + .unwrap() + .shutdown(std::net::Shutdown::Both)?; } Ok(()) diff --git a/src/main.rs b/src/main.rs index d440be5..0f63a35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,8 +20,8 @@ fn main() -> Result<(), std::io::Error> { true, "circe", ); - let mut client = Client::new(config)?; - client.identify()?; + let mut client = Client::new(config).unwrap(); + client.identify().unwrap(); loop { if let Ok(ref command) = client.read() {