diff --git a/android-scanner/src/main/java/com/meerkat/laura/fakescannerapp/MainActivity.java b/android-scanner/src/main/java/com/meerkat/laura/fakescannerapp/MainActivity.java index 9b64de7..e882fda 100644 --- a/android-scanner/src/main/java/com/meerkat/laura/fakescannerapp/MainActivity.java +++ b/android-scanner/src/main/java/com/meerkat/laura/fakescannerapp/MainActivity.java @@ -18,23 +18,26 @@ import android.widget.Toast; import com.google.protobuf.InvalidProtocolBufferException; import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult; +import meerkat.crypto.DigitalSignatureGenerator; +import meerkat.crypto.concrete.ECDSADeterministicSignature; +import meerkat.pollingstation.PollingStationScanner; import meerkat.pollingstation.ScannerClientAPI; import meerkat.protobuf.PollingStation; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.net.URLDecoder; +import java.math.BigInteger; +import java.util.Date; import static com.meerkat.laura.fakescannerapp.R.xml.preferences; public class MainActivity extends AppCompatActivity implements View.OnClickListener { + final public static String SCANNER_NAME = "AndroidScanner"; SharedPreferences sharedPref; Button scanBtn; TextView formatTxt, contentTxt, responseTxt; - ScannerClientAPI scannerClientAPI; + PollingStationScanner.ScannerClient scannerClient; + DigitalSignatureGenerator signer; @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -58,7 +61,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe void setNewScannerClientAPI(SharedPreferences sharedPref) { String pscUrlString = sharedPref.getString(SettingsActivity.PSC_URL, ""); - scannerClientAPI = new ScannerClientAPI(pscUrlString); + + scannerClient = new ScannerClientAPI(signer); } @Override @@ -80,6 +84,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe contentTxt = (TextView)findViewById(R.id.scan_content); responseTxt = (TextView)findViewById(R.id.server_response); + + signer = new ECDSADeterministicSignature(); + signer.generateSigningCertificate(BigInteger.ONE, new Date(System.currentTimeMillis()), + new Date(System.currentTimeMillis() + 1000*60*60*24*365), SCANNER_NAME); + setNewScannerClientAPI(sharedPref); scanBtn.setOnClickListener(this); } @@ -113,13 +122,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe public void sendPost(String scanContent) { try { - PollingStation.ScannedData scannedData = PollingStation.ScannedData.parseFrom(Base64.decode(scanContent.getBytes(), Base64.DEFAULT)); + PollingStation.ScannedBallot scannedBallot = PollingStation.ScannedBallot.parseFrom(Base64.decode(scanContent.getBytes(), Base64.DEFAULT)); // // PollingStation.ScannedData scannedData = PollingStation.ScannedData.newBuilder() // .setChannel(ByteString.copyFrom(body)) // .build(); - if (scannerClientAPI.sendScan(scannedData)) { + if (scannerClient.newScan(scannedBallot)) { Log.i("MainActivity", "post submitted to API."); } else { Log.e("MainActivity", "Unable to submit post to API."); diff --git a/scanner-api-common/build.gradle b/scanner-api-common/build.gradle index 1845939..70701b1 100644 --- a/scanner-api-common/build.gradle +++ b/scanner-api-common/build.gradle @@ -27,15 +27,10 @@ ext { isSnapshot = false } ext { groupId = 'org.factcenter.meerkat' - nexusRepository = "https://cs.idc.ac.il/nexus/content/groups/${isSnapshot ? 'unstable' : 'public'}/" - - // Credentials for IDC nexus repositories (needed only for using unstable repositories and publishing) - // Should be set in ${HOME}/.gradle/gradle.properties - - // Credentials for publishing repositories - publishRepository = "https://cs.idc.ac.il/nexus/content/repositories/${project.isSnapshot ? 'snapshots' : 'releases'}" - publishUser = project.hasProperty('publishUser') ? project.property('publishUser') : "" - publishPassword = project.hasProperty('publishPassword') ? project.property('publishPassword') : "" + // Credentials for publishing repositories + publishRepository = "https://cs.idc.ac.il/nexus/content/repositories/${project.isSnapshot ? 'snapshots' : 'releases'}" + publishUser = project.hasProperty('publishUser') ? project.property('publishUser') : "" + publishPassword = project.hasProperty('publishPassword') ? project.property('publishPassword') : "" } description = "Common files for polling-station scanner client API" @@ -218,8 +213,8 @@ publishing { repositories { maven { url publishRepository - credentials { username - password + credentials { username + password username publishUser password publishPassword @@ -230,3 +225,4 @@ publishing { + diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/PollingStationServerToyRun.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/PollingStationServerToyRun.java index 4f45faa..a02fc4f 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/PollingStationServerToyRun.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/PollingStationServerToyRun.java @@ -1,84 +1,49 @@ package meerkat.voting.gui; import com.google.common.util.concurrent.FutureCallback; +import meerkat.crypto.DigitalSignature; +import meerkat.crypto.concrete.ECDSADeterministicSignature; import meerkat.pollingstation.PollingStationScanner; import meerkat.pollingstation.PollingStationWebScanner; import meerkat.protobuf.PollingStation; - -import java.util.concurrent.Semaphore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Created by Laura on 2/1/2017. */ public class PollingStationServerToyRun { + final Logger logger = LoggerFactory.getLogger(getClass()); + private static final String SCAN_CONTEXT_PATH = "/scan"; - private PollingStationScanner.PollingStationServer 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 { - - 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 { - - 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(); - } - } + private PollingStationScanner.PollingStationServer scannerServer; + PollingStation.ConnectionServerData serverData; + DigitalSignature verifier; public void init() { - System.err.println("Setting up Scanner WebApp!"); + verifier = new ECDSADeterministicSignature(); - scanner = new PollingStationWebScanner(PORT, SUB_ADDRESS); + logger.debug("Setting up Scanner WebApp!"); - semaphore = new Semaphore(0); - thrown = null; + scannerServer = new PollingStationWebScanner(0, SCAN_CONTEXT_PATH); + + scannerServer.subscribe(new FutureCallback() { + @Override + public void onSuccess(PollingStation.ScannedData result) { + logger.info("Received scan #{}", result.getSerial()); + } + + @Override + public void onFailure(Throwable t) { } + }); try { - scanner.start(); + serverData = scannerServer.start(false); + logger.info("Scanner server started at {}", serverData.getServerUrl()); } catch (Exception e) { - System.out.println("Could not start server: " + e.getMessage()); + logger.error("Could not start server: " + e.getMessage()); } - } public static void main(String [] args) { diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/output/FXWindowOutputDevice.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/output/FXWindowOutputDevice.java index 429e602..21da53a 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/output/FXWindowOutputDevice.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/output/FXWindowOutputDevice.java @@ -120,16 +120,16 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice { plaintextSerialNumber + ", ciphertext# = " + encryptedSerialNumber); } - ScannedData scannedData = ScannedData.newBuilder() + PollingStation.ScannedBallot scannedBallot = PollingStation.ScannedBallot.newBuilder() .setChannel(command.getChannelIdentifierByteString()) .setSignedEncryptedBallot(command.getSignedEncryptedBallot()) .build(); - System.out.println(scannedData.getSerializedSize()); - encryptedText = Base64.getEncoder().encodeToString(scannedData.toByteArray()); + System.out.println(scannedBallot.getSerializedSize()); + encryptedText = Base64.getEncoder().encodeToString(scannedBallot.toByteArray()); try { - ScannedData result = ScannedData.parseFrom(Base64.getDecoder().decode(encryptedText.getBytes())); + PollingStation.ScannedBallot result = PollingStation.ScannedBallot.parseFrom(Base64.getDecoder().decode(encryptedText.getBytes())); System.out.println(result.getChannel()); System.out.println(command.getChannelIdentifierByteString()); } catch (InvalidProtocolBufferException e) {