Esempio n. 1
0
func ValidateVote(ballotKey *rsa.PublicKey, m *msgs.Vote) error {
	ballot := m.Ballot
	sig := m.BallotSignature
	if !sign.CheckBlindSig(ballotKey, ballot, sig) {
		return fmt.Errorf("Vote's BallotSignature Signature is invalid")
	}
	return nil
}
Esempio n. 2
0
// Get signature for the ballot from ballot server
func GetBallotSig(voterKey *rsa.PrivateKey, keySig, ballot []byte) ([]byte, error) {

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

	var r msgs.SignatureRequest

	// TODO real values
	r.VoterPublicKey = keys.PackKey(&voterKey.PublicKey)

	blindedBallot, unblinder := sign.Blind(ballotKey, ballot)
	r.BlindedBallot = blindedBallot
	r.KeySignature = keySig
	voterSignature, err := sign.Sign(voterKey, blindedBallot)
	if err != nil {
		fmt.Println(err)
		panic(err)
	}
	r.VoterSignature = voterSignature
	data, err := proto.Marshal(&r)
	if err != nil {
		panic(err)
	}
	err = msg.WriteBlock(conn, msg.SignatureRequest, data)
	if err != nil {
		panic(err)
	}
	t, err := msg.ReadType(conn)
	if err != nil {
		panic(err)
	}
	if t != msg.SignatureResponse {
		return nil, fmt.Errorf("SignatureResponse: invalid response type %d. Expected: %d", t, msg.SignatureResponse)
	}
	data, err = msg.ReadBlock(conn, maxLength)
	conn.Close()
	if err != nil {
		panic(err)
	}
	var response msgs.SignatureResponse
	err = proto.Unmarshal(data, &response)
	if err != nil {
		fmt.Println("error reading SignatureResponse:", err)
		panic(err)
	}

	if !KeysEqual(r.VoterPublicKey, response.Request.VoterPublicKey) {
		fmt.Println("illegal response from server. Voter keys must match:")
		fmt.Println(r.VoterPublicKey)
		fmt.Println(response.Request.VoterPublicKey)
		panic(err)
	}

	err = msg.ValidateSignatureRequest(response.Request)
	if err != nil {
		panic(err)
	}

	newBlindedBallot := response.Request.BlindedBallot

	if !bytes.Equal(r.BlindedBallot, newBlindedBallot) {
		fmt.Println("Server has proof you voted before!")
		// TODO should store ballots (and blinding factors?) from all attempts
		// so can try and cast old ballot
		panic(err)
	}

	if !sign.CheckBlindSig(ballotKey, newBlindedBallot, response.BlindedBallotSignature) {
		fmt.Println("illegal response from server. Signature in response is invalid:", ballotKey, newBlindedBallot, response.BlindedBallotSignature)
		panic(err)
	}

	sig := sign.Unblind(ballotKey, response.BlindedBallotSignature, unblinder)

	return sig, nil
}