Skip to content

Commit 4475e93

Browse files
authored
feat(bundler/cli): Add feature flag to use system certificates (#13824)
1 parent 5110a76 commit 4475e93

File tree

7 files changed

+94
-19
lines changed

7 files changed

+94
-19
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-bundler": "minor:enhance"
3+
"tauri-cli": "minor:enhance"
4+
"@tauri-apps/cli": "minor:enhance"
5+
---
6+
7+
The bundler and cli will now read TLS Certificates installed on the system when downloading tools and checking versions.

Cargo.lock

Lines changed: 48 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri-bundler/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ name = "tauri_bundler"
7474
path = "src/lib.rs"
7575

7676
[features]
77-
default = ["rustls"]
77+
default = ["rustls", "platform-certs"]
7878
native-tls = ["ureq/native-tls"]
7979
native-tls-vendored = ["native-tls", "native-tls/vendored"]
8080
rustls = ["ureq/rustls"]
81+
platform-certs = ["ureq/platform-verifier"]

crates/tauri-bundler/src/bundle/windows/util.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
};
99
use ureq::ResponseExt;
1010

11-
use crate::utils::http_utils::download;
11+
use crate::utils::http_utils::{base_ureq_agent, download};
1212

1313
pub const WEBVIEW2_BOOTSTRAPPER_URL: &str = "https://go.microsoft.com/fwlink/p/?LinkId=2124703";
1414
pub const WEBVIEW2_OFFLINE_INSTALLER_X86_URL: &str =
@@ -23,10 +23,7 @@ pub const WIX_OUTPUT_FOLDER_NAME: &str = "msi";
2323
pub const WIX_UPDATER_OUTPUT_FOLDER_NAME: &str = "msi-updater";
2424

2525
pub fn webview2_guid_path(url: &str) -> crate::Result<(String, String)> {
26-
let agent: ureq::Agent = ureq::Agent::config_builder()
27-
.proxy(ureq::Proxy::try_from_env())
28-
.build()
29-
.into();
26+
let agent = base_ureq_agent();
3027
let response = agent.head(url).call().map_err(Box::new)?;
3128
let final_url = response.get_uri().to_string();
3229
let remaining_url = final_url.strip_prefix(WEBVIEW2_URL_PREFIX).ok_or_else(|| {

crates/tauri-bundler/src/utils/http_utils.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,26 @@ fn generate_github_alternative_url(url: &str) -> Option<(ureq::Agent, String)> {
5151
}
5252

5353
fn create_agent_and_url(url: &str) -> (ureq::Agent, String) {
54-
generate_github_alternative_url(url).unwrap_or((
55-
ureq::Agent::config_builder()
56-
.proxy(ureq::Proxy::try_from_env())
57-
.build()
58-
.into(),
59-
url.to_owned(),
60-
))
54+
generate_github_alternative_url(url).unwrap_or((base_ureq_agent(), url.to_owned()))
55+
}
56+
57+
pub(crate) fn base_ureq_agent() -> ureq::Agent {
58+
#[cfg(feature = "platform-certs")]
59+
let agent: ureq::Agent = ureq::Agent::config_builder()
60+
.tls_config(
61+
ureq::tls::TlsConfig::builder()
62+
.root_certs(ureq::tls::RootCerts::PlatformVerifier)
63+
.build(),
64+
)
65+
.proxy(ureq::Proxy::try_from_env())
66+
.build()
67+
.into();
68+
#[cfg(not(feature = "platform-certs"))]
69+
let agent: ureq::Agent = ureq::Agent::config_builder()
70+
.proxy(ureq::Proxy::try_from_env())
71+
.build()
72+
.into();
73+
agent
6174
}
6275

6376
#[allow(dead_code)]

crates/tauri-cli/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ object = { version = "0.36", default-features = false, features = [
138138
ar = "0.9"
139139

140140
[features]
141-
default = ["rustls"]
141+
default = ["rustls", "platform-certs"]
142142
native-tls = [
143143
"tauri-bundler/native-tls",
144144
"cargo-mobile2/native-tls",
145145
"ureq/native-tls",
146146
]
147147
native-tls-vendored = ["native-tls", "tauri-bundler/native-tls-vendored"]
148148
rustls = ["tauri-bundler/rustls", "cargo-mobile2/rustls", "ureq/rustls"]
149+
platform-certs = ["tauri-bundler/platform-certs", "ureq/platform-verifier"]

crates/tauri-cli/src/helpers/cargo_manifest.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ struct CrateIoGetResponse {
117117
pub fn crate_latest_version(name: &str) -> Option<String> {
118118
// Reference: https://github.com/rust-lang/crates.io/blob/98c83c8231cbcd15d6b8f06d80a00ad462f71585/src/controllers/krate/metadata.rs#L88
119119
let url = format!("https://crates.io/api/v1/crates/{name}?include");
120+
#[cfg(feature = "platform-certs")]
121+
let mut response = {
122+
let agent = ureq::Agent::config_builder()
123+
.tls_config(
124+
ureq::tls::TlsConfig::builder()
125+
.root_certs(ureq::tls::RootCerts::PlatformVerifier)
126+
.build(),
127+
)
128+
.build()
129+
.new_agent();
130+
agent.get(&url).call().ok()?
131+
};
132+
#[cfg(not(feature = "platform-certs"))]
120133
let mut response = ureq::get(&url).call().ok()?;
121134
let metadata: CrateIoGetResponse =
122135
serde_json::from_reader(response.body_mut().as_reader()).unwrap();

0 commit comments

Comments
 (0)