forked from TrueCloudLab/lego
Revert adding locks to jws - not in scope of this branch
This commit is contained in:
parent
6671fd137c
commit
487c8763d5
1 changed files with 7 additions and 19 deletions
16
acme/jws.go
16
acme/jws.go
|
@ -6,7 +6,6 @@ import (
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/letsencrypt/go-jose"
|
"github.com/letsencrypt/go-jose"
|
||||||
)
|
)
|
||||||
|
@ -14,7 +13,6 @@ import (
|
||||||
type jws struct {
|
type jws struct {
|
||||||
privKey *rsa.PrivateKey
|
privKey *rsa.PrivateKey
|
||||||
nonces []string
|
nonces []string
|
||||||
nonceMutex sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func keyAsJWK(key *ecdsa.PublicKey) jose.JsonWebKey {
|
func keyAsJWK(key *ecdsa.PublicKey) jose.JsonWebKey {
|
||||||
|
@ -26,10 +24,12 @@ func keyAsJWK(key *ecdsa.PublicKey) jose.JsonWebKey {
|
||||||
|
|
||||||
// Posts a JWS signed message to the specified URL
|
// Posts a JWS signed message to the specified URL
|
||||||
func (j *jws) post(url string, content []byte) (*http.Response, error) {
|
func (j *jws) post(url string, content []byte) (*http.Response, error) {
|
||||||
|
if len(j.nonces) == 0 {
|
||||||
err := j.getNonce(url)
|
err := j.getNonce(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Could not get a nonce for request: %s\n\t\tError: %v", url, err)
|
return nil, fmt.Errorf("Could not get a nonce for request: %s\n\t\tError: %v", url, err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
signedContent, err := j.signContent(content)
|
signedContent, err := j.signContent(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -66,20 +66,11 @@ func (j *jws) getNonceFromResponse(resp *http.Response) error {
|
||||||
return fmt.Errorf("Server did not respond with a proper nonce header.")
|
return fmt.Errorf("Server did not respond with a proper nonce header.")
|
||||||
}
|
}
|
||||||
|
|
||||||
j.nonceMutex.Lock()
|
|
||||||
j.nonces = append(j.nonces, nonce)
|
j.nonces = append(j.nonces, nonce)
|
||||||
j.nonceMutex.Unlock()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *jws) getNonce(url string) error {
|
func (j *jws) getNonce(url string) error {
|
||||||
j.nonceMutex.Lock()
|
|
||||||
if len(j.nonces) > 0 {
|
|
||||||
j.nonceMutex.Unlock()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
j.nonceMutex.Unlock()
|
|
||||||
|
|
||||||
resp, err := http.Head(url)
|
resp, err := http.Head(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -89,9 +80,6 @@ func (j *jws) getNonce(url string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *jws) consumeNonce() string {
|
func (j *jws) consumeNonce() string {
|
||||||
j.nonceMutex.Lock()
|
|
||||||
defer j.nonceMutex.Unlock()
|
|
||||||
|
|
||||||
nonce := ""
|
nonce := ""
|
||||||
if len(j.nonces) == 0 {
|
if len(j.nonces) == 0 {
|
||||||
return nonce
|
return nonce
|
||||||
|
|
Loading…
Reference in a new issue