aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--account.go4
-rw-r--r--client.go28
-rw-r--r--cmd/acme/main.go7
-rw-r--r--helper.go15
5 files changed, 51 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1377554
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.swp
diff --git a/account.go b/account.go
index 5264636..62d3213 100644
--- a/account.go
+++ b/account.go
@@ -7,8 +7,8 @@ import (
)
type Account struct {
- Contact []string
- PrivKey *rsa.PrivateKey
+ Contact []string `json:"contact"`
+ PrivKey *rsa.PrivateKey `json:"key"`
}
func NewAccount(email string, bits int) (Account, error) {
diff --git a/client.go b/client.go
index 8759ad1..8f7138a 100644
--- a/client.go
+++ b/client.go
@@ -6,6 +6,8 @@ import (
"io/ioutil"
"log"
"net/http"
+
+ jose "github.com/square/go-jose"
)
func Get(uri string, v interface{}) error {
@@ -36,3 +38,29 @@ 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{})
+ if err != nil {
+ return "", err
+ }
+ obj, err := signer.Sign(body)
+ if err != nil {
+ return "", err
+ }
+ return obj.FullSerialize(), nil
+}
+
+func ParseSigned(body string) error {
+ obj, err := jose.ParseSigned(body)
+ if err != nil {
+ return err
+ }
+ log.Printf("%+v\n", obj)
+ return nil
+}
diff --git a/cmd/acme/main.go b/cmd/acme/main.go
index c85d1b3..ac9e679 100644
--- a/cmd/acme/main.go
+++ b/cmd/acme/main.go
@@ -20,7 +20,10 @@ func main() {
acc, err := acme.NewAccount("Dimitri Sokolyuk <demon@dim13.org>", 2048)
must(err)
log.Println(acc)
+ //acme.Dump(acc)
- me := []string{"mailto:demon@dim13.org"}
- acme.Post(dir.NewReg, acme.NewRegistration(me))
+ acme.Post(dir.NewReg, acme.NewRegistration(acc.Contact))
+
+ s, _ := acme.Sign(acc, []byte("AAA"))
+ acme.ParseSigned(s)
}
diff --git a/helper.go b/helper.go
new file mode 100644
index 0000000..4315ac2
--- /dev/null
+++ b/helper.go
@@ -0,0 +1,15 @@
+package acme
+
+import (
+ "encoding/json"
+ "fmt"
+)
+
+func Dump(v interface{}) error {
+ body, err := json.MarshalIndent(v, "", "\t")
+ if err != nil {
+ return err
+ }
+ fmt.Println(string(body))
+ return nil
+}