@@ -5,7 +5,7 @@ use const_oid::db::rfc5280::{ID_KP_CLIENT_AUTH, ID_KP_SERVER_AUTH};
5
5
use rsa:: pkcs8:: EncodePublicKey ;
6
6
use snafu:: { ResultExt , Snafu } ;
7
7
use stackable_operator:: time:: Duration ;
8
- use tracing:: debug;
8
+ use tracing:: { debug, warn } ;
9
9
use x509_cert:: {
10
10
builder:: { Builder , Profile } ,
11
11
der:: { DecodePem , asn1:: Ia5String } ,
@@ -129,8 +129,7 @@ where
129
129
) -> Result < CertificatePair < KP > , CreateCertificateError < KP :: Error > > {
130
130
let serial_number =
131
131
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
+
134
133
let validity = Validity :: from_now ( * self . validity ) . context ( ParseValiditySnafu ) ?;
135
134
let subject: Name = self . subject . parse ( ) . context ( ParseSubjectSnafu {
136
135
subject : self . subject ,
@@ -140,6 +139,20 @@ where
140
139
None => KP :: new ( ) . context ( CreateKeyPairSnafu ) ?,
141
140
} ;
142
141
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
+
143
156
let spki_pem = key_pair
144
157
. verifying_key ( )
145
158
. to_public_key_pem ( PEM_LINE_ENDING )
0 commit comments