File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -378,8 +378,8 @@ class CA {
378378 const notBefore = new Date ( ) ;
379379 notBefore . setDate ( notBefore . getDate ( ) - 1 ) ; // Valid from 24 hours ago
380380
381- const notAfter = new Date ( ) ;
382- notAfter . setFullYear ( notAfter . getFullYear ( ) + 1 ) ; // Valid for 1 year
381+ // As of March 2026, public certs are limited to 200 days
382+ const notAfter = new Date ( notBefore . getTime ( ) + 200 * 24 * 60 * 60 * 1000 ) ;
383383
384384 const extensions : x509 . Extension [ ] = [ ] ;
385385 extensions . push ( new x509 . BasicConstraintsExtension ( false , undefined , true ) ) ;
Original file line number Diff line number Diff line change @@ -176,12 +176,21 @@ nodeOnly(() => {
176176 const caCertificate = await caCertificatePromise ;
177177 const ca = await getCA ( { key : caCertificate . key , cert : caCertificate . cert , keyLength : 1024 } ) ;
178178
179- const { cert, key } = await ca . generateCertificate ( 'localhost' ) ;
179+ const { cert, key, expiresAt } = await ca . generateCertificate ( 'localhost' ) ;
180180
181181 expect ( cert . length ) . to . be . greaterThan ( 1000 ) ;
182182 expect ( cert . split ( '\n' ) [ 0 ] ) . to . equal ( '-----BEGIN CERTIFICATE-----' ) ;
183- expect ( key . length ) . to . be . greaterThan ( 1000 ) ;
183+ expect ( key . length ) . to . be . greaterThan ( 500 ) ;
184184 expect ( key . split ( '\n' ) [ 0 ] ) . to . equal ( '-----BEGIN PRIVATE KEY-----' ) ;
185+
186+ // Cert validity must be <= 200 days (notBefore is 1 day ago, notAfter is 199 days from now)
187+ const certData = new x509 . X509Certificate ( cert ) ;
188+ const validityDays = ( certData . notAfter . getTime ( ) - certData . notBefore . getTime ( ) ) / ( 1000 * 60 * 60 * 24 ) ;
189+ expect ( validityDays ) . to . be . at . most ( 200 ) ;
190+ expect ( validityDays ) . to . be . at . least ( 199 ) ;
191+
192+ // expiresAt should match the cert's notAfter (within 1s - cert times have second precision)
193+ expect ( Math . abs ( expiresAt . getTime ( ) - certData . notAfter . getTime ( ) ) ) . to . be . at . most ( 1000 ) ;
185194 } ) ;
186195
187196 it ( "should be able to generate a CA certificate that passes lintcert checks" , async function ( ) {
You can’t perform that action at this time.
0 commit comments