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
|
package acme
import "crypto/tls"
type CSR struct {
Resource Resource `json:"resource"` // new-cert
CSR string `json:"csr"`
}
func (p *Provider) Bundle(s Signer, d *Desire) (tls.Certificate, error) {
cert := tls.Certificate{PrivateKey: d.key}
csr, err := NewCSR(d.key, d.altnames)
if err != nil {
return cert, err
}
crt, up, err := p.RequestCert(s, d, csr)
if err != nil {
return cert, err
}
ca, err := p.GetCert(up)
if err != nil {
return cert, err
}
cert.Certificate = [][]byte{crt, ca}
return cert, nil
}
func (p *Provider) RequestCert(s Signer, d *Desire, csr string) ([]byte, string, error) {
req := &CSR{
Resource: ResNewCert,
CSR: csr,
}
resp, err := p.post(p.NewCert, s, req)
if err != nil {
return nil, "", err
}
ns := parseHeader(resp)
crt, err := parseCert(resp)
if err != nil {
return nil, "", err
}
return crt, ns.Link["up"], nil
}
func (p *Provider) GetCert(uri string) ([]byte, error) {
resp, err := p.Get(uri)
if err != nil {
return nil, err
}
return parseCert(resp)
}
|