From 32215b65656e77c2064fd0f0318bbc30ca96ce29 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 10 Dec 2015 14:17:23 +0100 Subject: WIP --- account.go | 7 +++++++ client.go | 20 ++++++++------------ cmd/x/main.go | 4 ++-- messages.go | 7 +++++-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/account.go b/account.go index a74f2d0..33f4e12 100644 --- a/account.go +++ b/account.go @@ -12,6 +12,7 @@ import ( // KeySize is a default RSA key size const KeySize = 2048 +// Account ... type Account struct { Contact []string `json:"contact"` PrivKey *rsa.PrivateKey `json:"key"` @@ -19,6 +20,7 @@ type Account struct { nonce chan string } +// NewAccount ... func NewAccount(email string, bits int) (*Account, error) { m, err := mail.ParseAddress(email) if err != nil { @@ -38,6 +40,11 @@ func LoadAccount(email string) (*Account, error) { return nil, nil } +// Signer describes a signing interface +type Signer interface { + Sign([]byte, jose.NonceSource) ([]byte, error) +} + func (a *Account) Sign(msg []byte, n jose.NonceSource) ([]byte, error) { if a.signer == nil { var err error diff --git a/client.go b/client.go index b144e6f..238543c 100644 --- a/client.go +++ b/client.go @@ -4,26 +4,25 @@ import ( "bytes" "encoding/json" "errors" - "log" "net/http" "net/textproto" "regexp" "time" - - "github.com/square/go-jose" ) +// Solver decribes a solving interface type Solver interface { Solve() } -type Signer interface { - Sign([]byte, jose.NonceSource) ([]byte, error) -} +// Links to the next stage +type Links map[string]string +// Client ... type Client struct { Dir Directory nonce chan string + Links Links } // NewClient fetches directory and initializes nonce @@ -71,7 +70,7 @@ func (c Client) Nonce() (string, error) { // Post is used for // new-reg, new-authz, challenge, new-cert -func (c Client) Post(s Signer, uri string, v interface{}) (*http.Response, error) { +func (c *Client) Post(s Signer, uri string, v interface{}) (*http.Response, error) { body, err := json.Marshal(v) if err != nil { return nil, err @@ -89,19 +88,16 @@ func (c Client) Post(s Signer, uri string, v interface{}) (*http.Response, error } c.nonce <- replyNonce(resp) + c.Links = links(resp) if resp.StatusCode >= http.StatusBadRequest { return nil, handleError(resp) } - log.Printf("%+v\n", link(resp)) - return resp, nil } -type Links map[string]string - -func link(r *http.Response) Links { +func links(r *http.Response) Links { links := make(Links) key := textproto.CanonicalMIMEHeaderKey("Link") reg := regexp.MustCompile(`^<(.*)>;rel="(.*)"`) diff --git a/cmd/x/main.go b/cmd/x/main.go index a876cec..d42d139 100644 --- a/cmd/x/main.go +++ b/cmd/x/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - c, err := acme.NewClient(acme.LEStaging) + c, err := acme.NewClient(acme.LES) if err != nil { log.Fatal(err) } @@ -27,5 +27,5 @@ func main() { log.Fatal(err) } log.Println(string(body)) - + log.Println(c) } diff --git a/messages.go b/messages.go index 28d531b..18fe0fb 100644 --- a/messages.go +++ b/messages.go @@ -9,8 +9,8 @@ import ( const ( // LEV1 Let's Encrytpt V1 LEV1 = `https://acme-v01.api.letsencrypt.org/directory` - // LEStaging Let's Encrypt Staging - LEStaging = `https://acme-staging.api.letsencrypt.org/directory` + // LES Let's Encrypt Staging + LES = `https://acme-staging.api.letsencrypt.org/directory` ) // Directory ... @@ -83,8 +83,10 @@ type Problem struct { Instance string `json:"instance"` } +// Status of request type Status int +// Statuses const ( StatusUnknown Status = iota StatusPending @@ -94,6 +96,7 @@ const ( StatusRevoked ) +// UnmarshalJSON implemets json interface for status decoding func (s *Status) UnmarshalJSON(b []byte) error { var status = map[string]Status{ "unknown": StatusUnknown, -- cgit v1.2.3