Compare commits

...
3 Commits
Author SHA1 Message Date
rustdeskandClaude Opus 5.5 333bfc6427 Initialize libsodium where Android starts the server
Started at boot, MainService calls startServer with no Flutter engine,
so initialize never ran: the server worked with libsodium uninitialized
until the UI opened, and that first sodium_init() could land while
sessions were running. startServer now makes the call first, before it
verifies the custom client's signature or spawns the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
2026-11-17 10:48:58 +08:00
rustdeskandClaude Opus 5.5 289f839646 Log a failed libsodium initialization and start anyway
As hbbs does: a client that does not start is worse than one that
runs with libsodium as it was before this change, and sodium_init()
fails only when it cannot lock its own mutex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
2026-11-17 10:47:06 +08:00
rustdeskandClaude Fable 5.2 3dd95ab73b Initialize libsodium before anything uses it
The client called sodium_init() only when the update signature check
or the trusted device token first ran. That call also chooses
libsodium's implementations: where a build has both, it moves Poly1305
from the default one to the SSE2 one, whose state is laid out
differently, so a secretbox or AEAD operation another thread was in
the middle of finished under the other implementation. In one thread,
a computation straddling the call gives a wrong tag. The call now runs
once at process start: first in global_init, which core_main begins
with, and at the top of the FFI initialize, which on mobile verifies a
signature before it reaches global_init.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
2026-11-17 10:42:46 +08:00
2 changed files with 13 additions and 0 deletions

No files matched your search

+9
View File
@@ -120,7 +120,16 @@ impl Drop for SimpleCallOnReturn {
}
}
/// `sodium_init()` chooses libsodium's implementations, so it runs before anything else uses the
/// library: a later call swaps Poly1305 under a computation another thread is in the middle of.
pub fn init_sodium() {
if hbb_common::sodiumoxide::init().is_err() {
log::error!("Failed to initialize libsodium");
}
}
pub fn global_init() -> bool {
init_sodium();
#[cfg(all(target_os = "linux", feature = "drm"))]
crate::platform::linux::dispatch_wayland_display_probe();
#[cfg(target_os = "linux")]
+4
View File
@@ -41,6 +41,8 @@ lazy_static::lazy_static! {
}
fn initialize(app_dir: &str, custom_client_config: &str) {
// On mobile `global_init` below comes after the custom client's signature is verified.
crate::common::init_sodium();
flutter::async_tasks::start_flutter_async_runner();
// `APP_DIR` is set in `main_get_data_dir_ios()` on iOS.
#[cfg(not(target_os = "ios"))]
@@ -3087,6 +3089,8 @@ pub mod server_side {
custom_client_config: JString,
) {
log::debug!("startServer from jvm");
// Started at boot, the service runs without the Flutter side and its `initialize`.
crate::common::init_sodium();
let mut env = env;
if let Ok(app_dir) = env.get_string(&app_dir) {
*config::APP_DIR.write().unwrap() = app_dir.into();