aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-21 16:42:06 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-21 16:42:06 +0100
commit352e343f51a7a923f50b275f188d82e08d8fa318 (patch)
tree5780c7506f02245f6c2108231e1dadf628f28518
parentacb9c5d087924b77d83a3fc65813c19b65e90298 (diff)
Agree to TOS
-rw-r--r--account.go24
-rw-r--r--client.go41
-rw-r--r--cmd/acme/main.go20
3 files changed, 38 insertions, 47 deletions
diff --git a/account.go b/account.go
index e3a0392..e0d24b0 100644
--- a/account.go
+++ b/account.go
@@ -35,20 +35,22 @@ func newPhone(phone string) (Phone, error) {
}
// NewAccount ...
-func NewAccount(email, phone string, key *rsa.PrivateKey) (*Account, error) {
- var c Contacts
- m, err := newMail(email)
- if err != nil {
- return nil, err
+func NewAccount(key *rsa.PrivateKey) (*Account, error) {
+ return &Account{PrivKey: key}, nil
+}
+
+func (a *Account) AddMail(mail string) error {
+ if m, _ := newMail(mail); m != "" {
+ a.Contact = append(a.Contact, m)
}
- c = append(c, m)
+ return nil
+}
+
+func (a *Account) AddPhone(phone string) error {
if ph, _ := newPhone(phone); ph != "" {
- c = append(c, ph)
+ a.Contact = append(a.Contact, ph)
}
- return &Account{
- Contact: c,
- PrivKey: key,
- }, nil
+ return nil
}
// Signer describes a signing interface
diff --git a/client.go b/client.go
index 4cb0aa9..16644c5 100644
--- a/client.go
+++ b/client.go
@@ -159,41 +159,40 @@ func (c *Client) parseHeader(r *http.Response) {
challenge cert-chain
*/
-func (c *Client) Register(a *Account) (*Registration, error) {
+func (c *Client) Register(a *Account) error {
r := &Registration{
Resource: ResNewReg,
Contact: a.Contact,
}
- _, err := c.post(c.Dir.NewReg, a, r)
- return r, err
-}
-
-// Agree to TOS
-func (c *Client) Agree(a *Account) (*Registration, error) {
- tos := c.Link["terms-of-service"]
- if tos == "" {
- return nil, errors.New("TOS agreed")
- }
- r := &Registration{
- Resource: ResRegister,
- Contact: a.Contact,
- Agreement: tos,
+ resp, err := c.post(c.Dir.NewReg, a, r)
+ switch resp.StatusCode {
+ case http.StatusConflict:
+ // Query Location
+ r.Resource = ResRegister
+ _, err = c.post(c.Location, a, r)
+ fallthrough
+ case http.StatusCreated:
+ // Agree to TOS
+ if tos := c.Link["terms-of-service"]; tos != "" {
+ r.Resource = ResRegister
+ r.Agreement = tos
+ _, err = c.post(c.Location, a, r)
+ }
}
- log.Println("TOS", tos)
- _, err := c.post(c.Location, a, r)
- return r, err
+ return err
}
-func (c *Client) Authorize(a *Account, domain string) (*Authorization, error) {
+func (c *Client) Authorize(a *Account, domain []string) error {
r := &Authorization{
Resource: ResNewAuthz,
Identifier: Identifier{
Type: IdentDNS,
- Value: domain,
+ Value: domain[0],
},
}
_, err := c.post(c.Dir.NewAuthz, a, r)
- return r, err
+ log.Println(r)
+ return err
}
func (c Client) String() string {
diff --git a/cmd/acme/main.go b/cmd/acme/main.go
index 0606fb7..c84367b 100644
--- a/cmd/acme/main.go
+++ b/cmd/acme/main.go
@@ -83,7 +83,9 @@ func main() {
}
for k, des := range conf.Desire {
- a, _ := acme.NewAccount(des.account.Mail, des.account.Phone, des.account.key)
+ a, _ := acme.NewAccount(des.account.key)
+ a.AddMail(des.account.Mail)
+ a.AddPhone(des.account.Phone)
log.Println(k, a)
c, err := acme.NewClient(des.provider.Directory)
if err != nil {
@@ -91,27 +93,15 @@ func main() {
}
log.Println(k, c)
- re, err := c.Register(a)
+ err = c.Register(a)
if err != nil {
log.Println("register", err)
}
- 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("agree", err)
- }
- log.Println(k, "agree", c)
- log.Println(k, "agree", re)
-
- az, err := c.Authorize(a, des.Altnames[0])
+ err = c.Authorize(a, des.Altnames)
if err != nil {
log.Println("authz", err)
}
- log.Println(k, "authz", c)
- log.Println(k, "authz", az)
}
}