mirror of
https://github.com/go-acme/lego.git
synced 2024-12-26 11:18:00 +02:00
Move back to square/go-jose (reverted from commit cae6d59e19
)
This commit is contained in:
parent
cae6d59e19
commit
a8c2a12871
25
acme/jws.go
25
acme/jws.go
@ -4,11 +4,10 @@ import (
|
||||
"bytes"
|
||||
"crypto/ecdsa"
|
||||
"crypto/rsa"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/square/go-jose"
|
||||
"github.com/letsencrypt/go-jose"
|
||||
)
|
||||
|
||||
type jws struct {
|
||||
@ -16,15 +15,10 @@ type jws struct {
|
||||
nonces []string
|
||||
}
|
||||
|
||||
func keyAsJWK(key interface{}) *jose.JsonWebKey {
|
||||
switch k := key.(type) {
|
||||
case *ecdsa.PublicKey:
|
||||
return &jose.JsonWebKey{Key: k, Algorithm: "EC"}
|
||||
case *rsa.PublicKey:
|
||||
return &jose.JsonWebKey{Key: k, Algorithm: "RSA"}
|
||||
|
||||
default:
|
||||
return nil
|
||||
func keyAsJWK(key *ecdsa.PublicKey) jose.JsonWebKey {
|
||||
return jose.JsonWebKey{
|
||||
Key: key,
|
||||
Algorithm: "EC",
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,9 +52,8 @@ func (j *jws) signContent(content []byte) (*jose.JsonWebSignature, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
signer.SetNonceSource(j)
|
||||
|
||||
signed, err := signer.Sign(content)
|
||||
signed, err := signer.Sign(content, j.consumeNonce())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -86,12 +79,12 @@ func (j *jws) getNonce(url string) error {
|
||||
return j.getNonceFromResponse(resp)
|
||||
}
|
||||
|
||||
func (j *jws) Nonce() (string, error) {
|
||||
func (j *jws) consumeNonce() string {
|
||||
nonce := ""
|
||||
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]
|
||||
return nonce, nil
|
||||
return nonce
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package acme
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/square/go-jose"
|
||||
"github.com/letsencrypt/go-jose"
|
||||
)
|
||||
|
||||
type directory struct {
|
||||
|
Loading…
Reference in New Issue
Block a user