-
Notifications
You must be signed in to change notification settings - Fork 37
/
issuer.go
55 lines (48 loc) · 1.48 KB
/
issuer.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
50
51
52
53
54
55
package certify
import (
"context"
"crypto"
"crypto/tls"
"net"
"net/url"
)
// Issuer is the interface that must be implemented
// by certificate issuers.
type Issuer interface {
Issue(context.Context, string, *CertConfig) (*tls.Certificate, error)
}
// KeyGenerator defines an interface used to generate a private key.
type KeyGenerator interface {
Generate() (crypto.PrivateKey, error)
}
// CertConfig configures the specifics of the certificate
// requested from the Issuer.
type CertConfig struct {
SubjectAlternativeNames []string
IPSubjectAlternativeNames []net.IP
URISubjectAlternativeNames []*url.URL
// KeyGenerator is used to create new private keys
// for CSR requests. If not defined, defaults to ECDSA P256.
// Only ECDSA and RSA keys are supported.
// This is guaranteed to be provided in Issue calls.
KeyGenerator KeyGenerator
}
// Clone makes a deep copy of the CertConfig.
func (cc *CertConfig) Clone() *CertConfig {
newCC := new(CertConfig)
if cc == nil {
return newCC
}
newCC.SubjectAlternativeNames = cc.SubjectAlternativeNames
newCC.IPSubjectAlternativeNames = cc.IPSubjectAlternativeNames
newCC.URISubjectAlternativeNames = cc.URISubjectAlternativeNames
newCC.KeyGenerator = cc.KeyGenerator
return newCC
}
func (cc *CertConfig) appendName(name string) {
if ip := net.ParseIP(name); ip != nil {
cc.IPSubjectAlternativeNames = append(cc.IPSubjectAlternativeNames, ip)
} else {
cc.SubjectAlternativeNames = append(cc.SubjectAlternativeNames, name)
}
}