aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-24 18:39:18 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-24 18:39:18 +0100
commit88533d6843eee95763c8e4782b60c4da17fc7609 (patch)
treeefdd6137717733ec2e3913e5d6942ce4fc93ccc0 /client.go
parentc7e20e280579bcabcb7b122ec11c88ccd057c4e2 (diff)
Add CSR request
Diffstat (limited to 'client.go')
-rw-r--r--client.go32
1 files changed, 28 insertions, 4 deletions
diff --git a/client.go b/client.go
index 8cfc06e..bbae554 100644
--- a/client.go
+++ b/client.go
@@ -1,6 +1,7 @@
package acme
import (
+ "crypto/rsa"
"encoding/json"
"errors"
"io/ioutil"
@@ -86,6 +87,12 @@ func (c *Client) post(uri string, s Signer, v interface{}) (*http.Response, erro
if err != nil {
return nil, err
}
+ // TODO: add content-type switch
+ // application/problem+json
+ // application/json
+ // application/pkix-cert
+ ct := resp.Header.Get("Content-Type")
+ log.Println(ansi.Color("CT", "green"), ct)
defer resp.Body.Close()
defer c.replyNonce(resp)
log.Println(ansi.Color("STATUS", "yellow"), resp.Status)
@@ -209,10 +216,10 @@ func pickChallenge(c []Challenge) (int, Challenge) {
return -1, Challenge{}
}
-func (c *Client) Authorize(a *Account, domain []string) error {
+func (c *Client) Authorize(a *Account, altnames []string) error {
ident := Identifier{
Type: IdentDNS,
- Value: domain[0],
+ Value: altnames[0],
}
r := &Authorization{
Resource: ResNewAuthz,
@@ -251,6 +258,7 @@ func (c *Client) Authorize(a *Account, domain []string) error {
ns := parseHeader(resp)
done := make(chan bool)
errc := make(chan error)
+ log.Println(ansi.Color("NextStep", "green"), ns)
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
go func() {
@@ -265,6 +273,8 @@ func (c *Client) Authorize(a *Account, domain []string) error {
select {
case <-done:
case err = <-errc:
+ case <-time.After(5 * time.Second):
+ return errors.New("timed out")
}
}
@@ -287,8 +297,22 @@ func (c *Client) Status(url string, n int, done chan bool) error {
log.Println(ansi.Color("DONE", "red:white"))
done <- true
}
- ns := parseHeader(resp)
- log.Println(ansi.Color("NEXT", "black:yellow"), ns)
+ return nil
+}
+
+func (c *Client) CSR(s Signer, altnames []string, key *rsa.PrivateKey) error {
+ csr, err := NewCSR(altnames, key)
+ if err != nil {
+ return err
+ }
+ r := &CSR{
+ Resource: ResNewCert,
+ CSR: csr,
+ }
+ _, err = c.post(c.NewCert, s, r)
+ if err != nil {
+ return err
+ }
return nil
}