@@ -413,16 +413,13 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
413
413
return fmt .Errorf ("waiting for request: %w" , err )
414
414
}
415
415
416
- // Default the renewal time to be 2/3rds through the certificate's duration .
416
+ // Calculate the default next issuance time .
417
417
// The implementation's writeKeypair function may override this value before
418
418
// writing to the storage layer.
419
- block , _ := pem .Decode (req .Status .Certificate )
420
- crt , err := x509 .ParseCertificate (block .Bytes )
419
+ renewalPoint , err := calculateNextIssuanceTime (req .Status .Certificate )
421
420
if err != nil {
422
- return fmt .Errorf ("parsing issued certificate : %w" , err )
421
+ return fmt .Errorf ("calculating next issuance time : %w" , err )
423
422
}
424
- duration := crt .NotAfter .Sub (crt .NotBefore )
425
- renewalPoint := crt .NotBefore .Add (duration * (2 / 3 ))
426
423
meta .NextIssuanceTime = & renewalPoint
427
424
428
425
if err := m .writeKeypair (meta , key , req .Status .Certificate , req .Status .CA ); err != nil {
@@ -722,3 +719,20 @@ func (m *Manager) Stop() {
722
719
delete (m .managedVolumes , k )
723
720
}
724
721
}
722
+
723
+ // calculateNextIssuanceTime will return the default time at which the certificate
724
+ // should be renewed by the driver- 2/3rds through its lifetime (NotAfter -
725
+ // NotBefore).
726
+ func calculateNextIssuanceTime (chain []byte ) (time.Time , error ) {
727
+ block , _ := pem .Decode (chain )
728
+ crt , err := x509 .ParseCertificate (block .Bytes )
729
+ if err != nil {
730
+ return time.Time {}, fmt .Errorf ("parsing issued certificate: %w" , err )
731
+ }
732
+
733
+ actualDuration := crt .NotAfter .Sub (crt .NotBefore )
734
+
735
+ renewBeforeNotAfter := actualDuration / 3
736
+
737
+ return crt .NotAfter .Add (- renewBeforeNotAfter ), nil
738
+ }
0 commit comments