func TestAuthoritySignature(t *testing.T) { s := testHelper.CreateAndPopulateTestState() idindex := s.CreateBlankFactomIdentity(primitives.NewZeroHash()) s.Identities[idindex].ManagementChainID = primitives.NewZeroHash() index := s.AddAuthorityFromChainID(primitives.NewZeroHash()) s.Authorities[index].SigningKey = *(s.GetServerPublicKey()) s.Authorities[index].Status = 1 ack := new(messages.Ack) ack.DBHeight = s.LLeaderHeight ack.VMIndex = 1 ack.Minute = byte(5) ack.Timestamp = s.GetTimestamp() ack.MessageHash = primitives.NewZeroHash() ack.LeaderChainID = s.IdentityChainID ack.SerialHash = primitives.NewZeroHash() err := ack.Sign(s) if err != nil { t.Error("Authority Test Failed when signing message") } msg, err := ack.MarshalForSignature() if err != nil { t.Error("Authority Test Failed when marshalling for sig") } sig := ack.GetSignature() server, err := s.Authorities[0].VerifySignature(msg, sig.GetSignature()) if !server || err != nil { t.Error("Authority Test Failed when checking sigs") } }
// Create a new Acknowledgement. Must be called by a leader. This // call assumes all the pieces are in place to create a new acknowledgement func (s *State) NewAck(msg interfaces.IMsg) interfaces.IMsg { vmIndex := msg.GetVMIndex() msg.SetLeaderChainID(s.IdentityChainID) ack := new(messages.Ack) ack.DBHeight = s.LLeaderHeight ack.VMIndex = vmIndex ack.Minute = byte(s.ProcessLists.Get(s.LLeaderHeight).VMs[vmIndex].LeaderMinute) ack.Timestamp = s.GetTimestamp() ack.SaltNumber = s.GetSalt(ack.Timestamp) copy(ack.Salt[:8], s.Salt.Bytes()[:8]) ack.MessageHash = msg.GetMsgHash() ack.LeaderChainID = s.IdentityChainID listlen := len(s.LeaderPL.VMs[vmIndex].List) if listlen == 0 { ack.Height = 0 ack.SerialHash = ack.MessageHash } else { last := s.LeaderPL.GetAckAt(vmIndex, listlen-1) ack.Height = last.Height + 1 ack.SerialHash, _ = primitives.CreateHash(last.MessageHash, ack.MessageHash) } ack.Sign(s) return ack }