Skip to content

Commit

Permalink
refactor: validity checker ignore acme certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Dec 2, 2024
1 parent 3809608 commit 5cf182f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/acme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct CertificateInfo {
pub not_after: i64,
pub not_before: i64,
pub issuer: String,
pub acme: Option<String>,
}

impl CertificateInfo {
Expand Down Expand Up @@ -84,6 +85,7 @@ pub fn get_certificate_info(data: &[u8]) -> Result<CertificateInfo> {
not_before: validity.not_before.timestamp(),
not_after: validity.not_after.timestamp(),
issuer: x509.issuer().to_string(),
..Default::default()
})
}

Expand Down
6 changes: 6 additions & 0 deletions src/acme/validity_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ fn validity_check(
) -> Result<(), String> {
let now = util::now().as_secs() as i64;
for (name, cert) in validity_list.iter() {
// acme certificate will auto update
if cert.acme.is_some() {
continue;
}
// will expire check
if now > cert.not_after - time_offset {
let message = format!(
Expand Down Expand Up @@ -120,6 +124,7 @@ mod tests {
.unwrap()
.timestamp(),
issuer: "pingap".to_string(),
..Default::default()
},
)],
7 * 24 * 3600,
Expand All @@ -141,6 +146,7 @@ mod tests {
.unwrap()
.timestamp(),
issuer: "pingap".to_string(),
..Default::default()
},
)],
7 * 24 * 3600,
Expand Down
3 changes: 2 additions & 1 deletion src/proxy/dynamic_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ fn parse_certificate(
"",
)
};
let info = get_certificate_info(&cert).map_err(|e| Error::Invalid {
let mut info = get_certificate_info(&cert).map_err(|e| Error::Invalid {
category: "get_certificate_info".to_string(),
message: e.to_string(),
})?;
info.acme = certificate_config.acme.clone();

let hash_key = certificate_config.hash_key();

Expand Down

0 comments on commit 5cf182f

Please sign in to comment.