diff --git a/Cargo.lock b/Cargo.lock index ab3aeb7..3678f02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ # It is not intended for manual editing. [[package]] name = "acme-client" -version = "0.2.0" +version = "0.3.0" dependencies = [ "acme-lib", "async-std", diff --git a/Cargo.toml b/Cargo.toml index 485dac7..ff70e27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "acme-client" -version = "0.2.0" +version = "0.3.0" authors = ["Hatter Jiang "] edition = "2018" description = "Acme auto challenge client, acme-client can issue certificates from Let's encrypt" diff --git a/src/config.rs b/src/config.rs index a98e8d7..47fbc28 100644 --- a/src/config.rs +++ b/src/config.rs @@ -110,15 +110,25 @@ impl CertConfigItem { } let path_buff = opt_result!(PathBuf::from_str(&self.path), "Path: {}, failed: {}", self.path); let cert_path_buff = path_buff.join(CERT_NAME); - if self.common_name.is_none() || self.dns_names.is_none() { + if self.common_name.is_none() && self.dns_names.is_none() { let pem = opt_result!(fs::read_to_string(cert_path_buff.clone()), "Read file: {:?}, failed: {}", cert_path_buff); let x509_certificate = opt_result!(x509::parse_x509(&format!("{}/{}", self.path, CERT_NAME), &pem), "Parse x509: {}/{}, faield: {}", self.path, CERT_NAME); self.common_name = Some(x509_certificate.common_name.clone()); self.dns_names = Some(x509_certificate.alt_names.clone()); + if let Some(pos) = x509_certificate.alt_names.iter().position(|n| n == &x509_certificate.common_name) { + if let Some(dns_names) = &mut self.dns_names { + dns_names.remove(pos); + } + } self.algo = None; self.public_key_algo = Some(x509_certificate.public_key_algo.clone()); Ok(Some(x509_certificate)) } else { + if self.common_name.is_none() { + if let Some(dns_names) = &mut self.dns_names { + self.common_name = Some(dns_names.remove(0)); + } + } if self.public_key_algo.is_none() { self.public_key_algo = match &self.algo { None => Some(X509PublicKeyAlgo::Rsa(2048)), @@ -141,6 +151,9 @@ impl CertConfigItem { let mut sorted_dns_names = dns_names.clone(); sorted_dns_names.sort(); let mut cert_sorted_dns_names = x509_certificate.alt_names.clone(); + if let Some(pos) = cert_sorted_dns_names.iter().position(|n| n == self.common_name.as_ref().unwrap()) { + cert_sorted_dns_names.remove(pos); + } cert_sorted_dns_names.sort(); if sorted_dns_names != cert_sorted_dns_names { warning!("Cert: {}, dns names mis-match: {:?} vs {:?}", self.path, sorted_dns_names, cert_sorted_dns_names);