forked from cert-manager/cert-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csr.go
38 lines (34 loc) · 1018 Bytes
/
csr.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
package pki
import (
"crypto/x509"
"crypto/x509/pkix"
"github.com/jetstack-experimental/cert-manager/pkg/apis/certmanager/v1alpha1"
)
// The provided Certificate *must* specify either a DNS name or a
// CommonName else this function will panic.
func CommonNameForCertificate(crt *v1alpha1.Certificate) string {
if crt.Spec.CommonName == "" {
return crt.Spec.DNSNames[0]
}
return crt.Spec.CommonName
}
// The provided Certificate *must* specify either a DNS name or a
// CommonName else this function will panic.
func DNSNamesForCertificate(crt *v1alpha1.Certificate) []string {
if len(crt.Spec.DNSNames) == 0 {
return []string{crt.Spec.CommonName}
}
if crt.Spec.CommonName != "" {
return append([]string{crt.Spec.CommonName}, crt.Spec.DNSNames...)
}
return crt.Spec.DNSNames
}
func GenerateCSR(commonName string, altNames ...string) *x509.CertificateRequest {
template := x509.CertificateRequest{
Subject: pkix.Name{
CommonName: commonName,
},
DNSNames: altNames,
}
return &template
}