Skip to content

Commit d402002

Browse files
fix(crypto): fix a data race in ECDSAService EE-6502 (#561)
1 parent bebc54a commit d402002

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

crypto/ecdsa.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/base64"
88
"encoding/hex"
99
"math/big"
10+
"sync"
1011

1112
"github.com/portainer/agent"
1213
)
@@ -16,6 +17,7 @@ import (
1617
type ECDSAService struct {
1718
publicKey *ecdsa.PublicKey
1819
secret string
20+
mu sync.Mutex
1921
}
2022

2123
// NewECDSAService returns a pointer to a ECDSAService.
@@ -29,6 +31,9 @@ func NewECDSAService(secret string) *ECDSAService {
2931
// IsAssociated tells if the service is associated with a public key
3032
// or if it's secured behind a secret
3133
func (service *ECDSAService) IsAssociated() bool {
34+
service.mu.Lock()
35+
defer service.mu.Unlock()
36+
3237
return service.publicKey != nil || service.secret != ""
3338
}
3439

@@ -53,6 +58,9 @@ func (service *ECDSAService) VerifySignature(signature, key string) (bool, error
5358
}
5459

5560
func (service *ECDSAService) decodeAndParsePublicKey(key string) (*ecdsa.PublicKey, error) {
61+
service.mu.Lock()
62+
defer service.mu.Unlock()
63+
5664
if service.publicKey != nil {
5765
return service.publicKey, nil
5866
}

0 commit comments

Comments
 (0)