MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / generateRootCertificate

Function generateRootCertificate

internal/pki/common.go:67–95  ·  view source on GitHub ↗
(
	privateKey *ecdsa.PrivateKey, serialNumber *big.Int,
)

Source from the content-addressed store, hash-verified

65}
66
67func generateRootCertificate(
68 privateKey *ecdsa.PrivateKey, serialNumber *big.Int,
69) (*x509.Certificate, error) {
70 const rootCommonName = "postgres-operator-ca"
71 const rootExpiration = time.Hour * 24 * 365 * 10
72 const rootStartValid = time.Hour * -1
73
74 now := currentTime()
75 template := &x509.Certificate{
76 BasicConstraintsValid: true,
77 IsCA: true,
78 KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign,
79 MaxPathLenZero: true, // there are no intermediate certificates
80 NotBefore: now.Add(rootStartValid),
81 NotAfter: now.Add(rootExpiration),
82 SerialNumber: serialNumber,
83 SignatureAlgorithm: certificateSignatureAlgorithm,
84 Subject: pkix.Name{
85 CommonName: rootCommonName,
86 },
87 }
88
89 // A root certificate is self-signed, so pass in the template twice.
90 bytes, err := x509.CreateCertificate(rand.Reader, template, template,
91 privateKey.Public(), privateKey)
92
93 parsed, _ := x509.ParseCertificate(bytes)
94 return parsed, err
95}

Callers 1

Calls 1

AddMethod · 0.45

Tested by

no test coverage detected