aboutsummaryrefslogtreecommitdiff
path: root/register.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-01-31 23:15:27 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-01-31 23:15:27 +0100
commitc49a0bf48ea10b54dbac3480716d9786a0ce8411 (patch)
tree3ce88f2422f3484aa95f77669fdafdfb6b2e63d9 /register.go
parentc9038d2f35945774f6cd32ade7b3abd1cd5ba952 (diff)
Split files (experimental)
Diffstat (limited to 'register.go')
-rw-r--r--register.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/register.go b/register.go
new file mode 100644
index 0000000..e002853
--- /dev/null
+++ b/register.go
@@ -0,0 +1,48 @@
+package acme
+
+import (
+ "net"
+ "time"
+
+ "github.com/square/go-jose"
+)
+
+// Registration Objects
+type Registration struct {
+ Resource Resource `json:"resource"` // new-reg
+ Contact Contacts `json:"contact,omitempty"`
+ Agreement string `json:"agreement,omitempty"`
+ Authorizations string `json:"authorizations,omitempty"`
+ Certificates string `json:"certificates,omitempty"`
+ 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"`
+}
+
+func (p *Provider) Register(s Signer, c Contacts) error {
+ // first step: new-reg
+ req := &Registration{
+ Resource: ResNewReg,
+ Contact: c,
+ }
+ resp, err := p.post(p.NewReg, s, req)
+ if err != nil {
+ return err
+ }
+ resp.Body.Close()
+ ns := parseHeader(resp)
+
+ // second step: reg, agree to tos
+ req = &Registration{
+ Resource: ResReg,
+ Agreement: ns.Link["terms-of-service"],
+ }
+ resp, err = p.post(ns.Location, s, req)
+ if err != nil {
+ return err
+ }
+ resp.Body.Close()
+
+ return nil
+}