Exemple #1
0
func HandelSignatureRequest(data []byte, c net.Conn) {
	var r msgs.SignatureRequest
	err := proto.Unmarshal(data, &r)
	if err != nil {
		fmt.Println("server error reading SignatureRequest:", err)
		server.ConnectionError(c)
		return
	}

	err = msg.ValidateSignatureRequest(&r)
	if err != nil {
		fmt.Println(err)
		return
	}

	keyString := keys.StringKey(r.VoterPublicKey)

	if !sign.CheckSig(voterListKey, []byte(keyString), r.KeySignature) {
		fmt.Println("SignatureRequest's KeySignature Signature is invalid")
		server.ConnectionError(c)
		return
	}

	responseData := getResponse(keyString, &r)

	server.SendBlock(msg.SignatureResponse, responseData, c)
}
Exemple #2
0
// Does not check keySignature
func ValidateSignatureRequest(m *msgs.SignatureRequest) error {
	newBlindedBallot := m.BlindedBallot
	newSig := m.VoterSignature
	key := keys.UnpackKey(m.VoterPublicKey)
	if !sign.CheckSig(key, newBlindedBallot, newSig) {
		return fmt.Errorf("SignatureRequest's VoterSignature Signature is invalid")
	}
	return nil
}
Exemple #3
0
func SubmitBallot(ballot, sig []byte) (*msgs.VoteResponse, error) {

	fmt.Printf("Casting Ballot: %s\n", ballot)

	conn, err := net.Dial("tcp", "localhost"+msg.Service)
	if err != nil {
		return nil, err
	}

	var vote msgs.Vote
	vote.Ballot = ballot
	vote.BallotSignature = sig

	// redundant sanity check signature
	err = msg.ValidateVote(ballotKey, &vote)
	if err != nil {
		return nil, err
	}
	data, err := proto.Marshal(&vote)
	if err != nil {
		return nil, err
	}
	err = msg.WriteBlock(conn, msg.Vote, data)
	if err != nil {
		return nil, err
	}
	t, err := msg.ReadType(conn)
	if err != nil {
		return nil, err
	}
	if t != msg.VoteResponse {
		return nil, fmt.Errorf("invalid response type")
	}
	data, err = msg.ReadBlock(conn, maxLength)
	conn.Close()
	if err != nil {
		return nil, err
	}

	var response msgs.VoteResponse
	err = proto.Unmarshal(data, &response)
	if err != nil {
		fmt.Println("error reading VoteResponse:", err)
		return nil, err
	}

	b := response.BallotEntry
	s := response.BallotEntrySignature

	if !sign.CheckSig(voteKey, b, s) {
		err = fmt.Errorf("illegal vote response from server. Signature in BallotEntry is invalid")
		return nil, err
	}

	fmt.Printf("Got signed BallotEntry for: %s\n", ballot)
	return &response, nil
}
Exemple #4
0
func CheckKeySig(privateInfo *msgs.VoterData) SignatureStatus {
	if privateInfo.KeySignature == nil {
		return Missing
	}
	config := config.Unpack(privateInfo.ElectionConfig)
	voterListKey := keys.UnpackKey(config.VoterListServer.Key)
	publicKey := PublicKey(privateInfo)
	if sign.CheckSig(voterListKey, publicKey, privateInfo.KeySignature) {
		return Valid
	}
	return Invalid
}