diff --git a/src/main/java/Demo.java b/src/main/java/Demo.java index 879501f..3b8e857 100644 --- a/src/main/java/Demo.java +++ b/src/main/java/Demo.java @@ -1,11 +1,7 @@ import com.google.protobuf.ByteString; -import meerkat.bulletinboard.BulletinBoard; -import meerkat.comm.BulletinBoardMessageProtos; - +import static meerkat.protobuf.Voting.*; import java.io.IOException; -import static meerkat.comm.BulletinBoardMessageProtos.*; - /** * Created by talm on 10/26/15. */ @@ -15,7 +11,7 @@ public class Demo { BulletinBoardMessage msg; - BulletinBoardMessage.Unsigned msgContents = BulletinBoardMessage.Unsigned.newBuilder() + UnsignedBulletinBoardMessage msgContents = UnsignedBulletinBoardMessage.newBuilder() .addTags("test") .setData(ByteString.copyFromUtf8("some data")) .build(); diff --git a/src/main/java/meerkat/bulletinboard/BulletinBoard.java b/src/main/java/meerkat/bulletinboard/BulletinBoard.java index dfeb321..980c8e9 100644 --- a/src/main/java/meerkat/bulletinboard/BulletinBoard.java +++ b/src/main/java/meerkat/bulletinboard/BulletinBoard.java @@ -1,7 +1,7 @@ package meerkat.bulletinboard; import meerkat.comm.*; -import meerkat.crypto.Signature; +import static meerkat.protobuf.Voting.*; import java.util.List; import java.util.Set; @@ -13,10 +13,8 @@ public interface BulletinBoard { /** * Post a message to the bulletin board * @param msg - * @param sig */ - MessageID postMessage(Message msg, Signature sig) throws CommunicationException; - + MessageID postMessage(BulletinBoardMessage msg) throws CommunicationException; /** * Check how "safe" a given message is @@ -34,10 +32,10 @@ public interface BulletinBoard { * @param max maximum number of messages to return (0=no limit) * @return */ - List readMessages(MessageFilter filter, int max); + List readMessages(MessageFilter filter, int max); interface MessageCallback { - void handleNewMessage(Message msg, Signature sig); + void handleNewMessage(BulletinBoardMessage msg); } /** diff --git a/src/main/java/meerkat/comm/Message.java b/src/main/java/meerkat/comm/Message.java deleted file mode 100644 index 47c916d..0000000 --- a/src/main/java/meerkat/comm/Message.java +++ /dev/null @@ -1,12 +0,0 @@ -package meerkat.comm; - -import java.util.Set; - -/** - * Created by talm on 24/10/15. - * - * A structured message - */ -public interface Message { -} - diff --git a/src/main/java/meerkat/crypto/DigitalSignature.java b/src/main/java/meerkat/crypto/DigitalSignature.java index 3a86caf..691b492 100644 --- a/src/main/java/meerkat/crypto/DigitalSignature.java +++ b/src/main/java/meerkat/crypto/DigitalSignature.java @@ -1,8 +1,9 @@ package meerkat.crypto; -import meerkat.comm.Message; +import com.google.protobuf.Message; import java.util.List; +import static meerkat.protobuf.Crypto.*; /** * Created by talm on 25/10/15. @@ -10,7 +11,7 @@ import java.util.List; * Sign arrays of messages */ public interface DigitalSignature { // Extends SCAPI DigitalSignature - public Signature sign(List msgs); + public Signature sign(List msg); public boolean verify(Signature sig, List msgs); } diff --git a/src/main/java/meerkat/crypto/Encryption.java b/src/main/java/meerkat/crypto/Encryption.java new file mode 100644 index 0000000..a1a023b --- /dev/null +++ b/src/main/java/meerkat/crypto/Encryption.java @@ -0,0 +1,12 @@ +package meerkat.crypto; + +import com.google.protobuf.Message; +import static meerkat.protobuf.Crypto.*; + +/** + * Created by talm on 11/2/15. + */ +public interface Encryption { + Message encrypt(Message plaintext, EncryptionRandomness rnd); + +} diff --git a/src/main/java/meerkat/crypto/EncryptionRandomness.java b/src/main/java/meerkat/crypto/EncryptionRandomness.java deleted file mode 100644 index fa44730..0000000 --- a/src/main/java/meerkat/crypto/EncryptionRandomness.java +++ /dev/null @@ -1,7 +0,0 @@ -package meerkat.crypto; - -/** - * Created by talm on 10/26/15. - */ -public interface EncryptionRandomness { -} diff --git a/src/main/java/meerkat/crypto/RandomnessGenerationProof.java b/src/main/java/meerkat/crypto/RandomnessGenerationProof.java deleted file mode 100644 index cc17ecc..0000000 --- a/src/main/java/meerkat/crypto/RandomnessGenerationProof.java +++ /dev/null @@ -1,7 +0,0 @@ -package meerkat.crypto; - -/** - * Created by talm on 10/26/15. - */ -public class RandomnessGenerationProof { -} diff --git a/src/main/java/meerkat/crypto/Signature.java b/src/main/java/meerkat/crypto/Signature.java deleted file mode 100644 index 432e7cd..0000000 --- a/src/main/java/meerkat/crypto/Signature.java +++ /dev/null @@ -1,9 +0,0 @@ -package meerkat.crypto; - -/** - * Created by talm on 24/10/15. - * - * A digital signature - */ -public interface Signature { -} diff --git a/src/main/java/meerkat/crypto/mixnet/Mixer.java b/src/main/java/meerkat/crypto/mixnet/Mixer.java index f77d302..44b113b 100644 --- a/src/main/java/meerkat/crypto/mixnet/Mixer.java +++ b/src/main/java/meerkat/crypto/mixnet/Mixer.java @@ -1,6 +1,6 @@ package meerkat.crypto.mixnet; -import meerkat.comm.Message; +import meerkat.voting.EncryptedBallot; import java.util.List; @@ -8,5 +8,5 @@ import java.util.List; * Created by talm on 25/10/15. */ public interface Mixer { - public List mix(List ciphertexts); + public List mix(List ballots); } diff --git a/src/main/java/meerkat/voting/BallotSecrets.java b/src/main/java/meerkat/voting/BallotSecrets.java deleted file mode 100644 index 4bd8e41..0000000 --- a/src/main/java/meerkat/voting/BallotSecrets.java +++ /dev/null @@ -1,14 +0,0 @@ -package meerkat.voting; - -import meerkat.crypto.EncryptionRandomness; -import meerkat.crypto.RandomnessGenerationProof; - -/** - * Created by talm on 10/26/15. - */ -public class BallotSecrets { - PlaintextBallot plaintext; - - EncryptionRandomness encryptionRandomness; - RandomnessGenerationProof proof; -} diff --git a/src/main/java/meerkat/voting/BoothParams.java b/src/main/java/meerkat/voting/BoothParams.java deleted file mode 100644 index 28af6b5..0000000 --- a/src/main/java/meerkat/voting/BoothParams.java +++ /dev/null @@ -1,11 +0,0 @@ -package meerkat.voting; - -/** - * Parameters local to the voting booth: - * Private and public signature keys - * Logging keys, - * Randomness generation params - * etc. - */ -public class BoothParams { -} diff --git a/src/main/java/meerkat/voting/ElectionParams.java b/src/main/java/meerkat/voting/ElectionParams.java deleted file mode 100644 index 3c78d42..0000000 --- a/src/main/java/meerkat/voting/ElectionParams.java +++ /dev/null @@ -1,7 +0,0 @@ -package meerkat.voting; - -/** - * Created by talm on 25/10/15. - */ -public class ElectionParams { -} diff --git a/src/main/java/meerkat/voting/EncryptedBallot.java b/src/main/java/meerkat/voting/EncryptedBallot.java index aa7bd80..8f86128 100644 --- a/src/main/java/meerkat/voting/EncryptedBallot.java +++ b/src/main/java/meerkat/voting/EncryptedBallot.java @@ -1,6 +1,6 @@ package meerkat.voting; -import meerkat.comm.Message; +import com.google.protobuf.Message; /** * Created by talm on 25/10/15. diff --git a/src/main/java/meerkat/voting/EncryptedBallotWithSecrets.java b/src/main/java/meerkat/voting/EncryptedBallotWithSecrets.java deleted file mode 100644 index c38f52d..0000000 --- a/src/main/java/meerkat/voting/EncryptedBallotWithSecrets.java +++ /dev/null @@ -1,12 +0,0 @@ -package meerkat.voting; - -/** - * Created by talm on 10/26/15. - */ -public interface EncryptedBallotWithSecrets extends EncryptedBallot { - /** - * Return the secrets required to open and verify an encrypted ballot - * @return - */ - BallotSecrets getBallotSecrets(); -} diff --git a/src/main/java/meerkat/voting/PlaintextBallot.java b/src/main/java/meerkat/voting/PlaintextBallot.java deleted file mode 100644 index 2833d54..0000000 --- a/src/main/java/meerkat/voting/PlaintextBallot.java +++ /dev/null @@ -1,19 +0,0 @@ -package meerkat.voting; - -import java.util.List; - -/** - * Created by talm on 25/10/15. - */ -public class PlaintextBallot { - /** - * Answers to the ballot questions. - * Each answer is a list of integers; its parsing depends on the question type. - * For example, a multiple choice question would have a length-1 list containing - * the single choice's index. - */ - List> answers; - - long serialNumber; - -} diff --git a/src/main/java/meerkat/voting/VotingBooth.java b/src/main/java/meerkat/voting/VotingBooth.java index 1eebd78..e337a83 100644 --- a/src/main/java/meerkat/voting/VotingBooth.java +++ b/src/main/java/meerkat/voting/VotingBooth.java @@ -1,5 +1,7 @@ package meerkat.voting; +import static meerkat.protobuf.Voting.*; + /** * Created by talm on 25/10/15. */ diff --git a/src/main/proto/meerkat/comm/bulletin_board_message.proto b/src/main/proto/meerkat/comm/bulletin_board_message.proto deleted file mode 100644 index 35163c0..0000000 --- a/src/main/proto/meerkat/comm/bulletin_board_message.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; - -package meerkat.comm; - -import 'meerkat/crypto/signature.proto'; - -option java_outer_classname = "BulletinBoardMessageProtos"; - -message BulletinBoardMessage { - message Unsigned { - // Optional tags describing message - repeated string tags = 1; - - // The actual content of the message - bytes data = 2; - } - - Unsigned msg = 1; - - // Signature of message (and tags) - meerkat.crypto.Signature sig = 2; -} - diff --git a/src/main/proto/meerkat/crypto.proto b/src/main/proto/meerkat/crypto.proto new file mode 100644 index 0000000..e1475da --- /dev/null +++ b/src/main/proto/meerkat/crypto.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; + +package meerkat; + +option java_package = "meerkat.protobuf"; + +enum SignatureType { + ECDSA = 0; + DSA = 1; +} + +// A digital signature +message Signature { + SignatureType type = 1; + + // Data encoding depends on type; default is x509 BER-encoded + bytes data = 2; +} + +// Public key used to verify signatures +message SignatureVerificationKey { + SignatureType type = 1; + + bytes data = 2; +} + +// A public encryption key +message EncryptionPublicKey { + bytes data = 1; +} + +// Randomness used for encryption +message EncryptionRandomness { + bytes data = 1; +} + +// A proof that randomness is correctly generated +message RandomnessGenerationProof { + bytes data = 1; +} \ No newline at end of file diff --git a/src/main/proto/meerkat/crypto/signature.proto b/src/main/proto/meerkat/crypto/signature.proto deleted file mode 100644 index 61df002..0000000 --- a/src/main/proto/meerkat/crypto/signature.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package meerkat.crypto; - -option java_outer_classname = "SignatureProtos"; - -message Signature { - enum Type { - ECDSA = 0; - DSA = 1; - } - Type type = 1; - - bytes data = 2; -} diff --git a/src/main/proto/meerkat/voting.proto b/src/main/proto/meerkat/voting.proto new file mode 100644 index 0000000..cdfb139 --- /dev/null +++ b/src/main/proto/meerkat/voting.proto @@ -0,0 +1,89 @@ +syntax = "proto3"; + +package meerkat; + +import 'meerkat/crypto.proto'; + +option java_package = "meerkat.protobuf"; + + +message UnsignedBulletinBoardMessage { + // Optional tags describing message + repeated string tags = 1; + + // The actual content of the message + bytes data = 2; +} + +message BulletinBoardMessage { + + UnsignedBulletinBoardMessage msg = 1; + + // Signature of message (and tags) + meerkat.Signature sig = 2; +} + +// A ballot question. This is an opaque +// data type that is parsed by the UI to display +// the question. +message BallotQuestion { + bytes data = 1; +} + +// An answer to a specific ballot question. +// The answer is a vector of signed integers, +// to encompass voting schemes such as ranked voting +// and STV. +message BallotAnswer { + repeated sint64 answer = 1 [packed=true]; +} + +message PlaintextBallot { + uint64 serialNumber = 1; // Ballot serial number + + repeated BallotAnswer answers = 2; +} + +message BallotSecrets { + PlaintextBallot plaintext_ballot = 1; + + EncryptionRandomness encryption_randomness = 2; + RandomnessGenerationProof proof = 3; +} + +message BoothParams { + repeated SignatureVerificationKey pscVerificationKeys = 1; + +} + +// A table to translate to and from compactly encoded answers +// and their human-understandable counterparts. +// This should be parsable by the UI +message BallotAnswerTranslationTable { + bytes data = 1; +} + +message ElectionParams { + // TODO: different sets of keys for different roles? + repeated SignatureVerificationKey trusteeVerificationKeys = 1; + + // How many trustees must participate in a signature for it to be considered valid. + uint32 trusteeSignatureThreshold = 2; + + // The key used to encrypt ballots. The corresponding private key + // is shared between the trustees. + EncryptionPublicKey ballotEncryptionKey = 3; + + // Verification keys for valid mixers. + repeated SignatureVerificationKey mixerVerificationKeys = 4; + + // How many mixers must participate for the mixing to be considered valid + uint32 mixerThreshold = 5; + + // Candidate list (or other question format) + repeated BallotQuestion questions = 6; + + // Translation table between answers and plaintext encoding + BallotAnswerTranslationTable answerTranslationTable = 7; + +}