BlueGit

ict rusty-teams

fix(session): pick the ring TLS provider before any TLS use

- both rustls providers are compiled in on Windows, rustls then panicked on the native Trouter connect
- installed at app start, before the HTTP client and before each Trouter connect

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-10 · 2 weeks ago

Hash
18fd4a74cb171a62867ad92648a2210ff999bf71
Parent
a90f6b44
5 files changed +12 −0
crates/app/src/main.rs +1 −0
@@ -157,6 +157,7 @@ fn open_store(path: &std::path::Path) -> Store {
157 157 }
158 158
159 159 fn main() {
160 session::ensure_crypto_provider();
160 161 app_base::version::set_build_version(VERSION_MARKER.trim_start_matches("teams-build:"));
161 162 if let Some(tag) = option_env!("TEAMS_RELEASE_TAG") {
162 163 app_base::version::set_release_tag(tag);
@@ -157,6 +157,7 @@ fn open_store(path: &std::path::Path) -> Store {
157}
157}
158
158
159fn main() {
159fn main() {
160 session::ensure_crypto_provider();
160 app_base::version::set_build_version(VERSION_MARKER.trim_start_matches("teams-build:"));
161 app_base::version::set_build_version(VERSION_MARKER.trim_start_matches("teams-build:"));
161 if let Some(tag) = option_env!("TEAMS_RELEASE_TAG") {
162 if let Some(tag) = option_env!("TEAMS_RELEASE_TAG") {
162 app_base::version::set_release_tag(tag);
163 app_base::version::set_release_tag(tag);
crates/chatsvc/src/realtime/native.rs +1 −0
@@ -351,6 +351,7 @@ impl NativeTrouter {
351 351 return Err(None);
352 352 }
353 353 };
354 session::ensure_crypto_provider();
354 355 let url = socket_url(&self.host, &self.endpoint_id, &uuid::Uuid::new_v4().to_string(), now_ms() as u128);
355 356 let Ok(Ok((socket, _))) = timeout(CONNECT_TIMEOUT, connect_async(url.as_str())).await else {
356 357 self.forward(&status_payload("disconnected", "connect_failed"));
@@ -351,6 +351,7 @@ impl NativeTrouter {
351 return Err(None);
351 return Err(None);
352 }
352 }
353 };
353 };
354 session::ensure_crypto_provider();
354 let url = socket_url(&self.host, &self.endpoint_id, &uuid::Uuid::new_v4().to_string(), now_ms() as u128);
355 let url = socket_url(&self.host, &self.endpoint_id, &uuid::Uuid::new_v4().to_string(), now_ms() as u128);
355 let Ok(Ok((socket, _))) = timeout(CONNECT_TIMEOUT, connect_async(url.as_str())).await else {
356 let Ok(Ok((socket, _))) = timeout(CONNECT_TIMEOUT, connect_async(url.as_str())).await else {
356 self.forward(&status_payload("disconnected", "connect_failed"));
357 self.forward(&status_payload("disconnected", "connect_failed"));
crates/session/Cargo.toml +1 −0
@@ -9,6 +9,7 @@ publish.workspace = true
9 9 base64.workspace = true
10 10 futures-util.workspace = true
11 11 reqwest = { version = "0.13", default-features = false, features = ["rustls"] }
12 rustls = { version = "0.23", default-features = false, features = ["ring", "std"] }
12 13 serde.workspace = true
13 14 serde_json.workspace = true
14 15 thiserror.workspace = true
@@ -9,6 +9,7 @@ publish.workspace = true
9base64.workspace = true
9base64.workspace = true
10futures-util.workspace = true
10futures-util.workspace = true
11reqwest = { version = "0.13", default-features = false, features = ["rustls"] }
11reqwest = { version = "0.13", default-features = false, features = ["rustls"] }
12rustls = { version = "0.23", default-features = false, features = ["ring", "std"] }
12serde.workspace = true
13serde.workspace = true
13serde_json.workspace = true
14serde_json.workspace = true
14thiserror.workspace = true
15thiserror.workspace = true
crates/session/src/lib.rs +1 −0
@@ -12,6 +12,7 @@ mod transport;
12 12 pub use app::{App, Target, find_app_tab, has_login_tab, is_login_url};
13 13 pub use error::{Error, Result};
14 14 pub use events::{TabChannel, TabCommand, TabControl, TabEvent, TabEvents};
15 pub use native::ensure_crypto_provider;
15 16 pub use page_script::token_acquirer_script;
16 17 pub use request::{ApiResponse, AugloopExchange, AugloopStage, BodyToken, Method, Request, SignalrExchange};
17 18 pub use scope::{GRAPH, IC3, NestedApp, OUTLOOK, PRESENCE, SPACES, Scope};
@@ -12,6 +12,7 @@ mod transport;
12pub use app::{App, Target, find_app_tab, has_login_tab, is_login_url};
12pub use app::{App, Target, find_app_tab, has_login_tab, is_login_url};
13pub use error::{Error, Result};
13pub use error::{Error, Result};
14pub use events::{TabChannel, TabCommand, TabControl, TabEvent, TabEvents};
14pub use events::{TabChannel, TabCommand, TabControl, TabEvent, TabEvents};
15pub use native::ensure_crypto_provider;
15pub use page_script::token_acquirer_script;
16pub use page_script::token_acquirer_script;
16pub use request::{ApiResponse, AugloopExchange, AugloopStage, BodyToken, Method, Request, SignalrExchange};
17pub use request::{ApiResponse, AugloopExchange, AugloopStage, BodyToken, Method, Request, SignalrExchange};
17pub use scope::{GRAPH, IC3, NestedApp, OUTLOOK, PRESENCE, SPACES, Scope};
18pub use scope::{GRAPH, IC3, NestedApp, OUTLOOK, PRESENCE, SPACES, Scope};
crates/session/src/native.rs +8 −0
@@ -47,6 +47,7 @@ pub(crate) struct NativeHttp {
47 47
48 48 impl NativeHttp {
49 49 pub(crate) fn new(timeout: Duration, max_bytes: u64) -> Option<Self> {
50 ensure_crypto_provider();
50 51 let client = reqwest::Client::builder().timeout(timeout).build().ok()?;
51 52 Some(NativeHttp { client, tokens: Mutex::new(HashMap::new()), max_bytes })
52 53 }
@@ -149,6 +150,13 @@ impl NativeHttp {
149 150
150 151 const TEAMS_BEARER_PATHS: [&str; 2] = ["/api/", "/registrar/"];
151 152
153 /// Both rustls providers end up compiled in through dependencies, and then rustls refuses to pick one on its own.
154 pub fn ensure_crypto_provider() {
155 if rustls::crypto::CryptoProvider::get_default().is_none() {
156 let _ = rustls::crypto::ring::default_provider().install_default();
157 }
158 }
159
152 160 /// Page-only: websocket exchanges, tokens spliced into bodies, and app-origin calls that may rely on its cookies.
153 161 fn eligible(request: &Request) -> bool {
154 162 request.signalr.is_none()
@@ -47,6 +47,7 @@ pub(crate) struct NativeHttp {
47
47
48impl NativeHttp {
48impl NativeHttp {
49 pub(crate) fn new(timeout: Duration, max_bytes: u64) -> Option<Self> {
49 pub(crate) fn new(timeout: Duration, max_bytes: u64) -> Option<Self> {
50 ensure_crypto_provider();
50 let client = reqwest::Client::builder().timeout(timeout).build().ok()?;
51 let client = reqwest::Client::builder().timeout(timeout).build().ok()?;
51 Some(NativeHttp { client, tokens: Mutex::new(HashMap::new()), max_bytes })
52 Some(NativeHttp { client, tokens: Mutex::new(HashMap::new()), max_bytes })
52 }
53 }
@@ -149,6 +150,13 @@ impl NativeHttp {
149
150
150const TEAMS_BEARER_PATHS: [&str; 2] = ["/api/", "/registrar/"];
151const TEAMS_BEARER_PATHS: [&str; 2] = ["/api/", "/registrar/"];
151
152
153/// Both rustls providers end up compiled in through dependencies, and then rustls refuses to pick one on its own.
154pub fn ensure_crypto_provider() {
155 if rustls::crypto::CryptoProvider::get_default().is_none() {
156 let _ = rustls::crypto::ring::default_provider().install_default();
157 }
158}
159
152/// Page-only: websocket exchanges, tokens spliced into bodies, and app-origin calls that may rely on its cookies.
160/// Page-only: websocket exchanges, tokens spliced into bodies, and app-origin calls that may rely on its cookies.
153fn eligible(request: &Request) -> bool {
161fn eligible(request: &Request) -> bool {
154 request.signalr.is_none()
162 request.signalr.is_none()