-
Notifications
You must be signed in to change notification settings - Fork 456
/
csr.go
39 lines (34 loc) · 907 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
39
package util
import (
"crypto/rand"
"crypto/x509"
"crypto/x509/pkix"
"net/url"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/zeebo/errs"
)
func MakeCSR(privateKey any, spiffeID spiffeid.ID) ([]byte, error) {
return makeCSR(privateKey, &x509.CertificateRequest{
Subject: pkix.Name{
Country: []string{"US"},
Organization: []string{"SPIRE"},
},
URIs: []*url.URL{spiffeID.URL()},
})
}
func MakeCSRWithoutURISAN(privateKey any) ([]byte, error) {
return makeCSR(privateKey, &x509.CertificateRequest{
Subject: pkix.Name{
Country: []string{"US"},
Organization: []string{"SPIRE"},
},
SignatureAlgorithm: x509.ECDSAWithSHA256,
})
}
func makeCSR(privateKey any, template *x509.CertificateRequest) ([]byte, error) {
csr, err := x509.CreateCertificateRequest(rand.Reader, template, privateKey)
if err != nil {
return nil, errs.Wrap(err)
}
return csr, nil
}