Skip to content

Commit 70dc741

Browse files
committed
warn when cert lifes longer than CA
1 parent d3e7643 commit 70dc741

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

crates/stackable-certs/src/cert_builder.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use const_oid::db::rfc5280::{ID_KP_CLIENT_AUTH, ID_KP_SERVER_AUTH};
55
use rsa::pkcs8::EncodePublicKey;
66
use snafu::{ResultExt, Snafu};
77
use stackable_operator::time::Duration;
8-
use tracing::debug;
8+
use tracing::{debug, warn};
99
use x509_cert::{
1010
builder::{Builder, Profile},
1111
der::{DecodePem, asn1::Ia5String},
@@ -129,8 +129,7 @@ where
129129
) -> Result<CertificatePair<KP>, CreateCertificateError<KP::Error>> {
130130
let serial_number =
131131
SerialNumber::from(self.serial_number.unwrap_or_else(|| rand::random::<u64>()));
132-
// NOTE (@Techassi): Should we validate that the validity is shorter
133-
// than the validity of the issuing CA?
132+
134133
let validity = Validity::from_now(*self.validity).context(ParseValiditySnafu)?;
135134
let subject: Name = self.subject.parse().context(ParseSubjectSnafu {
136135
subject: self.subject,
@@ -140,6 +139,20 @@ where
140139
None => KP::new().context(CreateKeyPairSnafu)?,
141140
};
142141

142+
let ca_validity = self.signed_by.ca_cert().tbs_certificate.validity;
143+
let ca_not_after = ca_validity.not_after.to_system_time();
144+
let cert_not_after = validity.not_after.to_system_time();
145+
if ca_not_after < cert_not_after {
146+
warn!(
147+
ca.validity = ?ca_validity,
148+
cert.validity = ?validity,
149+
ca.not_after = ?ca_not_after,
150+
cert.not_after = ?cert_not_after,
151+
subject = ?subject,
152+
"The lifetime of certificate authority is shorted than the lifetime of the generated certificate",
153+
);
154+
}
155+
143156
let spki_pem = key_pair
144157
.verifying_key()
145158
.to_public_key_pem(PEM_LINE_ENDING)

0 commit comments

Comments
 (0)