Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
default cert expiration to two years, not one
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Oct 18, 2019
1 parent 76974ab commit c5d433d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/util/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"time"

"github.com/cloudflare/cfssl/config"
"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/helpers"
"github.com/cloudflare/cfssl/initca"
Expand Down Expand Up @@ -77,7 +78,14 @@ func MakeCert(host []string, certKind, CACert, CAKey string) (CertType, error) {
return CertType{}, errors.Wrap(err, "parse csr")
}

localSigner, err := local.NewSigner(parsedCaKey, parsedCaCert, signer.DefaultSigAlgo(parsedCaKey), nil)
twoYearConfig := config.DefaultConfig()
twoYearConfig.Expiry = 17520 * time.Hour // two years
twoYearConfig.ExpiryString = "17520h"
signConfig := config.Signing{
Default: twoYearConfig,
}

localSigner, err := local.NewSigner(parsedCaKey, parsedCaCert, signer.DefaultSigAlgo(parsedCaKey), &signConfig)
if err != nil {
return CertType{}, errors.Wrap(err, "create signer")
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/certs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/x509"
"encoding/pem"
"testing"
"time"

"github.com/cloudflare/cfssl/csr"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -206,6 +207,11 @@ func TestMakeCert(t *testing.T) {
err = parsedCert.VerifyHostname(host)
req.NoError(err, "hostname %s must be present on cert", host)
}

// validate that the cert is valid for two more years
req.True(parsedCert.NotAfter.Add(-time.Hour * (17520 - 1)).After(time.Now()))
// and that it is valid now
req.True(parsedCert.NotBefore.Before(time.Now()))
})
}
}

0 comments on commit c5d433d

Please sign in to comment.