From 0d1fddd9d4859a2d4ce2175215cec486dd38a50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sat, 7 May 2022 16:04:10 +0200 Subject: [PATCH] Stop using `libc::time_t` This type was used for the calculation of the certificate's expiration delay, which causes troubles on some 32 bits systems. Rel #59 --- CHANGELOG.md | 1 + acme_common/Cargo.toml | 1 - acme_common/src/crypto/openssl_certificate.rs | 5 ++--- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 347400c..97e814a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - An invalid reference in the command line arguments has been fixed. - Some missing file path in log messages has been added. +- The calculation of the certificate's expiration delay does no longer break compilation on some systems. ## [0.19.0] - 2022-04-17 diff --git a/acme_common/Cargo.toml b/acme_common/Cargo.toml index f60dad0..e9a45d1 100644 --- a/acme_common/Cargo.toml +++ b/acme_common/Cargo.toml @@ -24,7 +24,6 @@ base64 = "0.13" daemonize = "0.4" env_logger = "0.9" glob = "0.3" -libc = "0.2" log = "0.4" native-tls = "0.2" openssl = { version = "0.10", optional = true } diff --git a/acme_common/src/crypto/openssl_certificate.rs b/acme_common/src/crypto/openssl_certificate.rs index bf7c506..287dc04 100644 --- a/acme_common/src/crypto/openssl_certificate.rs +++ b/acme_common/src/crypto/openssl_certificate.rs @@ -10,7 +10,7 @@ use openssl::x509::extension::{BasicConstraints, SubjectAlternativeName}; use openssl::x509::{X509Builder, X509Extension, X509NameBuilder, X509Req, X509ReqBuilder, X509}; use std::collections::{HashMap, HashSet}; use std::net::IpAddr; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use std::time::Duration; fn get_digest(digest: HashFunction, key_pair: &KeyPair) -> MessageDigest { #[cfg(not(any(ed25519, ed448)))] @@ -109,8 +109,7 @@ impl X509Certificate { } pub fn expires_in(&self) -> Result { - let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() as libc::time_t; - let now = Asn1Time::from_unix(timestamp)?; + let now = Asn1Time::days_from_now(0)?; let not_after = self.inner_cert.not_after(); let diff = now.diff(not_after)?; let nb_secs = diff.days * 24 * 60 * 60 + diff.secs;