aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.go28
-rw-r--r--cmd/acme/main.go11
-rw-r--r--helper.go4
3 files changed, 29 insertions, 14 deletions
diff --git a/client.go b/client.go
index 8f7138a..e99bb74 100644
--- a/client.go
+++ b/client.go
@@ -3,24 +3,34 @@ package acme
import (
"bytes"
"encoding/json"
- "io/ioutil"
"log"
"net/http"
jose "github.com/square/go-jose"
)
+type Nonce []string
+
+var nonce = Nonce([]string{})
+
+func (n *Nonce) Parse(r *http.Response) {
+ nonce := r.Header.Get("Replay-Nonce")
+ *n = append(*n, nonce)
+}
+
+func (n Nonce) Nonce() (string, error) {
+ last := n[len(n)-1]
+ return last, nil
+}
+
func Get(uri string, v interface{}) error {
resp, err := http.Get(uri)
if err != nil {
return err
}
defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return err
- }
- return json.Unmarshal(body, v)
+ nonce.Parse(resp)
+ return json.NewDecoder(resp.Body).Decode(v)
}
func Post(uri string, v interface{}) error {
@@ -39,13 +49,9 @@ func Post(uri string, v interface{}) error {
return nil
}
-type Z struct{}
-
-func (Z) Nonce() (string, error) { return "test", nil }
-
func Sign(acc Account, body []byte) (string, error) {
signer, err := jose.NewSigner(jose.RS256, acc.PrivKey)
- signer.SetNonceSource(Z{})
+ signer.SetNonceSource(nonce)
if err != nil {
return "", err
}
diff --git a/cmd/acme/main.go b/cmd/acme/main.go
index ac9e679..eb83418 100644
--- a/cmd/acme/main.go
+++ b/cmd/acme/main.go
@@ -12,14 +12,19 @@ func must(err error) {
}
}
+const (
+ eMail = `Dimitri Sokolyuk <demon@dim13.org>`
+ keySize = 2048
+)
+
func main() {
dir, err := acme.NewDirectory(acme.LEV1)
must(err)
- log.Println(dir)
+ acme.Print(dir)
- acc, err := acme.NewAccount("Dimitri Sokolyuk <demon@dim13.org>", 2048)
+ acc, err := acme.NewAccount(eMail, keySize)
must(err)
- log.Println(acc)
+ acme.Print(acc)
//acme.Dump(acc)
acme.Post(dir.NewReg, acme.NewRegistration(acc.Contact))
diff --git a/helper.go b/helper.go
index 4315ac2..0ce20ae 100644
--- a/helper.go
+++ b/helper.go
@@ -13,3 +13,7 @@ func Dump(v interface{}) error {
fmt.Println(string(body))
return nil
}
+
+func Print(v interface{}) (int, error) {
+ return fmt.Printf("%+v\n", v)
+}