ignoring election params. dat files. Audit ballot QRcode.

voting-booth-gui
Laura Radaelli 2017-07-17 13:37:39 +03:00
parent dadf301fcf
commit ce2fe0e8f2
4 changed files with 64 additions and 24 deletions

2
.gitignore vendored
View File

@ -36,3 +36,5 @@ testem.log
bundle.js
bundle.d.ts
/voting-booth-gui/meerkat_election_params_tempfile.dat
/voting-booth-gui/meerkat_booth_system_messages.dat

View File

@ -83,6 +83,11 @@ message BallotSecrets {
RandomnessGenerationProof proof = 3;
}
message SignedBallotSecrets {
BallotSecrets ballot_secrets = 1;
Signature signature = 2;
}
message BoothParams {
repeated SignatureVerificationKey pscVerificationKeys = 1;

View File

@ -6,11 +6,9 @@ import com.google.zxing.WriterException;
import meerkat.protobuf.Crypto.EncryptionRandomness;
import meerkat.protobuf.Crypto.RandomnessGenerationProof;
import meerkat.protobuf.PollingStation;
import meerkat.protobuf.PollingStation.ScannedData;
import meerkat.protobuf.Voting;
import meerkat.protobuf.Voting.BallotSecrets;
import meerkat.protobuf.Voting.PlaintextBallot;
import meerkat.protobuf.Voting.SignedEncryptedBallot;
import meerkat.rest.Constants;
import meerkat.voting.gui.controllersFX.VistaNavigator;
import meerkat.voting.output.AsyncRunnableOutputDevice;
import meerkat.voting.output.outputcommands.AuditOutputCommand;
@ -20,7 +18,6 @@ import meerkat.voting.output.outputcommands.CommitOutputCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.client.Entity;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Base64;
@ -49,7 +46,7 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice {
ByteString channel = command.getChannelIdentifierByteString();
printPlainText(plaintextBallot, channel);
printEncryptedText(plaintextBallot, command);
printCommitBallot(plaintextBallot, command);
}
@ -61,11 +58,10 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice {
public void doAudit(AuditOutputCommand command) {
logger.debug("entered method doAudit");
VistaNavigator.printFXSeparator();
String msg = "Auditing";
VistaNavigator.printFX(msg);
BallotSecrets ballotSecrets = command.getBallotSecrets();
printEncryptionRandomness(ballotSecrets.getEncryptionRandomness());
printRandomnessGenerationProof (ballotSecrets.getProof());
printAuditBallot(ballotSecrets);
command.getCallback().onSuccess(null);
}
@ -106,19 +102,15 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice {
VistaNavigator.printFX(toPrint);
}
private void printEncryptedText(PlaintextBallot plaintextBallot, CommitOutputCommand command) {
String encryptedText;
SignedEncryptedBallot signedEncryptedBallot = command.getSignedEncryptedBallot();
long encryptedSerialNumber = signedEncryptedBallot.getEncryptedBallot().getSerialNumber();
long plaintextSerialNumber = plaintextBallot.getSerialNumber();
private void printCommitBallot(PlaintextBallot plaintextBallot, CommitOutputCommand command) {
String toPrint = "";
toPrint+="Commitment of Ballot #" + encryptedSerialNumber + " (ciphertext):";
toPrint+="Commitment of Ballot #" + command.getSignedEncryptedBallot().getEncryptedBallot().getSerialNumber() + " (ciphertext):";
toPrint+="\n";
VistaNavigator.printFX(toPrint);
if (plaintextSerialNumber != encryptedSerialNumber) {
if (plaintextBallot.getSerialNumber() != command.getSignedEncryptedBallot().getEncryptedBallot().getSerialNumber()) {
logger.error("plaintext and encryption serial numbers do not match!! plaintext# = " +
plaintextSerialNumber + ", ciphertext# = " + encryptedSerialNumber);
plaintextBallot.getSerialNumber() + ", ciphertext# = " + command.getSignedEncryptedBallot().getEncryptedBallot().getSerialNumber());
}
PollingStation.ScannedBallot scannedBallot = PollingStation.ScannedBallot.newBuilder()
@ -126,15 +118,15 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice {
.setSignedEncryptedBallot(command.getSignedEncryptedBallot())
.build();
System.out.println(scannedBallot.getSerializedSize());
encryptedText = Base64.getEncoder().encodeToString(scannedBallot.toByteArray());
logger.info("ScannedBallot serialized size: "+scannedBallot.getSerializedSize());
String encryptedText = Base64.getEncoder().encodeToString(scannedBallot.toByteArray());
try {
PollingStation.ScannedBallot result = PollingStation.ScannedBallot.parseFrom(Base64.getDecoder().decode(encryptedText.getBytes()));
System.out.println(result.getChannel());
System.out.println(command.getChannelIdentifierByteString());
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
command.getCallback().onFailure(e);
}
try {
@ -148,10 +140,41 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice {
}
private void printQRCode(String toQRCode, int size) throws IOException, WriterException {
BufferedImage image = null;
image = GenerateQRCode.createQRImage(toQRCode, size);
VistaNavigator.printFX(image);
private void printAuditBallot(BallotSecrets ballotSecrets) {
String toPrint = "";
toPrint+="Audit of Ballot";// + command.getSignedEncryptedBallot().getEncryptedBallot().getSerialNumber() + " (ciphertext):";
toPrint+="\n";
VistaNavigator.printFX(toPrint);
//generate the PollingStation.<protobuf> corresponding to [plaintext, randomness, Signed(plaintext, randomness)]
// PollingStation.ScannedBallot scannedBallot = PollingStation.ScannedBallot.newBuilder()
// .setChannel(command.getChannelIdentifierByteString())
// .setSignedEncryptedBallot(command.getSignedEncryptedBallot())
// .build();
//encode to String
// logger.info("ScannedAudit serialized size: "+scannedBallot.getSerializedSize());
// String auditText = Base64.getEncoder().encodeToString(scannedBallot.toByteArray());
//check that decoding encoded gives same as original
// try {
// PollingStation.ScannedBallot result = PollingStation.ScannedBallot.parseFrom(Base64.getDecoder().decode(auditText.getBytes()));
// System.out.println(result.getChannel());
// System.out.println(command.getChannelIdentifierByteString());
// } catch (InvalidProtocolBufferException e) {
// command.getCallback().onFailure(e);
// }
//print to FX
// try {
// printQRCode(auditText, 250);
// command.getCallback().onSuccess(null);
// } catch (IOException e) {
// command.getCallback().onFailure(e);
// } catch (WriterException e) {
// command.getCallback().onFailure(e);
// }
}
private void printEncryptionRandomness (EncryptionRandomness encryptionRandomness) {
@ -168,6 +191,16 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice {
VistaNavigator.printFX(msg);
}
/**
* Creates an image of the QRcode with the String toQRCode in it and displays it to the virtual printer (FX window)
* @param toQRCode a String that contains the text to encode into the QRcode
* @param size the size of the QRcode (we use 250 for testing)
*/
private void printQRCode(String toQRCode, int size) throws IOException, WriterException {
BufferedImage image = null;
image = GenerateQRCode.createQRImage(toQRCode, size);
VistaNavigator.printFX(image);
}
/*
* Returns the UTF8 decoding of byte-string data

View File

@ -40,5 +40,5 @@ public interface VBCryptoManager {
// TODO: do we seed the random here?
public EncryptionAndSecrets encrypt (PlaintextBallot plaintextBallot) throws SignatureException, IOException;
//TODO: Laura: there should be a method here to sign whatever I need to sign, no? Does it mean that I need to create a class for each type of thing I need to sign?
}