aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-21 00:35:34 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-21 00:35:34 +0100
commitd2afad37c087ba4f0026dc08d11cddcd5fde400e (patch)
treea366da78ef7018d7efe6dc3c13c81a64f1f38918
parenta40075b5a70eac0027f15576c4b16ea39faf940a (diff)
Cleanup
-rw-r--r--client.go28
-rw-r--r--cmd/acme/main.go27
-rw-r--r--messages.go8
3 files changed, 37 insertions, 26 deletions
diff --git a/client.go b/client.go
index 8b9cf5d..7c32b70 100644
--- a/client.go
+++ b/client.go
@@ -114,22 +114,27 @@ func (c *Client) post(s Signer, v interface{}) error {
var linksRe = regexp.MustCompile(`^<(.*)>;rel="(.*)"`)
func (c *Client) parseHeader(r *http.Response) {
- c.nonce <- r.Header.Get("Replay-Nonce")
+ if no := r.Header.Get("Replay-Nonce"); no != "" {
+ c.nonce <- no
+ }
- c.Location = r.Header.Get("Location")
+ if lo := r.Header.Get("Location"); lo != "" {
+ c.Location = lo
+ }
c.Link = make(Links)
- for _, l := range r.Header["Link"] {
- re := linksRe.FindStringSubmatch(l)
+ for _, li := range r.Header["Link"] {
+ re := linksRe.FindStringSubmatch(li)
if len(re) == 3 {
c.Link[re[2]] = re[1]
}
}
- c.RetryAfter = time.Second
- ra, err := strconv.Atoi(r.Header.Get("Retry-After"))
- if err == nil {
- c.RetryAfter *= time.Duration(ra)
+ if ra := r.Header.Get("Retry-After"); ra != "" {
+ n, err := strconv.Atoi(ra)
+ if err == nil {
+ c.RetryAfter = time.Second * time.Duration(n)
+ }
}
}
@@ -171,11 +176,6 @@ func (c *Client) Agree(a *Account) (*Registration, error) {
return r, c.post(a, r)
}
-func (c *Client) Query(a *Account) (*Registration, error) {
- r := &Registration{Resource: ResRegister}
- return r, c.post(a, r)
-}
-
func (c *Client) Authorize(a *Account, domain string) (*Authorization, error) {
r := &Authorization{
Resource: ResNewAuthz,
@@ -189,5 +189,5 @@ func (c *Client) Authorize(a *Account, domain string) (*Authorization, error) {
}
func (c Client) String() string {
- return fmt.Sprintf("Link: %v, Location: %v", c.Link, c.Location)
+ return fmt.Sprintf("Location: %v Links: %v", c.Location, c.Link)
}
diff --git a/cmd/acme/main.go b/cmd/acme/main.go
index a1a6870..1073e88 100644
--- a/cmd/acme/main.go
+++ b/cmd/acme/main.go
@@ -94,18 +94,29 @@ func main() {
if err != nil {
log.Println(err)
}
- r, err := c.Register(a)
+ log.Println(k, c)
+
+ re, err := c.Register(a)
if err != nil {
- log.Println(err)
+ log.Println("register", err)
}
- log.Println(k, c)
- log.Println(k, r)
- r, err = c.Query(a)
+ log.Println(k, "register", c)
+ log.Println(k, "register", re)
+
+ re, err = c.Agree(a)
+ re, err = c.Agree(a)
if err != nil {
- log.Println(err)
+ log.Println("agree", err)
}
- log.Println(k, c)
- log.Println(k, r)
+ log.Println(k, "agree", c)
+ log.Println(k, "agree", re)
+
+ az, err := c.Authorize(a, des.Altnames[0])
+ if err != nil {
+ log.Println("authz", err)
+ }
+ log.Println(k, "authz", c)
+ log.Println(k, "authz", az)
}
}
diff --git a/messages.go b/messages.go
index 7546088..3933592 100644
--- a/messages.go
+++ b/messages.go
@@ -34,15 +34,15 @@ type Registration struct {
ID int `json:"id,omitempty"`
Key *jose.JsonWebKey `json:"key,omitempty"`
InitialIP *net.IP `json:"initialIp,omitempty"` // not in draft
- CreatedAt *time.Time `json:"createdAt,omitempty"` // 2006-01-02T15:04:05.999999999Z
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
}
// Authorization request
type Authorization struct {
Resource Resource `json:"resource"` // new-authz
Identifier Identifier `json:"identifier"`
- Status Status `json:"status,omitempty"` // e.g. valid
- Expires *time.Time `json:"expires,omitempty"` // 2006-01-02
+ Status Status `json:"status,omitempty"` // e.g. valid
+ Expires *time.Time `json:"expires,omitempty"`
Challenges []Challenge `json:"challenges,omitempty"`
Combinations [][]int `json:"combinations,omitempty"`
}
@@ -60,7 +60,7 @@ type Challenge struct {
Token string `json:"token"`
Status Status `json:"status,omitempty"` // e.g. valid
URI string `json:"uri,omitempty"`
- Validated *time.Time `json:"validated,omitempty"` // 2006-01-02T15:04Z
+ Validated *time.Time `json:"validated,omitempty"`
KeyAuthorization string `json:"keyAuthorization,omitempty"`
}