From 4ad13df49903a5ada692ef80dab7c537b1181d08 Mon Sep 17 00:00:00 2001 From: Alex Yusiuk <55661041+RRRadicalEdward@users.noreply.github.com> Date: Thu, 30 Mar 2023 01:34:07 +0300 Subject: [PATCH] feat(ironrdp-client): add ability to collect sspi-rs logs (#100) --- Cargo.lock | 104 ++++++++++++++++++++++++- ffi/wasm/Cargo.toml | 2 +- iron-tauri-client/src-tauri/Cargo.toml | 2 +- ironrdp-client-glutin/Cargo.toml | 2 +- ironrdp-client/Cargo.toml | 4 +- ironrdp-client/src/main.rs | 29 +++++++ ironrdp-session/Cargo.toml | 2 +- 7 files changed, 138 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5caec781..db7a7691 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1652,6 +1652,8 @@ dependencies = [ "tokio", "tokio-rustls", "tokio-util", + "tracing", + "tracing-subscriber", "whoami", "winit 0.28.2", "x509-parser 0.14.0", @@ -1952,6 +1954,15 @@ dependencies = [ "libc", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + [[package]] name = "md-5" version = "0.8.0" @@ -2223,6 +2234,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-bigint" version = "0.2.6" @@ -2550,6 +2571,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "owned_ttf_parser" version = "0.18.1" @@ -3051,6 +3078,24 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + [[package]] name = "regex-syntax" version = "0.6.28" @@ -3523,6 +3568,15 @@ dependencies = [ "keccak", ] +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + [[package]] name = "shared_library" version = "0.1.9" @@ -3682,9 +3736,9 @@ dependencies = [ [[package]] name = "sspi" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e676b09028bca74185041e073a467e71112c19e4032fc290df82a4ad10c390e" +checksum = "f820e38002148b97ce7e90eb4c77fb81023c304b87a74f396893157d8a6521c9" dependencies = [ "async-dnssd", "bitflags", @@ -3837,6 +3891,16 @@ dependencies = [ "syn 1.0.104", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", +] + [[package]] name = "time" version = "0.1.45" @@ -4044,6 +4108,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] @@ -4142,6 +4236,12 @@ dependencies = [ "serde", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/ffi/wasm/Cargo.toml b/ffi/wasm/Cargo.toml index c1e66e56..ce74f669 100644 --- a/ffi/wasm/Cargo.toml +++ b/ffi/wasm/Cargo.toml @@ -28,7 +28,7 @@ opt-level = "s" ironrdp = { path = "../../ironrdp" } ironrdp-session = { path = "../../ironrdp-session", features = ["dgw_ext"] } # FIXME: secret feature until session state machine is done ironrdp-input = { path = "../../ironrdp-input" } -sspi = "0.7" +sspi = "0.8" # Wasm wasm-bindgen = "0.2.83" diff --git a/iron-tauri-client/src-tauri/Cargo.toml b/iron-tauri-client/src-tauri/Cargo.toml index 1f25b102..2c047e94 100644 --- a/iron-tauri-client/src-tauri/Cargo.toml +++ b/iron-tauri-client/src-tauri/Cargo.toml @@ -21,7 +21,7 @@ custom-protocol = [ "tauri/custom-protocol" ] # Protocol ironrdp = { path = "../../ironrdp" } -sspi = { version = "0.7", features = ["network_client"] } +sspi = { version = "0.8", features = ["network_client"] } serde = { version = "1.0", features = ["derive"] } # SSL diff --git a/ironrdp-client-glutin/Cargo.toml b/ironrdp-client-glutin/Cargo.toml index 3c8365aa..54854a8e 100644 --- a/ironrdp-client-glutin/Cargo.toml +++ b/ironrdp-client-glutin/Cargo.toml @@ -18,7 +18,7 @@ native-tls = ["dep:async-native-tls", "ironrdp/native-tls"] # Protocol ironrdp = { path = "../ironrdp" } -sspi = { version = "0.7", features = ["network_client"] } +sspi = { version = "0.8", features = ["network_client"] } # CLI clap = { version = "4.0", features = ["derive", "cargo"] } diff --git a/ironrdp-client/Cargo.toml b/ironrdp-client/Cargo.toml index ae2706ee..6a130e92 100644 --- a/ironrdp-client/Cargo.toml +++ b/ironrdp-client/Cargo.toml @@ -19,7 +19,7 @@ native-tls = ["dep:async-native-tls", "ironrdp/native-tls"] # Protocol ironrdp = { path = "../ironrdp" } ironrdp-input = { path = "../ironrdp-input" } -sspi = { version = "0.7", features = ["network_client"] } # TODO: enable dns_resolver at some point +sspi = { version = "0.8.0", features = ["network_client"] } # TODO: enable dns_resolver at some point # GUI softbuffer = "0.2.0" @@ -49,3 +49,5 @@ chrono = "0.4.23" whoami = "1.2.3" anyhow = "1.0.68" smallvec = "1.10.0" +tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } +tracing = "0.1.37" diff --git a/ironrdp-client/src/main.rs b/ironrdp-client/src/main.rs index a23d754e..135011e0 100644 --- a/ironrdp-client/src/main.rs +++ b/ironrdp-client/src/main.rs @@ -1,11 +1,15 @@ #[macro_use] extern crate log; +use std::fs::OpenOptions; + use anyhow::Context as _; use ironrdp_client::config::Config; use ironrdp_client::gui::GuiContext; use ironrdp_client::rdp::{RdpClient, RdpInputEvent}; use tokio::runtime; +use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt; +use tracing_subscriber::EnvFilter; fn main() -> anyhow::Result<()> { let mut config = Config::parse_args().context("CLI arguments parsing")?; @@ -57,5 +61,30 @@ fn setup_logging(log_file: &str) -> Result<(), fern::InitError> { .chain(fern::log_file(log_file)?) .apply()?; + // sspi-rs logging + if let Ok(path) = std::env::var("SSPI_LOG_FILE") { + let file = match OpenOptions::new().read(true).append(true).open(path) { + Ok(file) => file, + Err(e) => { + warn!("Can not open sspi-rs log file: {:?}", e); + + return Ok(()); + } + }; + + let fmt_layer = tracing_subscriber::fmt::layer() + .pretty() + .with_thread_names(true) + .with_writer(file); + + let reg = tracing_subscriber::registry() + .with(fmt_layer) + .with(EnvFilter::from_env("SSPI_LOG_LEVEL")); + + if let Err(err) = tracing::subscriber::set_global_default(reg) { + warn!("Can not set sspi-rs logger: {:?}", err); + } + } + Ok(()) } diff --git a/ironrdp-session/Cargo.toml b/ironrdp-session/Cargo.toml index 3049e299..018df07d 100644 --- a/ironrdp-session/Cargo.toml +++ b/ironrdp-session/Cargo.toml @@ -18,7 +18,7 @@ dgw_ext = [] ironrdp-core = { path = "../ironrdp-core" } ironrdp-graphics = { path = "../ironrdp-graphics" } ironrdp-rdcleanpath = { path = "../ironrdp-rdcleanpath" } # FIXME: Quick and dirty approach, this should not be here -sspi = "0.7" +sspi = "0.8" bytes = "1" log = "0.4" whoami = "1"