Skip to content

Commit 4bf0f02

Browse files
committed
fix: get rid of data race in the key sign interceptor
The code underneath is not thread safe and it looks like we need a mutex. Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
1 parent 782aac0 commit 4bf0f02

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/pgp/key.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package pgp
88
import (
99
"crypto"
1010
"math"
11+
"sync"
1112
"time"
1213

1314
"github.com/ProtonMail/go-crypto/openpgp"
@@ -19,6 +20,7 @@ import (
1920
type Key struct {
2021
key *pgpcrypto.Key
2122
keyring *pgpcrypto.KeyRing
23+
mu sync.Mutex
2224
}
2325

2426
// GenerateKey generates a new PGP key pair.
@@ -77,6 +79,9 @@ func (p *Key) Verify(data, signature []byte) error {
7779

7880
// Sign signs the given data using the private key.
7981
func (p *Key) Sign(data []byte) ([]byte, error) {
82+
p.mu.Lock()
83+
defer p.mu.Unlock()
84+
8085
message := pgpcrypto.NewPlainMessage(data)
8186

8287
signature, err := p.keyring.SignDetached(message)

0 commit comments

Comments
 (0)