func (jv *JVSS) finaliseSecret(sid SID) error { secret, err := jv.secrets.secret(sid) if err != nil { return err } log.Lvlf4("Node %d: %s deals %d/%d", jv.Index(), sid, len(secret.deals), len(jv.List())) if len(secret.deals) == jv.info.T { for _, deal := range secret.deals { if _, err := secret.receiver.AddDeal(jv.Index(), deal); err != nil { log.Error(jv.Index(), err) return err } } sec, err := secret.receiver.ProduceSharedSecret() if err != nil { return err } secret.secret = sec isShortTermSecret := strings.HasPrefix(string(sid), string(STSS)) if isShortTermSecret { secret.nShortConfirmsMtx.Lock() defer secret.nShortConfirmsMtx.Unlock() secret.numShortConfs++ } else { secret.nLongConfirmsMtx.Lock() defer secret.nLongConfirmsMtx.Unlock() secret.numLongtermConfs++ } log.Lvlf4("Node %d: %v created", jv.Index(), sid) // Initialise Schnorr struct for long-term shared secret if not done so before if sid.IsLTSS() && !jv.ltssInit { jv.ltssInit = true jv.schnorr.Init(jv.keyPair.Suite, jv.info, secret.secret) log.Lvlf4("Node %d: %v Schnorr struct initialised", jv.Index(), sid) } // Broadcast that we have finished setting up our shared secret msg := &SecConfMsg{ Src: jv.Index(), SID: sid, } if err := jv.Broadcast(msg); err != nil { log.Error(err) return err } } return nil }
func (jv *JVSS) handleSigResp(m WSigRespMsg) error { msg := m.SigRespMsg // Collect partial signatures secret, err := jv.secrets.secret(msg.SID) if err != nil { return err } secret.sigs[msg.Src] = msg.Sig log.Lvlf4("Node %d: %s signatures %d/%d", jv.Index(), msg.SID, len(secret.sigs), len(jv.List())) // Create Schnorr signature once we received enough partial signatures if jv.info.T == len(secret.sigs) { for _, sig := range secret.sigs { if err := jv.schnorr.AddPartialSig(sig); err != nil { return err } } sig, err := jv.schnorr.Sig() if err != nil { return err } jv.sigChan <- sig // Cleanup short-term shared secret jv.secrets.remove(msg.SID) } return nil }
// propagateSkipBlock saves a new skipblock to the identity func (s *Service) propagateSkipBlockHandler(msg network.Body) { log.Lvlf4("Got msg %+v %v", msg, reflect.TypeOf(msg).String()) usb, ok := msg.(*UpdateSkipBlock) if !ok { log.Error("Wrong message-type") return } sid := s.getIdentityStorage(usb.ID) if sid == nil { log.Error("Didn't find entity in", s) return } sid.Lock() defer sid.Unlock() skipblock := msg.(*UpdateSkipBlock).Latest _, msgLatest, err := network.UnmarshalRegistered(skipblock.Data) if err != nil { log.Error(err) return } al, ok := msgLatest.(*Config) if !ok { log.Error(err) return } sid.Data = skipblock sid.Latest = al sid.Proposed = nil }
// propagateConfig handles propagation of all configuration-proposals in the identity-service. func (s *Service) propagateConfigHandler(msg network.Body) { log.Lvlf4("Got msg %+v %v", msg, reflect.TypeOf(msg).String()) id := ID(nil) switch msg.(type) { case *ProposeSend: id = msg.(*ProposeSend).ID case *ProposeVote: id = msg.(*ProposeVote).ID default: log.Errorf("Got an unidentified propagation-request: %v", msg) return } if id != nil { sid := s.getIdentityStorage(id) if sid == nil { log.Error("Didn't find entity in", s) return } sid.Lock() defer sid.Unlock() switch msg.(type) { case *ProposeSend: p := msg.(*ProposeSend) sid.Proposed = p.Config sid.Votes = make(map[string]*crypto.SchnorrSig) case *ProposeVote: v := msg.(*ProposeVote) sid.Votes[v.Signer] = v.Signature } } }
func (jv *JVSS) initSecret(sid SID) error { if sid.IsLTSS() && jv.ltssInit { return errors.New("Only one longterm secret allowed per JVSS instance") } // Initialise shared secret of given type if necessary if sec, err := jv.secrets.secret(sid); sec == nil && err != nil { log.Lvlf4("Node %d: Initialising %s shared secret", jv.Index(), sid) sec := &secret{ receiver: poly.NewReceiver(jv.keyPair.Suite, jv.info, jv.keyPair), deals: make(map[int]*poly.Deal), sigs: make(map[int]*poly.SchnorrPartialSig), numLongtermConfs: 0, } jv.secrets.addSecret(sid, sec) } secret, err := jv.secrets.secret(sid) if err != nil { // this should never happen here log.Error(err) return err } // Initialise and broadcast our deal if necessary if len(secret.deals) == 0 { kp := config.NewKeyPair(jv.keyPair.Suite) deal := new(poly.Deal).ConstructDeal(kp, jv.keyPair, jv.info.T, jv.info.R, jv.pubKeys) log.Lvlf4("Node %d: Initialising %v deal", jv.Index(), sid) secret.deals[jv.Index()] = deal db, _ := deal.MarshalBinary() msg := &SecInitMsg{ Src: jv.Index(), SID: sid, Deal: db, } if err := jv.Broadcast(msg); err != nil { log.Print(jv.Name(), "Error broadcast secInit:", err) return err } } return nil }
// propagateIdentity stores a new identity in all nodes. func (s *Service) propagateIdentityHandler(msg network.Body) { log.Lvlf4("Got msg %+v %v", msg, reflect.TypeOf(msg).String()) pi, ok := msg.(*PropagateIdentity) if !ok { log.Error("Got a wrong message for propagation") return } id := ID(pi.Data.Hash) if s.getIdentityStorage(id) != nil { log.Error("Couldn't store new identity") return } log.Lvl3("Storing identity in", s) s.setIdentityStorage(id, pi.Storage) return }
// bftVerify takes a message and verifies it's valid func (s *Service) bftVerify(msg []byte, data []byte) bool { log.Lvlf4("%s verifying block %x", s.ServerIdentity(), msg) s.testVerify = true _, sbN, err := network.UnmarshalRegistered(data) if err != nil { log.Error("Couldn't unmarshal SkipBlock", data) return false } sb := sbN.(*SkipBlock) if !sb.Hash.Equal(SkipBlockID(msg)) { log.Lvlf2("Data skipBlock different from msg %x %x", msg, sb.Hash) return false } f, ok := s.verifiers[sb.VerifierID] if !ok { log.Lvlf2("Found no user verification for %x", sb.VerifierID) return false } return f(msg, sb) }