Exemplo n.º 1
0
func (e *ServerFault) UpdateState(state interfaces.IState) error {
	core, err := e.MarshalCore()
	if err != nil {
		return err
	}

	verifiedSignatures := 0
	for _, fullSig := range e.SignatureList.List {
		sig := fullSig.GetSignature()
		v, err := state.VerifyAuthoritySignature(core, sig, state.GetLeaderHeight())
		if err != nil {
			if err.Error() != "Signature Key Invalid or not Federated Server Key" {
				return err
			}
		}
		if v == 1 {
			verifiedSignatures++
		}
	}

	feds := state.GetFedServers(state.GetLeaderHeight())

	//50% threshold
	if verifiedSignatures <= len(feds)/2 {
		return fmt.Errorf("Quorum not reached for ServerFault")
	}

	//TODO: do
	/*
		state.AddFedServer(e.DBHeight, e.IdentityChainID)
		state.UpdateAuthorityFromABEntry(e)
	*/
	return nil
}
Exemplo n.º 2
0
// Validate the message, given the state.  Three possible results:
//  < 0 -- Message is invalid.  Discard
//  0   -- Cannot tell if message is Valid
//  1   -- Message is valid
func (m *Ack) Validate(state interfaces.IState) int {

	if m.authvalid {
		return 1
	}

	// Only new acks are valid. Of course, the VMIndex has to be valid too.
	msg, err := state.GetMsg(m.VMIndex, int(m.DBHeight), int(m.Height))
	if err != nil || msg != nil {
		return -1
	}

	// Check signature
	bytes, err := m.MarshalForSignature()
	if err != nil {
		//fmt.Println("Err is not nil on Ack sig check: ", err)
		return -1
	}
	sig := m.Signature.GetSignature()
	ackSigned, err := state.VerifyAuthoritySignature(bytes, sig, m.DBHeight)

	//ackSigned, err := m.VerifySignature()
	if err != nil {
		//fmt.Println("Err is not nil on Ack sig check: ", err)
		return -1
	}
	if ackSigned < 1 {
		return -1
	}
	m.authvalid = true
	return 1
}
Exemplo n.º 3
0
func (m *FullServerFault) SigTally(state interfaces.IState) int {
	validSigCount := 0
	// Check main signature
	bytes, err := m.MarshalForSignature()
	if err != nil {
		return 0
	}
	sig := m.Signature.GetSignature()
	sfSigned, err := state.VerifyAuthoritySignature(bytes, sig, m.DBHeight)
	if err != nil {
		return 0
	}
	if sfSigned < 1 {
		return 0
	}
	cb, err := m.MarshalCore()
	if err != nil {
		return 0
	}
	for _, fedSig := range m.SignatureList.List {
		check, err := state.VerifyAuthoritySignature(cb, fedSig.GetSignature(), m.DBHeight)
		if err == nil && check == 1 {
			validSigCount++
		}
	}
	return validSigCount
}
Exemplo n.º 4
0
func (m *ChangeServerKeyMsg) Validate(state interfaces.IState) int {
	return 1
	// Check to see if identity exists and is audit or fed server
	if !state.VerifyIsAuthority(m.IdentityChainID) {
		fmt.Println("ChangeServerKey Error. Server is not an authority")
		return -1
	}

	// Should only be 20 bytes in the hash
	if m.AdminBlockChange == constants.TYPE_ADD_BTC_ANCHOR_KEY {
		for _, b := range m.Key.Bytes()[21:] {
			if b != 0 {
				fmt.Println("ChangeServerKey Error. Newkey is invalid length")
				return -1
			}
		}
	}

	// Check signatures
	bytes, err := m.MarshalForSignature()
	if err != nil {
		fmt.Println("ChangeServerKey Error: Err is not nil, err: ", err.Error())
		return -1
	}
	if m.Signature == nil {
		fmt.Println("ChangeServerKey Error: No signiture on ChangeServerKeyMessage")
		return -1
	}
	sig := m.Signature.GetSignature()
	authSigned, err := state.VerifyAuthoritySignature(bytes, sig, state.GetLeaderHeight())

	//ackSigned, err := m.VerifySignature()
	if err != nil {
		fmt.Println("ChangeServerKey Error: Err is not nil, err: ", err.Error())
		return -1
	}
	if authSigned < 1 {
		fmt.Println("ChangeServerKey Error: Message not signed by an authority")
		return -1
	}
	return 1
}