aboutsummaryrefslogtreecommitdiff
path: root/provider.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-05-22 16:48:10 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-05-22 16:48:10 +0200
commitddd02682605ebad46cd36714981a6859c69f349e (patch)
treea2f12fee5118e6480fdfb0a0bb4a8bebf974f052 /provider.go
parent9664c9a60a10cf7a91fbf9e93b595f2155a9543a (diff)
Refactor signer
Diffstat (limited to 'provider.go')
-rw-r--r--provider.go39
1 files changed, 9 insertions, 30 deletions
diff --git a/provider.go b/provider.go
index 78855f0..5c43655 100644
--- a/provider.go
+++ b/provider.go
@@ -1,6 +1,7 @@
package acme
import (
+ "crypto"
"encoding/json"
"errors"
"io/ioutil"
@@ -47,12 +48,10 @@ type Meta struct {
// Provider ...
type Provider struct {
Directory
- nonces chan string
http.Client
}
var (
- errNoNonces = errors.New("out of nonces")
errContentType = errors.New("unknown content type")
errChalType = errors.New("unknown challenge")
errStatus = errors.New("unexpected status")
@@ -67,37 +66,17 @@ const (
poll = time.Second
)
-// RoundTrip extracts nonces from HTTP reponse
-func (p *Provider) RoundTrip(req *http.Request) (*http.Response, error) {
- resp, err := http.DefaultTransport.RoundTrip(req)
+// DialProvider fetches directory and initializes first nonce
+func DialProvider(directory string, key crypto.PrivateKey) (*Provider, error) {
+ sig, err := NewSigner(key)
if err != nil {
return nil, err
}
- nonce := resp.Header.Get("Replay-Nonce")
- if nonce == "" {
- return nil, errNoNonces
- }
- if len(p.nonces) == cap(p.nonces) {
- <-p.nonces // drop oldest
- }
- p.nonces <- nonce
- return resp, nil
-}
-
-// Nonce implements jose nonce provider
-func (p *Provider) Nonce() (string, error) {
- select {
- case nonce := <-p.nonces:
- return nonce, nil
- case <-time.After(timeout):
- return "", errNoNonces
+ p := &Provider{
+ Client: http.Client{
+ Transport: sig,
+ },
}
-}
-
-// DialProvider fetches directory and initializes first nonce
-func DialProvider(directory string) (*Provider, error) {
- p := &Provider{nonces: make(chan string, 100)}
- p.Client = http.Client{Transport: p}
if directory == "" {
directory = LE1
}
@@ -113,7 +92,7 @@ func (p *Provider) post(uri string, s *Signer, v interface{}) (*http.Response, e
if err != nil {
return nil, err
}
- signed, err := s.Sign(msg, p)
+ signed, err := s.Sign(msg)
if err != nil {
return nil, err
}