Skip to content

Commit

Permalink
bug
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltorio committed Dec 16, 2024
1 parent 2b30614 commit d62c546
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
29 changes: 24 additions & 5 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use handlers::DataHandler;
use handlers::DownloadHandler;
use handlers::UploadHandler;
use indicatif::{ProgressBar, ProgressStyle};
use crate::ca_bundle::get_cert_bundle;
use crate::ca_bundle::CERT_BUNDLE;

use log;

Expand All @@ -36,8 +36,8 @@ fn new_easy2_data(
let _ = easy2.ssl_verify_host(false);
let _ = easy2.ssl_verify_peer(false);
} else {
if env::var("CURL_USE_SYSTEM_CA_BUNDLE") == Ok("1".to_string()) {
if easy2.ssl_cainfo_blob(get_cert_bundle().as_bytes()) != Ok(()) {
if env::var("CURL_USE_INTERNAL_CA_BUNDLE") == Ok("1".to_string()) {
if easy2.ssl_cainfo_blob(CERT_BUNDLE) != Ok(()) {
log::error!("Failed to load cacert.pem");
}
}
Expand Down Expand Up @@ -90,6 +90,12 @@ pub fn new_easy2_download(
if env::var("CURL_VERBOSE") == Ok("1".to_string()) {
let _ = easy2.verbose(true);
}

if env::var("CURL_USE_INTERNAL_CA_BUNDLE") == Ok("1".to_string()) {
if easy2.ssl_cainfo_blob(CERT_BUNDLE) != Ok(()) {
log::error!("Failed to load cacert.pem");
}
}

let mut merged_headers: Vec<String> = DEFAULT_HEADERS.iter().map(|x| x.to_string()).collect();

Expand Down Expand Up @@ -153,8 +159,8 @@ pub fn new_easy2_upload(
let _ = easy2.ssl_verify_host(false);
let _ = easy2.ssl_verify_peer(false);
} else {
if env::var("CURL_USE_SYSTEM_CA_BUNDLE") == Ok("1".to_string()) {
if easy2.ssl_cainfo_blob(get_cert_bundle().as_bytes()) != Ok(()) {
if env::var("CURL_USE_INTERNAL_CA_BUNDLE") == Ok("1".to_string()) {
if easy2.ssl_cainfo_blob(&CERT_BUNDLE) != Ok(()) {
log::error!("Failed to load cacert.pem");
}
}
Expand All @@ -177,6 +183,12 @@ pub fn get(url: &str, additional_headers: Option<Vec<String>>) -> Result<String,
let _ = easy2.verbose(true);
}

if env::var("CURL_USE_INTERNAL_CA_BUNDLE") == Ok("1".to_string()) {
if easy2.ssl_cainfo_blob(CERT_BUNDLE) != Ok(()) {
log::error!("Failed to load cacert.pem");
}
}

log::debug!(
"Sending get request to: {} \n with headers {}",
url,
Expand Down Expand Up @@ -219,6 +231,13 @@ pub fn post(
if env::var("CURL_VERBOSE") == Ok("1".to_string()) {
let _ = easy2.verbose(true);
}

if env::var("CURL_USE_INTERNAL_CA_BUNDLE") == Ok("1".to_string()) {
if easy2.ssl_cainfo_blob(CERT_BUNDLE) != Ok(()) {
log::error!("Failed to load cacert.pem");
}
}

easy2.post_fields_copy(&body)?;

loop {
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ fn main() -> Result<(), SwishError> {
let system_ca_bundle = cli.system_ca_bundle;
// Set the system CA bundle flag as an environment variable
if system_ca_bundle {
env::set_var("CURL_USE_SYSTEM_CA_BUNDLE", "1");
env::set_var("CURL_USE_INTERNAL_CA_BUNDLE", "0");
} else {
env::set_var("CURL_USE_INTERNAL_CA_BUNDLE", "1");
}

//check if the arg is a link
Expand Down

0 comments on commit d62c546

Please sign in to comment.