Skip to content

Commit

Permalink
Fix for 5.10 reshare denial of service via predicable instance ids (#152
Browse files Browse the repository at this point in the history
)

* fix 5.10 Reshare Denial-of-Service via Predicable
Instance IDs

* refactor

* lint
  • Loading branch information
pavelkrolevets authored Nov 11, 2024
1 parent dcd95be commit abbc1fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
17 changes: 9 additions & 8 deletions pkgs/initiator/initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ func (c *Initiator) ResignMessageFlowHandling(signedResign *wire.SignedResign, i
// reqIDtracker is used to track if all ceremony are in the responses in the expected order
reqIDs := make([][24]byte, 0)
for _, msg := range signedResign.Messages {
reqID, err := utils.GetReqIDfromMsg(msg)
msgID, err := utils.GetReqIDfromMsg(msg, id)
if err != nil {
return nil, err
}
reqIDs = append(reqIDs, reqID)
reqIDs = append(reqIDs, msgID)
}
resignResult, errs, err := c.SendResignMsg(id, signedResign, operators)
if err != nil {
Expand Down Expand Up @@ -270,11 +270,11 @@ func (c *Initiator) ReshareMessageFlowHandling(id [24]byte, signedReshare *wire.
// reqIDtracker is used to track if all ceremony are in the responses in the expected order
reqIDs := make([][24]byte, 0)
for _, msg := range signedReshare.Messages {
reqID, err := utils.GetReqIDfromMsg(msg)
msgID, err := utils.GetReqIDfromMsg(msg, id)
if err != nil {
return nil, err
}
reqIDs = append(reqIDs, reqID)
reqIDs = append(reqIDs, msgID)
}
c.Logger.Info("sending signed reshare message to all operators")
var errs map[uint64]error
Expand Down Expand Up @@ -394,11 +394,11 @@ func (c *Initiator) StartResigning(id [24]byte, signedResign *wire.SignedResign)
}
resignIDMap := make(map[[24]byte]*spec.Resign)
for _, msg := range signedResign.Messages {
reqID, err := utils.GetReqIDfromMsg(msg)
msgID, err := utils.GetReqIDfromMsg(msg, id)
if err != nil {
return nil, nil, nil, err
}
resignIDMap[reqID] = msg.Resign
resignIDMap[msgID] = msg.Resign
}
var operatorIDs []uint64
for _, op := range signedResign.Messages[0].Operators {
Expand Down Expand Up @@ -511,11 +511,11 @@ func (c *Initiator) StartResharing(id [24]byte, signedReshare *wire.SignedReshar
}
reshareIDMap := make(map[[24]byte]*spec.Reshare)
for _, msg := range signedReshare.Messages {
reqID, err := utils.GetReqIDfromMsg(msg)
msgID, err := utils.GetReqIDfromMsg(msg, id)
if err != nil {
return nil, nil, nil, err
}
reshareIDMap[reqID] = msg.Reshare
reshareIDMap[msgID] = msg.Reshare
}
oldOperatorIDs := make([]uint64, 0)
for _, op := range signedReshare.Messages[0].Reshare.OldOperators {
Expand Down Expand Up @@ -970,3 +970,4 @@ func (c *Initiator) createBulkResults(resultsBytes [][][]byte, signedMsg, msgIDM
}
return bulkDepositData, bulkKeyShares, bulkProofs, nil
}

16 changes: 8 additions & 8 deletions pkgs/operator/instances_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (s *Switch) HandleInstanceOperation(reqID [24]byte, transportMsg *wire.Tran
resps := [][]byte{}
// Run all resign/reshare ceremonies
for _, instance := range signedResign.Messages {
resp, err := s.runInstance(instance, allOps, initiatorPubKey, operationType)
resp, err := s.runInstance(reqID, instance, allOps, initiatorPubKey, operationType)
if err != nil {
return nil, fmt.Errorf("%s: failed to run instance: %w", operationType, err)
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func (s *Switch) HandleInstanceOperation(reqID [24]byte, transportMsg *wire.Tran
resps := [][]byte{}
// Run all resign/reshare ceremonies
for _, instance := range signedReshare.Messages {
resp, err := s.runInstance(instance, allOps, initiatorPubKey, operationType)
resp, err := s.runInstance(reqID, instance, allOps, initiatorPubKey, operationType)
if err != nil {
return nil, fmt.Errorf("%s: failed to run instance: %w", operationType, err)
}
Expand Down Expand Up @@ -285,23 +285,23 @@ func (s *Switch) validateInstances(reqID InstanceID) error {
return nil
}

func (s *Switch) runInstance(instance interface{}, allOps []*spec.Operator, initiatorPubKey *rsa.PublicKey, operationType string) ([]byte, error) {
reqID, err := utils.GetReqIDfromMsg(instance)
func (s *Switch) runInstance(reqID [24]byte, instance interface{}, allOps []*spec.Operator, initiatorPubKey *rsa.PublicKey, operationType string) ([]byte, error) {
instanceID, err := utils.GetReqIDfromMsg(instance, reqID)
if err != nil {
return nil, err
}
if err := s.validateInstances(reqID); err != nil {
if err := s.validateInstances(instanceID); err != nil {
return nil, err
}

inst, resp, err := s.CreateInstance(reqID, allOps, instance, initiatorPubKey)
inst, resp, err := s.CreateInstance(instanceID, allOps, instance, initiatorPubKey)
if err != nil {
return nil, fmt.Errorf("%s: failed to create instance: %w", operationType, err)
}

s.Mtx.Lock()
s.Instances[reqID] = inst
s.InstanceInitTime[reqID] = time.Now()
s.Instances[instanceID] = inst
s.InstanceInitTime[instanceID] = time.Now()
s.Mtx.Unlock()

return resp, nil
Expand Down
5 changes: 3 additions & 2 deletions pkgs/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,15 @@ func GetMessageHash(msg interface{}) ([32]byte, error) {
return hash, nil
}

func GetReqIDfromMsg(instance interface{}) ([24]byte, error) {
func GetReqIDfromMsg(instance interface{}, id [24]byte) ([24]byte, error) {
// make a unique ID for each reshare using the instance hash
reqID := [24]byte{}
instanceHash, err := GetMessageHash(instance)
if err != nil {
return reqID, fmt.Errorf("failed to get reqID: %w", err)
}
copy(reqID[:], instanceHash[:])
copy(reqID[:12], id[:12])
copy(reqID[12:24], instanceHash[:12])
return reqID, nil
}

Expand Down

0 comments on commit abbc1fa

Please sign in to comment.