Move back to square/go-jose

This commit is contained in:
xenolf 2015-11-12 02:06:22 +01:00
parent 438531d667
commit 998a8325aa
2 changed files with 17 additions and 10 deletions

View file

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

View file

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