From 61cfd4f45f762c53f50eb5d302f912cd3b714aab Mon Sep 17 00:00:00 2001 From: detoro Date: Sun, 3 Nov 2024 22:22:27 +0700 Subject: [PATCH] fix: ssl redirect --- Cargo.toml | 2 +- src/config/certs.rs | 2 +- src/config/store.rs | 7 +++---- src/proxy/mod.rs | 2 +- src/utils.rs | 4 +--- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 83249b8..aadf5ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "easy-proxy" -version = "0.1.7" +version = "0.1.8" edition = "2021" [dependencies] diff --git a/src/config/certs.rs b/src/config/certs.rs index b3cc869..28f4cb5 100644 --- a/src/config/certs.rs +++ b/src/config/certs.rs @@ -153,7 +153,7 @@ pub fn load_cert( let expiry = expiry - 432000; let now = chrono::Utc::now().timestamp() as i128; // 5 days before expiration - if expiry < now { + if expiry < now { tracing::info!("Renewing cert for {}", host); let add = acme_requests.get_mut(&tls.name); if let Some(add) = add { diff --git a/src/config/store.rs b/src/config/store.rs index 402515f..ab5f34c 100644 --- a/src/config/store.rs +++ b/src/config/store.rs @@ -586,10 +586,9 @@ pub async fn acme_request(tls_name: &str, acme: &Acme, domains: &[String]) -> Re .map_err(|_| Errors::AcmeClientError("Unable to parse cert".to_string()))?; let expiry = utils::asn1_time_to_unix_time(cert.not_after()) .map_err(|e| Errors::AcmeClientError(format!("Unable to parse cert expiry: {}", e)))?; - acme_store.acme_expires.insert( - order_id.to_string(), - (tls_name.to_string(), expiry), - ); + acme_store + .acme_expires + .insert(order_id.to_string(), (tls_name.to_string(), expiry)); let chain = cert_pems[1..] .iter() .map(|c| { diff --git a/src/proxy/mod.rs b/src/proxy/mod.rs index 289e5b8..8fe108f 100644 --- a/src/proxy/mod.rs +++ b/src/proxy/mod.rs @@ -370,7 +370,7 @@ impl ProxyHttp for EasyProxy { None => false, }; // println!("TLS: {}", is_tls); - if tls.redirect.unwrap_or(false) && is_tls { + if tls.redirect.unwrap_or(false) && !is_tls { // println!("Redirecting to https"); if tls_port != "443" { res.redirect_https(host, path, Some(tls_port.to_string())); diff --git a/src/utils.rs b/src/utils.rs index 149e379..74d7b15 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,9 +4,7 @@ use openssl::{ }; use std::time::{Duration, SystemTime}; -pub fn asn1_time_to_unix_time( - time: &Asn1TimeRef, -) -> Result { +pub fn asn1_time_to_unix_time(time: &Asn1TimeRef) -> Result { let threshold = Asn1Time::days_from_now(0).unwrap(); let time = threshold.diff(time)?; let days = time.days; // Difference in days