Skip to content

Commit 92d03c8

Browse files
committed
Fixes a bug in default renewal time calculation
Signed-off-by: irbekrm <[email protected]>
1 parent 8ebb8cd commit 92d03c8

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

manager/manager.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,16 +413,13 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
413413
return fmt.Errorf("waiting for request: %w", err)
414414
}
415415

416-
// Default the renewal time to be 2/3rds through the certificate's duration.
416+
// Calculate the default next issuance time.
417417
// The implementation's writeKeypair function may override this value before
418418
// 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)
421420
if err != nil {
422-
return fmt.Errorf("parsing issued certificate: %w", err)
421+
return fmt.Errorf("calculating next issuance time: %w", err)
423422
}
424-
duration := crt.NotAfter.Sub(crt.NotBefore)
425-
renewalPoint := crt.NotBefore.Add(duration * (2 / 3))
426423
meta.NextIssuanceTime = &renewalPoint
427424

428425
if err := m.writeKeypair(meta, key, req.Status.Certificate, req.Status.CA); err != nil {
@@ -722,3 +719,20 @@ func (m *Manager) Stop() {
722719
delete(m.managedVolumes, k)
723720
}
724721
}
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

Comments
 (0)