Skip to content

Commit 2c26e5b

Browse files
authored
Add support for NotBefore and NotAfter in Order (#329)
When testing against Pebble I found it doesn't reject NotBefore and NotAfter in orders but it wasn't using them causing to have confusing results. This PR adds support for issuing a cert with NotBefore/NotAfter set to specific values set in the order.
1 parent a1a52e8 commit 2c26e5b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

ca/ca.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (ca *CAImpl) newChain(intermediateKey crypto.Signer, intermediateSubject pk
248248
return c
249249
}
250250

251-
func (ca *CAImpl) newCertificate(domains []string, ips []net.IP, key crypto.PublicKey, accountID string) (*core.Certificate, error) {
251+
func (ca *CAImpl) newCertificate(domains []string, ips []net.IP, key crypto.PublicKey, accountID, notBefore, notAfter string) (*core.Certificate, error) {
252252
var cn string
253253
if len(domains) > 0 {
254254
cn = domains[0]
@@ -269,6 +269,22 @@ func (ca *CAImpl) newCertificate(domains []string, ips []net.IP, key crypto.Publ
269269
return nil, fmt.Errorf("cannot create subject key ID: %s", err.Error())
270270
}
271271

272+
certNotBefore := time.Now()
273+
if notBefore != "" {
274+
certNotBefore, err = time.Parse(time.RFC3339, notBefore)
275+
if err != nil {
276+
return nil, fmt.Errorf("cannot parse Not Before date: %w", err)
277+
}
278+
}
279+
280+
certNotAfter := time.Now().AddDate(5, 0, 0)
281+
if notAfter != "" {
282+
certNotAfter, err = time.Parse(time.RFC3339, notAfter)
283+
if err != nil {
284+
return nil, fmt.Errorf("cannot parse Not After date: %w", err)
285+
}
286+
}
287+
272288
serial := makeSerial()
273289
template := &x509.Certificate{
274290
DNSNames: domains,
@@ -277,8 +293,8 @@ func (ca *CAImpl) newCertificate(domains []string, ips []net.IP, key crypto.Publ
277293
CommonName: cn,
278294
},
279295
SerialNumber: serial,
280-
NotBefore: time.Now(),
281-
NotAfter: time.Now().AddDate(5, 0, 0),
296+
NotBefore: certNotBefore,
297+
NotAfter: certNotAfter,
282298

283299
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
284300
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
@@ -375,7 +391,7 @@ func (ca *CAImpl) CompleteOrder(order *core.Order) {
375391

376392
// issue a certificate for the csr
377393
csr := order.ParsedCSR
378-
cert, err := ca.newCertificate(csr.DNSNames, csr.IPAddresses, csr.PublicKey, order.AccountID)
394+
cert, err := ca.newCertificate(csr.DNSNames, csr.IPAddresses, csr.PublicKey, order.AccountID, order.NotBefore, order.NotAfter)
379395
if err != nil {
380396
ca.log.Printf("Error: unable to issue order: %s", err.Error())
381397
return

0 commit comments

Comments
 (0)