aboutsummaryrefslogtreecommitdiff
path: root/certificate.go
diff options
context:
space:
mode:
Diffstat (limited to 'certificate.go')
-rw-r--r--certificate.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/certificate.go b/certificate.go
index 292059a..195d56f 100644
--- a/certificate.go
+++ b/certificate.go
@@ -8,29 +8,37 @@ type CSR struct {
}
func (p *Provider) Bundle(s Signer, d *Desire) error {
- d.cert = make([]*x509.Certificate, 2)
- // first step: post csr
- csr, err := d.CSR()
+ crt, up, err := p.RequestCert(s, d)
+ if err != nil {
+ return err
+ }
+ ca, err := p.GetCert(up)
if err != nil {
return err
}
+ d.cert = []*x509.Certificate{crt, ca}
+ return nil
+}
+
+func (p *Provider) RequestCert(s Signer, d *Desire) (*x509.Certificate, string, error) {
+ csr, err := d.CSR()
+ if err != nil {
+ return nil, "", err
+ }
req := &CSR{
Resource: ResNewCert,
CSR: csr,
}
resp, err := p.post(p.NewCert, s, req)
if err != nil {
- return err
+ return nil, "", err
}
- d.cert[0], err = parseCert(resp)
+ ns := parseHeader(resp)
+ crt, err := parseCert(resp)
if err != nil {
- return err
+ return nil, "", err
}
- ns := parseHeader(resp)
-
- // second step: cet CA
- d.cert[1], err = p.GetCert(ns.Link["up"])
- return err
+ return crt, ns.Link["up"], nil
}
func (p *Provider) GetCert(uri string) (*x509.Certificate, error) {