aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-03-14 14:02:11 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-03-14 14:02:11 +0100
commit2443d4d63cfd5ed7bd7bd6413b6bc958aba84200 (patch)
tree238ef3ff67241a77c81c51619a3a7995bb968a5f
parent52af623629dc7d739c4bcedcbafd2c8931f04d6b (diff)
Replace Account with Signer
-rw-r--r--account.go28
-rw-r--r--authorize.go2
-rw-r--r--certificate.go4
-rw-r--r--challenge.go2
-rw-r--r--cmd/acme/main.go10
-rw-r--r--provider.go2
-rw-r--r--register.go2
7 files changed, 22 insertions, 28 deletions
diff --git a/account.go b/account.go
index 8456ce7..a513d6e 100644
--- a/account.go
+++ b/account.go
@@ -8,19 +8,19 @@ import (
"io"
"strings"
- "gopkg.in/square/go-jose.v1"
+ "github.com/square/go-jose"
)
// KeySize is a default RSA key size
const KeySize = 2048
-// Account ...
-type Account struct {
+// Signer ...
+type Signer struct {
signer jose.Signer
thumb string
}
-func NewAccount(privKey crypto.PrivateKey) (*Account, error) {
+func NewSigner(privKey crypto.PrivateKey) (*Signer, error) {
thumb := func(alg string, pubKey crypto.PublicKey) (string, error) {
wk := &jose.JsonWebKey{Key: pubKey, Algorithm: alg}
t, err := wk.Thumbprint(crypto.SHA256)
@@ -36,7 +36,7 @@ func NewAccount(privKey crypto.PrivateKey) (*Account, error) {
if err != nil {
return nil, err
}
- return &Account{signer: s, thumb: t}, nil
+ return &Signer{signer: s, thumb: t}, nil
case *ecdsa.PrivateKey:
s, err := jose.NewSigner(jose.ES384, k)
if err != nil {
@@ -46,28 +46,22 @@ func NewAccount(privKey crypto.PrivateKey) (*Account, error) {
if err != nil {
return nil, err
}
- return &Account{signer: s, thumb: t}, nil
+ return &Signer{signer: s, thumb: t}, nil
default:
return nil, errKeyType
}
}
-// Signer describes a signing interface
-type Signer interface {
- Sign([]byte, jose.NonceSource) (io.Reader, error)
- KeyAuth(string) string
-}
-
// Sign implements Signer interface
-func (a Account) Sign(msg []byte, n jose.NonceSource) (io.Reader, error) {
- a.signer.SetNonceSource(n)
- obj, err := a.signer.Sign(msg)
+func (s Signer) Sign(msg []byte, n jose.NonceSource) (io.Reader, error) {
+ s.signer.SetNonceSource(n)
+ obj, err := s.signer.Sign(msg)
if err != nil {
return nil, err
}
return strings.NewReader(obj.FullSerialize()), nil
}
-func (a Account) KeyAuth(token string) string {
- return token + "." + a.thumb
+func (s Signer) KeyAuth(token string) string {
+ return token + "." + s.thumb
}
diff --git a/authorize.go b/authorize.go
index 00378e7..e3a0837 100644
--- a/authorize.go
+++ b/authorize.go
@@ -44,7 +44,7 @@ func (a Authorization) Supported(sols Solvers) []Challenge {
return nil
}
-func (p *Provider) Authorize(s Signer, sols Solvers, domain string) error {
+func (p *Provider) Authorize(s *Signer, sols Solvers, domain string) error {
req := &Authorization{
Resource: ResNewAuthz,
Identifier: Identifier{
diff --git a/certificate.go b/certificate.go
index ada5991..05ad0f1 100644
--- a/certificate.go
+++ b/certificate.go
@@ -10,7 +10,7 @@ type CSR struct {
CSR string `json:"csr"`
}
-func (p *Provider) Bundle(s Signer, key crypto.PrivateKey, altnames []string) (tls.Certificate, error) {
+func (p *Provider) Bundle(s *Signer, key crypto.PrivateKey, altnames []string) (tls.Certificate, error) {
cert := tls.Certificate{PrivateKey: key}
csr, err := NewCSR(key, altnames)
if err != nil {
@@ -28,7 +28,7 @@ func (p *Provider) Bundle(s Signer, key crypto.PrivateKey, altnames []string) (t
return cert, nil
}
-func (p *Provider) RequestCert(s Signer, csr string) ([]byte, string, error) {
+func (p *Provider) RequestCert(s *Signer, csr string) ([]byte, string, error) {
req := &CSR{
Resource: ResNewCert,
CSR: csr,
diff --git a/challenge.go b/challenge.go
index abc35ef..725a9a3 100644
--- a/challenge.go
+++ b/challenge.go
@@ -49,7 +49,7 @@ const (
ChallengeDNS ChalType = "dns-01"
)
-func (p *Provider) Solve(s Signer, ch Challenge, sol Solver) error {
+func (p *Provider) Solve(s *Signer, ch Challenge, sol Solver) error {
// update challenge
ch.Resource = ResChallenge
ch.KeyAuthorization = s.KeyAuth(ch.Token)
diff --git a/cmd/acme/main.go b/cmd/acme/main.go
index 2c977c7..e99d65e 100644
--- a/cmd/acme/main.go
+++ b/cmd/acme/main.go
@@ -29,23 +29,23 @@ func dialProvider(p provider) error {
return nil
}
-func load(a account) (*acme.Account, error) {
+func load(a account) (*acme.Signer, error) {
key, err := a.Load()
if err != nil {
return nil, err
}
log.Println("Load", a.KeyFile)
- return acme.NewAccount(key)
+ return acme.NewSigner(key)
}
-func register(prov *acme.Provider, a account) (*acme.Account, error) {
+func register(prov *acme.Provider, a account) (*acme.Signer, error) {
key, err := acme.NewKey(a.KeySize)
if err != nil {
return nil, err
}
defer a.Save(key)
- acc, err := acme.NewAccount(key)
+ acc, err := acme.NewSigner(key)
if err != nil {
return nil, err
}
@@ -83,7 +83,7 @@ func loadAccount(prov *acme.Provider, a account) error {
return nil
}
-func requestCert(prov *acme.Provider, acc *acme.Account, d domain) error {
+func requestCert(prov *acme.Provider, acc *acme.Signer, d domain) error {
c, err := d.Load()
if err != nil {
c.PrivateKey, err = acme.NewKey(d.KeySize)
diff --git a/provider.go b/provider.go
index 08fd993..b0866c3 100644
--- a/provider.go
+++ b/provider.go
@@ -104,7 +104,7 @@ func DialProvider(directory string) (*Provider, error) {
return p, parseJson(resp, &p.Directory)
}
-func (p Provider) post(uri string, s Signer, v interface{}) (*http.Response, error) {
+func (p Provider) post(uri string, s *Signer, v interface{}) (*http.Response, error) {
msg, err := json.Marshal(v)
if err != nil {
return nil, err
diff --git a/register.go b/register.go
index a66fa3f..f3fd1a9 100644
--- a/register.go
+++ b/register.go
@@ -22,7 +22,7 @@ type Registration struct {
CreatedAt *time.Time `json:"createdAt,omitempty"`
}
-func (p *Provider) Register(s Signer, c Contacts, agree func(string) bool) error {
+func (p *Provider) Register(s *Signer, c Contacts, agree func(string) bool) error {
// first step: new-reg
req := &Registration{
Resource: ResNewReg,