aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--account.go24
-rw-r--r--cmd/acme/main.go7
-rw-r--r--contact.go17
-rw-r--r--provider.go6
4 files changed, 27 insertions, 27 deletions
diff --git a/account.go b/account.go
index 3fa1ae7..62f1c78 100644
--- a/account.go
+++ b/account.go
@@ -5,7 +5,6 @@ import (
"crypto/rsa"
"encoding/base64"
"io"
- "net/mail"
"strings"
"github.com/square/go-jose"
@@ -16,10 +15,9 @@ const KeySize = 2048
// Account ...
type Account struct {
- contact Contacts
- key *rsa.PrivateKey
- signer jose.Signer
- nonce chan string
+ key *rsa.PrivateKey
+ signer jose.Signer
+ nonce chan string
}
// NewAccount ...
@@ -31,22 +29,6 @@ func NewAccount(key *rsa.PrivateKey) (*Account, error) {
return &Account{key: key, signer: signer}, nil
}
-func (a *Account) AddMail(email string) error {
- m, err := mail.ParseAddress(email)
- if err != nil {
- return err
- }
- a.contact = append(a.contact, Mail(m.Address))
- return nil
-}
-
-func (a *Account) AddPhone(phone string) error {
- if ph := strings.TrimSpace(phone); ph != "" {
- a.contact = append(a.contact, Phone(ph))
- }
- return nil
-}
-
// Signer describes a signing interface
type Signer interface {
Sign([]byte, jose.NonceSource) (io.Reader, error)
diff --git a/cmd/acme/main.go b/cmd/acme/main.go
index 2243ac3..0fa0ddc 100644
--- a/cmd/acme/main.go
+++ b/cmd/acme/main.go
@@ -76,8 +76,9 @@ func main() {
for k, des := range conf.Desire {
a, _ := acme.NewAccount(des.account.key)
- a.AddMail(des.account.Mail)
- a.AddPhone(des.account.Phone)
+ c := acme.Contacts{}
+ c.AddMail(des.account.Mail)
+ c.AddPhone(des.account.Phone)
log.Println(k, a)
p, err := acme.NewProvider(des.provider.Directory)
if err != nil {
@@ -85,7 +86,7 @@ func main() {
}
log.Println(k, p)
- err = p.Register(a)
+ err = p.Register(a, c)
if err != nil {
log.Fatal("register", err)
}
diff --git a/contact.go b/contact.go
index 8b0b054..7d6446c 100644
--- a/contact.go
+++ b/contact.go
@@ -4,6 +4,7 @@ import (
"encoding"
"encoding/json"
"errors"
+ "net/mail"
"strings"
)
@@ -46,3 +47,19 @@ func (c *Contacts) UnmarshalJSON(b []byte) error {
}
return nil
}
+
+func (c *Contacts) AddMail(email string) error {
+ m, err := mail.ParseAddress(email)
+ if err != nil {
+ return err
+ }
+ *c = append(*c, Mail(m.Address))
+ return nil
+}
+
+func (c *Contacts) AddPhone(phone string) error {
+ if ph := strings.TrimSpace(phone); ph != "" {
+ *c = append(*c, Phone(ph))
+ }
+ return nil
+}
diff --git a/provider.go b/provider.go
index a9ff15a..c6b8e9f 100644
--- a/provider.go
+++ b/provider.go
@@ -175,10 +175,10 @@ func parseHeader(r *http.Response) nextStep {
challenge cert-chain
*/
-func (p *Provider) Register(a *Account) error {
+func (p *Provider) Register(a *Account, c Contacts) error {
r := &Registration{
Resource: ResNewReg,
- Contact: a.contact,
+ Contact: c,
}
resp, err := p.post(p.NewReg, a, r)
if err != nil && err.(Problem).Err != ErrMalformed {
@@ -199,7 +199,7 @@ func (p *Provider) Register(a *Account) error {
if tos := ns.Link["terms-of-service"]; tos != "" {
r = &Registration{
Resource: ResReg,
- Contact: a.contact,
+ Contact: c,
Agreement: tos,
}
_, err = p.post(ns.Location.String(), a, r)