( privateKey *ecdsa.PrivateKey, serialNumber *big.Int, )
| 65 | } |
| 66 | |
| 67 | func 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 | } |
no test coverage detected