Skip to content

Commit 16e274e

Browse files
committed
Add missing error handling for ecdh session
1 parent 2e0200e commit 16e274e

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

cmd/mpcium/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
const (
34-
Version = "0.3.1"
34+
Version = "0.3.2"
3535
DefaultBackupPeriodSeconds = 300 // (5 minutes)
3636
)
3737

pkg/identity/identity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func (s *fileStore) VerifySignature(msg *types.ECDHMessage) error {
484484

485485
// Verify the signature
486486
if !ed25519.Verify(senderPk, msgBytes, msg.Signature) {
487-
return fmt.Errorf("invalid signature")
487+
return fmt.Errorf("invalid signature from %s with public key %s", msg.From, hex.EncodeToString(senderPk))
488488
}
489489

490490
return nil

pkg/mpc/registry.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func NewRegistry(
7272
logger.Fatal("mpc_threshold must be greater than 0", nil)
7373
}
7474

75-
return &registry{
75+
reg := &registry{
7676
consulKV: consulKV,
7777
nodeID: nodeID,
7878
peerNodeIDs: getPeerIDsExceptSelf(nodeID, peerNodeIDs),
@@ -84,6 +84,10 @@ func NewRegistry(
8484
ecdhSession: ecdhSession,
8585
mpcThreshold: mpcThreshold,
8686
}
87+
88+
go reg.consumeECDHErrors()
89+
90+
return reg
8791
}
8892

8993
func getPeerIDsExceptSelf(nodeID string, peerNodeIDs []string) []string {
@@ -160,7 +164,7 @@ func (r *registry) Ready() error {
160164

161165
_, err = r.healthCheck.Listen(r.composeHealthCheckTopic(r.nodeID), func(data []byte) {
162166
peerID, isEcdhReady, _ := parseHealthDataSplit(string(data))
163-
logger.Debug("Health check ok", "peerID", peerID)
167+
logger.Debug("Health check ok", "peerID", peerID, "isEcdhReady", isEcdhReady)
164168
if !isEcdhReady {
165169
logger.Info("[ECDH exchange retriggerd] not all peers are ready", "peerID", peerID)
166170
go r.triggerECDHExchange()
@@ -367,9 +371,16 @@ func parseHealthDataSplit(s string) (peerID string, ready bool, err error) {
367371
}
368372

369373
peerID = parts[0]
370-
ready, err = strconv.ParseBool(parts[1]) // accepts "true"/"false", "1"/"0", "t"/"f"
374+
ready, err = strconv.ParseBool(parts[1])
371375
if err != nil {
372376
return "", false, err
373377
}
374378
return peerID, ready, nil
375379
}
380+
381+
// consumeECDHErrors consumes errors from ECDH session and logs them
382+
func (r *registry) consumeECDHErrors() {
383+
for err := range r.ecdhSession.ErrChan() {
384+
logger.Error("ECDH error", err)
385+
}
386+
}

0 commit comments

Comments
 (0)