Skip to content

Commit

Permalink
fix: ssl redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitthi committed Nov 3, 2024
1 parent 918b37d commit 61cfd4f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "easy-proxy"
version = "0.1.7"
version = "0.1.8"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/config/certs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/config/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
4 changes: 1 addition & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use openssl::{
};
use std::time::{Duration, SystemTime};

pub fn asn1_time_to_unix_time(
time: &Asn1TimeRef,
) -> Result<i128, ErrorStack> {
pub fn asn1_time_to_unix_time(time: &Asn1TimeRef) -> Result<i128, ErrorStack> {
let threshold = Asn1Time::days_from_now(0).unwrap();
let time = threshold.diff(time)?;
let days = time.days; // Difference in days
Expand Down

0 comments on commit 61cfd4f

Please sign in to comment.