Skip to content

Commit

Permalink
client-go: allow to set NotBefore in NewSelfSignedCACert()
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Champetier <[email protected]>

Kubernetes-commit: 0fc5c972129308617d39c543a8d34d1247ade265
  • Loading branch information
champtar authored and k8s-publishing-bot committed Jun 28, 2023
1 parent 860d25f commit b1b513f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion util/cert/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Config struct {
Organization []string
AltNames AltNames
Usages []x509.ExtKeyUsage
NotBefore time.Time
}

// AltNames contains the domain names and IP addresses that will be added
Expand All @@ -64,14 +65,18 @@ func NewSelfSignedCACert(cfg Config, key crypto.Signer) (*x509.Certificate, erro
return nil, err
}
serial = new(big.Int).Add(serial, big.NewInt(1))
notBefore := now.UTC()
if !cfg.NotBefore.IsZero() {
notBefore = cfg.NotBefore.UTC()
}
tmpl := x509.Certificate{
SerialNumber: serial,
Subject: pkix.Name{
CommonName: cfg.CommonName,
Organization: cfg.Organization,
},
DNSNames: []string{cfg.CommonName},
NotBefore: now.UTC(),
NotBefore: notBefore,
NotAfter: now.Add(duration365d * 10).UTC(),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
BasicConstraintsValid: true,
Expand Down

0 comments on commit b1b513f

Please sign in to comment.