Skip to content

Commit cb5e207

Browse files
authored
sso_proxy: fix request signer hash panic (#274)
* make copy * new hasher for each request * func * spacing * go fmt
1 parent e49ca7a commit cb5e207

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

internal/proxy/request_signer.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var signingKeyHeader = "kid"
3838
// RequestSigner exposes an interface for digitally signing requests using an RSA private key.
3939
// See comments for the Sign() method below, for more on how this signature is constructed.
4040
type RequestSigner struct {
41-
hasher hash.Hash
41+
newHasher func() hash.Hash
4242
signingKey crypto.Signer
4343
publicKeyStr string
4444
publicKeyID string
@@ -79,7 +79,7 @@ func NewRequestSigner(signingKeyPemStr string) (*RequestSigner, error) {
7979
keyHash = hasher.Sum(keyHash)
8080

8181
return &RequestSigner{
82-
hasher: sha256.New(),
82+
newHasher: func() hash.Hash { return sha256.New() },
8383
signingKey: privateKey,
8484
publicKeyStr: string(publicKeyPEM),
8585
publicKeyID: hex.EncodeToString(keyHash),
@@ -168,9 +168,10 @@ func (signer RequestSigner) Sign(req *http.Request) error {
168168

169169
// Generate hash of the document buffer.
170170
var documentHash []byte
171-
signer.hasher.Reset()
172-
_, _ = signer.hasher.Write([]byte(repr))
173-
documentHash = signer.hasher.Sum(documentHash)
171+
hasher := signer.newHasher()
172+
hasher.Reset()
173+
_, _ = hasher.Write([]byte(repr))
174+
documentHash = hasher.Sum(documentHash)
174175

175176
// Sign the documentHash with the signing key.
176177
signatureBytes, err := signer.signingKey.Sign(rand.Reader, documentHash, crypto.SHA256)

0 commit comments

Comments
 (0)