Skip to content

Commit 4330f4e

Browse files
committed
Add support for custom validity certs
This commit allows autocert to request certificates with a specific notAfter value from the ACME CA. The CA may choose to honor this request or not. The acme package already supports this functionality.
1 parent 2c47667 commit 4330f4e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

acme/autocert/autocert.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ type Manager struct {
137137
// If zero, they're renewed 30 days before expiration.
138138
RenewBefore time.Duration
139139

140+
// RequestedCertificateValidity optionally specifies the validity of the requested
141+
// certificates from the CA. This may not be honored by all CAs. Ensure that this
142+
// and RenewBefore make sense in both cases (honored and not honored).
143+
//
144+
// The CA default value is used if this is not set.
145+
RequestedCertificateValidity time.Duration
146+
140147
// Client is used to perform low-level operations, such as account registration
141148
// and requesting new certificates.
142149
//
@@ -697,7 +704,14 @@ func (m *Manager) verifyRFC(ctx context.Context, client *acme.Client, domain str
697704
nextTyp := 0 // challengeTypes index
698705
AuthorizeOrderLoop:
699706
for {
700-
o, err := client.AuthorizeOrder(ctx, acme.DomainIDs(domain))
707+
// Send the notAfter option to the CA
708+
var orderOpts []acme.OrderOption
709+
if m.RequestedCertificateValidity != 0 {
710+
orderOpts = append(orderOpts, acme.WithOrderNotAfter(
711+
time.Now().UTC().Add(m.RequestedCertificateValidity)))
712+
}
713+
714+
o, err := client.AuthorizeOrder(ctx, acme.DomainIDs(domain), orderOpts...)
701715
if err != nil {
702716
return nil, err
703717
}

0 commit comments

Comments
 (0)