QR code for cast (missing QR code for audit) + test interaction polling station
parent
6350da1fc2
commit
db4cf6a734
|
@ -0,0 +1,88 @@
|
|||
package meerkat.voting.gui;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import meerkat.pollingstation.PollingStationScanner;
|
||||
import meerkat.pollingstation.PollingStationWebScanner;
|
||||
import meerkat.protobuf.PollingStation;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
* Created by Laura on 2/1/2017.
|
||||
*/
|
||||
public class PollingStationServerToyRun {
|
||||
|
||||
private PollingStationScanner.Consumer scanner;
|
||||
private static final String ADDRESS = "http://localhost";
|
||||
private static final String SUB_ADDRESS = "";
|
||||
private static final int PORT = 8080;
|
||||
|
||||
private Semaphore semaphore;
|
||||
private Throwable thrown;
|
||||
private boolean dataIsAsExpected;
|
||||
|
||||
private class ScanHandler implements FutureCallback<PollingStation.ScannedData> {
|
||||
|
||||
private final PollingStation.ScannedData expectedData;
|
||||
|
||||
public ScanHandler(PollingStation.ScannedData expectedData) {
|
||||
this.expectedData = expectedData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(PollingStation.ScannedData result) {
|
||||
dataIsAsExpected = result.getChannel().equals(expectedData.getChannel());
|
||||
semaphore.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
dataIsAsExpected = false;
|
||||
thrown = t;
|
||||
semaphore.release();
|
||||
}
|
||||
}
|
||||
|
||||
private class ErrorHandler implements FutureCallback<PollingStation.ScannedData> {
|
||||
|
||||
private final String expectedErrorMessage;
|
||||
|
||||
public ErrorHandler(String expectedErrorMessage) {
|
||||
this.expectedErrorMessage = expectedErrorMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(PollingStation.ScannedData result) {
|
||||
dataIsAsExpected = false;
|
||||
semaphore.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
dataIsAsExpected = t.getMessage().equals(expectedErrorMessage);
|
||||
semaphore.release();
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
System.err.println("Setting up Scanner WebApp!");
|
||||
|
||||
scanner = new PollingStationWebScanner(PORT, SUB_ADDRESS);
|
||||
|
||||
semaphore = new Semaphore(0);
|
||||
thrown = null;
|
||||
|
||||
try {
|
||||
scanner.start();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Could not start server: " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String [] args) {
|
||||
PollingStationServerToyRun run = new PollingStationServerToyRun();
|
||||
run.init();
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import meerkat.voting.encryptor.VBCryptoManager;
|
|||
import meerkat.voting.encryptor.VBCryptoManagerImpl;
|
||||
import meerkat.voting.gui.uiFX.GraphicalUI;
|
||||
import meerkat.voting.gui.output.FXWindowOutputDevice;
|
||||
import meerkat.voting.output.NetworkVirtualPrinter;
|
||||
import meerkat.voting.storage.StorageManager;
|
||||
import meerkat.voting.storage.StorageManagerMockup;
|
||||
|
||||
|
@ -44,6 +45,7 @@ public class VotingBoothToyGraphicalRun {
|
|||
|
||||
StorageManager storageManager = new StorageManagerMockup();
|
||||
FXWindowOutputDevice outputDevice = new FXWindowOutputDevice();
|
||||
// NetworkVirtualPrinter outputDevice = new NetworkVirtualPrinter("http://localhost:8080");
|
||||
VBCryptoManager cryptoManager = new VBCryptoManagerImpl(rand, enc, sig);
|
||||
// SystemConsoleUI ui = new SystemConsoleUI ();
|
||||
GraphicalUI ui = new GraphicalUI();
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package meerkat.voting.gui.output;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
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.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;
|
||||
|
@ -16,8 +20,10 @@ 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;
|
||||
|
||||
/**
|
||||
* A toy OutputDevice class
|
||||
|
@ -113,8 +119,22 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice {
|
|||
logger.error("plaintext and encryption serial numbers do not match!! plaintext# = " +
|
||||
plaintextSerialNumber + ", ciphertext# = " + encryptedSerialNumber);
|
||||
}
|
||||
ByteString encryptedData = signedEncryptedBallot.getEncryptedBallot().getData().getData();
|
||||
encryptedText = encryptedSerialNumber+"|"+bytesToString(encryptedData);
|
||||
|
||||
ScannedData scannedData = ScannedData.newBuilder()
|
||||
.setChannel(command.getChannelIdentifierByteString())
|
||||
.setSignedEncryptedBallot(command.getSignedEncryptedBallot())
|
||||
.build();
|
||||
|
||||
System.out.println(scannedData.getSerializedSize());
|
||||
encryptedText = Base64.getEncoder().encodeToString(scannedData.toByteArray());
|
||||
|
||||
try {
|
||||
ScannedData result = ScannedData.parseFrom(Base64.getDecoder().decode(encryptedText.getBytes()));
|
||||
System.out.println(result.getChannel());
|
||||
System.out.println(command.getChannelIdentifierByteString());
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
printQRCode(encryptedText, 250);
|
||||
|
|
|
@ -336,6 +336,7 @@ public class GraphicalUI implements VotingBoothUI, Runnable {
|
|||
cmdPend.trample(new FatalErrorUICommand(errorMessage, buttonLabels, (ControllerCallback<Integer>)callback));
|
||||
}
|
||||
|
||||
// TODO: make javafx interface for handling fatal error
|
||||
/**
|
||||
* show an error to the voter. let him press a (chosen) button for handling the error.
|
||||
* @param command a FatalErrorUICommand with the callback
|
||||
|
|
Loading…
Reference in New Issue