forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
49 lines (38 loc) · 1.12 KB
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tls
import (
"crypto/x509"
"crypto/x509/pkix"
"github.com/openshift/installer/pkg/asset"
"github.com/pkg/errors"
)
// RootCA contains the private key and the cert that's
// self-signed as the root CA.
type RootCA struct {
CertKey
}
var _ asset.WritableAsset = (*RootCA)(nil)
// Dependencies returns the dependency of the root-ca, which is empty.
func (c *RootCA) Dependencies() []asset.Asset {
return []asset.Asset{}
}
// Generate generates the root-ca key and cert pair.
func (c *RootCA) Generate(parents asset.Parents) error {
cfg := &CertCfg{
Subject: pkix.Name{CommonName: "root-ca", OrganizationalUnit: []string{"openshift"}},
KeyUsages: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
Validity: ValidityTenYears,
IsCA: true,
}
key, crt, err := GenerateRootCertKey(cfg)
if err != nil {
return errors.Wrap(err, "failed to generate RootCA")
}
c.KeyRaw = PrivateKeyToPem(key)
c.CertRaw = CertToPem(crt)
c.generateFiles("root-ca")
return nil
}
// Name returns the human-friendly name of the asset.
func (c *RootCA) Name() string {
return "Root CA"
}