Skip to content

Commit 612b982

Browse files
committed
refactor: refactor init ring tls config
1 parent 0a4b32e commit 612b982

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/main.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io::{self, IsTerminal, stderr, stdin};
55
use std::path::{Path, PathBuf};
66

77
use std::process::{Command, exit};
8-
use std::sync::{Arc, LazyLock, OnceLock};
8+
use std::sync::{LazyLock, OnceLock};
99
use std::thread;
1010
use std::time::{Duration, SystemTime, UNIX_EPOCH};
1111

@@ -37,8 +37,6 @@ use oma_utils::dbus::{create_dbus_connection, get_another_oma_status};
3737
use oma_utils::{OsRelease, is_termux};
3838
use reqwest::Client;
3939
use rustix::stdio::stdout;
40-
use rustls::ClientConfig;
41-
use rustls_platform_verifier::BuilderVerifierExt;
4240
use subcommand::utils::{LockError, is_terminal};
4341
use tokio::runtime::Runtime;
4442
use tracing::{debug, error, info, warn};
@@ -71,9 +69,10 @@ static RT: LazyLock<Runtime> = LazyLock::new(|| {
7169
});
7270

7371
static HTTP_CLIENT: LazyLock<Client> = LazyLock::new(|| {
72+
init_tls_config();
73+
7474
Client::builder()
7575
.user_agent(APP_USER_AGENT)
76-
.tls_backend_preconfigured(tls_config())
7776
.build()
7877
.unwrap()
7978
});
@@ -480,15 +479,12 @@ fn try_main(
480479
code
481480
}
482481

483-
fn tls_config() -> ClientConfig {
484-
let arc_crypto_provider = Arc::new(rustls::crypto::ring::default_provider());
485-
486-
ClientConfig::builder_with_provider(arc_crypto_provider)
487-
.with_safe_default_protocol_versions()
488-
.unwrap()
489-
.with_platform_verifier()
490-
.unwrap()
491-
.with_no_client_auth()
482+
/// Initialize ring TLS config for HTTP client
483+
#[inline]
484+
fn init_tls_config() {
485+
rustls::crypto::ring::default_provider()
486+
.install_default()
487+
.expect("Failed to install rustls crypto provider");
492488
}
493489

494490
fn init_color_formatter(oma: &OhManagerAilurus, config: &Config) {

src/subcommand/mirror.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ use crate::args::HELP_TEMPLATE;
5353
use crate::config::Config;
5454
use crate::error::OutputError;
5555
use crate::fl;
56+
use crate::init_tls_config;
5657
use crate::lang::SYSTEM_LANG;
5758
use crate::pb::OmaProgressBar;
5859
use crate::pb::Print;
5960
use crate::subcommand::utils::multiselect;
6061
use crate::success;
6162
use crate::table::PagerPrinter;
62-
use crate::tls_config;
6363
use crate::utils::root;
6464

6565
use super::utils::Refresh;
@@ -818,9 +818,10 @@ fn speedtest(
818818
}
819819

820820
fn client(timeout: f64) -> Result<blocking::Client, OutputError> {
821+
init_tls_config();
822+
821823
let client = blocking::ClientBuilder::new()
822824
.user_agent(APP_USER_AGENT)
823-
.tls_backend_preconfigured(tls_config())
824825
.timeout(Duration::from_secs_f64(timeout))
825826
.build()?;
826827

0 commit comments

Comments
 (0)