Move back to square/go-jose (reverted from commit cae6d59e19)

This commit is contained in:
xenolf 2015-11-18 21:15:49 +01:00
parent cae6d59e19
commit a8c2a12871
2 changed files with 10 additions and 17 deletions

View file

@ -4,11 +4,10 @@ import (
"bytes" "bytes"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/rsa" "crypto/rsa"
"errors"
"fmt" "fmt"
"net/http" "net/http"
"github.com/square/go-jose" "github.com/letsencrypt/go-jose"
) )
type jws struct { type jws struct {
@ -16,15 +15,10 @@ type jws struct {
nonces []string nonces []string
} }
func keyAsJWK(key interface{}) *jose.JsonWebKey { func keyAsJWK(key *ecdsa.PublicKey) jose.JsonWebKey {
switch k := key.(type) { return jose.JsonWebKey{
case *ecdsa.PublicKey: Key: key,
return &jose.JsonWebKey{Key: k, Algorithm: "EC"} Algorithm: "EC",
case *rsa.PublicKey:
return &jose.JsonWebKey{Key: k, Algorithm: "RSA"}
default:
return nil
} }
} }
@ -58,9 +52,8 @@ func (j *jws) signContent(content []byte) (*jose.JsonWebSignature, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
signer.SetNonceSource(j)
signed, err := signer.Sign(content) signed, err := signer.Sign(content, j.consumeNonce())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -86,12 +79,12 @@ func (j *jws) getNonce(url string) error {
return j.getNonceFromResponse(resp) return j.getNonceFromResponse(resp)
} }
func (j *jws) Nonce() (string, error) { func (j *jws) consumeNonce() string {
nonce := "" nonce := ""
if len(j.nonces) == 0 { if len(j.nonces) == 0 {
return nonce, errors.New("No nonce available.") return nonce
} }
nonce, j.nonces = j.nonces[len(j.nonces)-1], j.nonces[:len(j.nonces)-1] nonce, j.nonces = j.nonces[len(j.nonces)-1], j.nonces[:len(j.nonces)-1]
return nonce, nil return nonce
} }

View file

@ -3,7 +3,7 @@ package acme
import ( import (
"time" "time"
"github.com/square/go-jose" "github.com/letsencrypt/go-jose"
) )
type directory struct { type directory struct {