diff options
Diffstat (limited to 'register.go')
-rw-r--r-- | register.go | 48 |
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 +} |