aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challange_http.go16
-rw-r--r--client.go21
2 files changed, 31 insertions, 6 deletions
diff --git a/challange_http.go b/challange_http.go
index ee1708a..bd53ebf 100644
--- a/challange_http.go
+++ b/challange_http.go
@@ -2,8 +2,11 @@ package acme
import (
"io"
+ "io/ioutil"
"net"
"net/http"
+ "os"
+ "path"
)
const wellKnown = `/.well-known/acme-challenge/`
@@ -41,3 +44,16 @@ func (c httpChallenge) Solve() error {
<-done
return nil
}
+
+type webRoot struct {
+ Challenge
+ Webroot string
+}
+
+func (c webRoot) Solve() error {
+ file := path.Join(c.Webroot, wellKnown, c.Token)
+ if err := os.MkdirAll(path.Dir(file), 0755); err != nil {
+ return err
+ }
+ return ioutil.WriteFile(file, []byte(c.KeyAuthorization), 0644)
+}
diff --git a/client.go b/client.go
index 4be5bdf..84906b5 100644
--- a/client.go
+++ b/client.go
@@ -228,31 +228,40 @@ func (c *Client) Authorize(a *Account, domain []string) error {
_, err = c.post(ch.URI, a, ans)
switch ch.Type {
case ChallengeHTTP:
- httpChallenge{Addr: ":80", Challenge: *ans}.Solve()
+ httpChallenge{Addr: ":8080", Challenge: *ans}.Solve()
}
}
}
for {
- az, err := c.Status(ns.Location.String())
+ az, ra, err := c.Status(ns.Location.String())
if err != nil {
return err
}
log.Println(az)
- time.Sleep(time.Second)
+ log.Println(ra)
+ for _, ch := range az.Challenges {
+ switch ch.Status {
+ case StatusPending, StatusProcessing:
+ default:
+ return nil
+ }
+ }
+ time.Sleep(ra)
}
}
return err
}
-func (c *Client) Status(url string) (*Authorization, error) {
+func (c *Client) Status(url string) (*Authorization, time.Duration, error) {
r := &Authorization{}
resp, err := http.Get(url)
if err != nil {
- return nil, err
+ return nil, time.Second, err
}
defer resp.Body.Close()
defer c.replyNonce(resp)
- return r, json.NewDecoder(resp.Body).Decode(r)
+ ns := parseHeader(resp)
+ return r, ns.RetryAfter, json.NewDecoder(resp.Body).Decode(r)
}
////////////////////////////////////////////////////////////////////////