Skip to content

Commit 01e1f30

Browse files
committed
Default renewal time to halfway through certificates lifetime
Signed-off-by: James Munnelly <[email protected]>
1 parent 6ca41bd commit 01e1f30

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

manager/manager.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package manager
1818

1919
import (
2020
"context"
21+
"crypto/x509"
22+
"encoding/pem"
2123
"errors"
2224
"fmt"
2325
"math"
@@ -402,6 +404,18 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
402404
return fmt.Errorf("waiting for request: %w", err)
403405
}
404406

407+
// Default the renewal time to be halfway through the certificate's duration.
408+
// The implementation's writeKeypair function may override this value before
409+
// writing to the storage layer.
410+
block, _ := pem.Decode(req.Status.Certificate)
411+
crt, err := x509.ParseCertificate(block.Bytes)
412+
if err != nil {
413+
return fmt.Errorf("parsing issued certificate: %w", err)
414+
}
415+
duration := crt.NotAfter.Sub(crt.NotBefore)
416+
midpoint := crt.NotBefore.Add(duration / 2)
417+
meta.NextIssuanceTime = &midpoint
418+
405419
if err := m.writeKeypair(meta, key, req.Status.Certificate, req.Status.CA); err != nil {
406420
return fmt.Errorf("writing keypair: %w", err)
407421
}

0 commit comments

Comments
 (0)