diff --git a/bulletin-board-server/build.gradle b/bulletin-board-server/build.gradle index 3b3a082..cfe4233 100644 --- a/bulletin-board-server/build.gradle +++ b/bulletin-board-server/build.gradle @@ -71,7 +71,7 @@ task integrationTest(type: Test) { } gretty { - httpPort = 8081 + httpPort = 8082 contextPath = '/' integrationTestTask = 'integrationTest' loggingLevel = 'TRACE' diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/httpserver/BulletinBoardHttpServer.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/httpserver/BulletinBoardHttpServer.java index 10683cb..6d344fe 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/httpserver/BulletinBoardHttpServer.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/httpserver/BulletinBoardHttpServer.java @@ -11,7 +11,7 @@ import javax.servlet.http.HttpServletResponse; import meerkat.bulletinboard.BulletinBoardServer; import meerkat.bulletinboard.sqlserver.SQLiteBulletinBoardServer; import meerkat.comm.CommunicationException; -import meerkat.protobuf.Voting.BulletinBoardMessage; +import meerkat.protobuf.BulletinBoardAPI.*; public class BulletinBoardHttpServer extends HttpServlet { diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/service/HelloProtoBuf.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/service/HelloProtoBuf.java index f848a47..a4d8012 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/service/HelloProtoBuf.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/service/HelloProtoBuf.java @@ -3,8 +3,7 @@ package meerkat.bulletinboard.service; import com.google.protobuf.ByteString; import com.google.protobuf.Message; import meerkat.protobuf.Crypto; -import meerkat.protobuf.Voting; -import meerkat.protobuf.Voting.BulletinBoardMessage; +import meerkat.protobuf.BulletinBoardAPI.*; import java.util.Arrays; import java.util.List; @@ -16,7 +15,7 @@ public class HelloProtoBuf { public Message sayHello() { BulletinBoardMessage.Builder msg = BulletinBoardMessage.newBuilder(); - Voting.UnsignedBulletinBoardMessage.Builder unsigned = Voting.UnsignedBulletinBoardMessage.newBuilder(); + UnsignedBulletinBoardMessage.Builder unsigned = UnsignedBulletinBoardMessage.newBuilder(); unsigned.setData(ByteString.copyFromUtf8("Hello World!")); List tags = Arrays.asList("Greetings", "FirstPrograms"); unsigned.addAllTags(tags); diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/BulletinBoardSQLServer.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/BulletinBoardSQLServer.java index d91b545..b4045fb 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/BulletinBoardSQLServer.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/BulletinBoardSQLServer.java @@ -3,10 +3,6 @@ package meerkat.bulletinboard.sqlserver; import java.util.Arrays; import java.util.List; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; - import com.google.protobuf.ProtocolStringList; import java.sql.Connection; @@ -16,14 +12,11 @@ import java.sql.SQLException; import java.sql.Statement; import meerkat.bulletinboard.BulletinBoardServer; -import meerkat.protobuf.Voting.MessageFilterList; import meerkat.comm.CommunicationException; +import meerkat.protobuf.BulletinBoardAPI.*; import meerkat.protobuf.Crypto.SignatureVerificationKey; -import meerkat.protobuf.Voting.BulletinBoardMessage; -import meerkat.protobuf.Voting.BulletinBoardMessageList; import meerkat.crypto.Digest; import meerkat.crypto.concrete.SHA256Digest; -import meerkat.protobuf.Voting.MessageID; public abstract class BulletinBoardSQLServer implements BulletinBoardServer{ @@ -69,10 +62,17 @@ public abstract class BulletinBoardSQLServer implements BulletinBoardServer{ */ protected abstract void insertNewTags(String[] tags) throws SQLException; + private BoolMsg boolToBoolMsg(boolean b){ + return BoolMsg.newBuilder() + .setValue(b) + .build(); + } + @Override - public boolean postMessage(BulletinBoardMessage msg) throws CommunicationException { + public BoolMsg postMessage(BulletinBoardMessage msg) throws CommunicationException { + if (!verifyMessage(msg)) { - return false; + return boolToBoolMsg(false); } PreparedStatement pstmt; @@ -130,7 +130,7 @@ public abstract class BulletinBoardSQLServer implements BulletinBoardServer{ throw new CommunicationException("Error Linking tags: " + e.getMessage()); } - return true; + return boolToBoolMsg(true); } @Override diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java index a3782c1..6cc016b 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java @@ -4,9 +4,6 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -16,20 +13,14 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import com.google.protobuf.Message; -import meerkat.protobuf.BulletinBoardServer; -import meerkat.protobuf.Bulletinboardserver; -import meerkat.protobuf.Voting.MessageFilterList; +import meerkat.protobuf.BulletinBoardAPI.*; import meerkat.rest.Constants; import meerkat.bulletinboard.sqlserver.BulletinBoardSQLServer; import meerkat.comm.CommunicationException; -import meerkat.protobuf.Voting.BulletinBoardMessage; -import meerkat.protobuf.Voting.BulletinBoardMessageList; -@Path("/SQLServer") +@Path("/sqlserver") public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer { protected static final int TIMEOUT = 20; @@ -104,24 +95,15 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer { } + @Path("postmessage") + @POST @Override - public boolean postMessage(BulletinBoardMessage msg) throws CommunicationException { + public BoolMsg postMessage(BulletinBoardMessage msg) throws CommunicationException { return super.postMessage(msg); } - + @Path("readmessages") @POST - @Consumes(Constants.MEDIATYPE_PROTOBUF) - @Produces(Constants.MEDIATYPE_PROTOBUF) - public Message doPostMessage(BulletinBoardMessage msg)throws CommunicationException { - boolean result = super.postMessage(msg); - - return BulletinBoardServer.Boolean.newBuilder() - .setValue(result) - .build(); - } - -// @GET @Consumes(Constants.MEDIATYPE_PROTOBUF) @Produces(Constants.MEDIATYPE_PROTOBUF) @Override diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/HelloProtoWebApp.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/HelloProtoWebApp.java index b144a5a..ca56c3d 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/HelloProtoWebApp.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/HelloProtoWebApp.java @@ -3,10 +3,8 @@ package meerkat.bulletinboard.webapp; import com.google.protobuf.ByteString; import com.google.protobuf.Message; import meerkat.bulletinboard.service.HelloProtoBuf; -import meerkat.protobuf.Crypto.Signature; -import meerkat.protobuf.Crypto.SignatureType; -import meerkat.protobuf.Voting.BulletinBoardMessage; -import meerkat.protobuf.Voting.UnsignedBulletinBoardMessage; +import meerkat.protobuf.Crypto.*; +import meerkat.protobuf.BulletinBoardAPI.*; import meerkat.rest.Constants; import javax.annotation.PostConstruct; diff --git a/bulletin-board-server/src/test/java/meerkat/bulletinboard/HelloProtoIntegrationTest.java b/bulletin-board-server/src/test/java/meerkat/bulletinboard/HelloProtoIntegrationTest.java index 1bcb091..a34de1d 100644 --- a/bulletin-board-server/src/test/java/meerkat/bulletinboard/HelloProtoIntegrationTest.java +++ b/bulletin-board-server/src/test/java/meerkat/bulletinboard/HelloProtoIntegrationTest.java @@ -1,6 +1,6 @@ package meerkat.bulletinboard; -import meerkat.protobuf.Voting; +import meerkat.protobuf.BulletinBoardAPI.*; import meerkat.rest.Constants; import meerkat.rest.ProtobufMessageBodyReader; import meerkat.rest.ProtobufMessageBodyWriter; @@ -29,8 +29,8 @@ public class HelloProtoIntegrationTest { client.register(ProtobufMessageBodyWriter.class); WebTarget webTarget = client.target(BASE_URL).path(HELLO_URL); - Voting.BulletinBoardMessage response = webTarget.request(Constants.MEDIATYPE_PROTOBUF) - .get(Voting.BulletinBoardMessage.class); + BulletinBoardMessage response = webTarget.request(Constants.MEDIATYPE_PROTOBUF) + .get(BulletinBoardMessage.class); System.out.println(response.getMsg().getData()); diff --git a/bulletin-board-server/src/test/java/meerkat/bulletinboard/SQLiteServerIntegrationTest.java b/bulletin-board-server/src/test/java/meerkat/bulletinboard/SQLiteServerIntegrationTest.java index 6a6371d..2de886b 100644 --- a/bulletin-board-server/src/test/java/meerkat/bulletinboard/SQLiteServerIntegrationTest.java +++ b/bulletin-board-server/src/test/java/meerkat/bulletinboard/SQLiteServerIntegrationTest.java @@ -2,13 +2,12 @@ package meerkat.bulletinboard; import com.google.protobuf.ByteString; -import meerkat.protobuf.Crypto.Signature; -import meerkat.protobuf.Crypto.SignatureType; -import meerkat.protobuf.Voting.BulletinBoardMessage; -import meerkat.protobuf.Voting.UnsignedBulletinBoardMessage; +import meerkat.protobuf.Crypto.*; +import meerkat.protobuf.BulletinBoardAPI.*; import meerkat.rest.Constants; import meerkat.rest.ProtobufMessageBodyReader; import meerkat.rest.ProtobufMessageBodyWriter; + import org.junit.Before; import org.junit.Test; @@ -21,9 +20,9 @@ import javax.ws.rs.core.Response; public class SQLiteServerIntegrationTest { private static String PROP_GETTY_URL = "gretty.httpBaseURI"; - private static String DEFAULT_BASE_URL = "http://localhost:8081/"; + private static String DEFAULT_BASE_URL = "localhost:8082"; private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL); - private static String SQL_SERVER_URL = "SQLServer"; + private static String SQL_SERVER_URL = "sqlserver/postmessage"; Client client; @@ -57,19 +56,13 @@ public class SQLiteServerIntegrationTest { .build()) .build(); -// SQLiteBulletinBoardServer bbs = new SQLiteBulletinBoardServer(); -// -// -// bbs.init(); -// -// bbs.postMessage(msg); -// response = Response.status(Status.OK).entity(bbs.testPrint()).build(); -// -// bbs.close(); - System.err.println("******** Testing: " + SQL_SERVER_URL); WebTarget webTarget = client.target(BASE_URL).path(SQL_SERVER_URL); response = webTarget.request(Constants.MEDIATYPE_PROTOBUF).post(Entity.entity(msg, Constants.MEDIATYPE_PROTOBUF)); + System.err.println(response); + BoolMsg bool = response.readEntity(BoolMsg.class); + assert bool.getValue(); + } } diff --git a/meerkat-common/src/main/java/Demo.java b/meerkat-common/src/main/java/Demo.java index 3b8e857..be79642 100644 --- a/meerkat-common/src/main/java/Demo.java +++ b/meerkat-common/src/main/java/Demo.java @@ -1,5 +1,5 @@ import com.google.protobuf.ByteString; -import static meerkat.protobuf.Voting.*; +import static meerkat.protobuf.BulletinBoardAPI.*; import java.io.IOException; /** diff --git a/meerkat-common/src/main/java/meerkat/bulletinboard/BulletinBoard.java b/meerkat-common/src/main/java/meerkat/bulletinboard/BulletinBoard.java index eb31c6d..0efd6a7 100644 --- a/meerkat-common/src/main/java/meerkat/bulletinboard/BulletinBoard.java +++ b/meerkat-common/src/main/java/meerkat/bulletinboard/BulletinBoard.java @@ -1,7 +1,7 @@ package meerkat.bulletinboard; import meerkat.comm.*; -import static meerkat.protobuf.Voting.*; +import static meerkat.protobuf.BulletinBoardAPI.*; import java.util.List; diff --git a/meerkat-common/src/main/java/meerkat/bulletinboard/BulletinBoardServer.java b/meerkat-common/src/main/java/meerkat/bulletinboard/BulletinBoardServer.java index f312ed8..d37a674 100644 --- a/meerkat-common/src/main/java/meerkat/bulletinboard/BulletinBoardServer.java +++ b/meerkat-common/src/main/java/meerkat/bulletinboard/BulletinBoardServer.java @@ -1,9 +1,7 @@ package meerkat.bulletinboard; import meerkat.comm.CommunicationException; -import meerkat.protobuf.Voting.BulletinBoardMessage; -import meerkat.protobuf.Voting.BulletinBoardMessageList; -import meerkat.protobuf.Voting.MessageFilterList; +import meerkat.protobuf.BulletinBoardAPI.*; /** * Created by Arbel on 07/11/15. @@ -24,10 +22,10 @@ public interface BulletinBoardServer{ /** * Post a message to bulletin board. * @param msg is the actual (signed) message - * @return TRUE if the message has been authenticated and FALSE otherwise. + * @return TRUE if the message has been authenticated and FALSE otherwise (in ProtoBuf form). * @throws CommunicationException on DB connection error. */ - public boolean postMessage(BulletinBoardMessage msg) throws CommunicationException; + public BoolMsg postMessage(BulletinBoardMessage msg) throws CommunicationException; /** * Read all messages posted matching the given filter. diff --git a/meerkat-common/src/main/java/meerkat/crypto/DigitalSignature.java b/meerkat-common/src/main/java/meerkat/crypto/DigitalSignature.java index 1abad8f..e0a9294 100644 --- a/meerkat-common/src/main/java/meerkat/crypto/DigitalSignature.java +++ b/meerkat-common/src/main/java/meerkat/crypto/DigitalSignature.java @@ -17,7 +17,7 @@ import static meerkat.protobuf.Crypto.*; /** * Created by talm on 25/10/15. * - * Sign and verifyarrays of messages + * Sign and verify arrays of messages */ public interface DigitalSignature { final public static String CERTIFICATE_ENCODING_X509 = "X.509"; diff --git a/meerkat-common/src/main/proto/meerkat/BulletinBoardAPI.proto b/meerkat-common/src/main/proto/meerkat/BulletinBoardAPI.proto new file mode 100644 index 0000000..fa64380 --- /dev/null +++ b/meerkat-common/src/main/proto/meerkat/BulletinBoardAPI.proto @@ -0,0 +1,65 @@ +syntax = "proto3"; + +package meerkat; + +option java_package = "meerkat.protobuf"; + +import 'meerkat/crypto.proto'; + +message BoolMsg { + bool value = 1; +} + + +message MessageID { + // The ID of a message for unique retrieval. + // Note that it is assumed that this ID is a function of the message itself. + bytes ID = 1; +} + +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; +} + +message BulletinBoardMessageList { + + repeated BulletinBoardMessage messages = 1; + +} + +enum FilterType { + ID = 0; // Match exact message ID + EXACT_ENTRY = 1; // Match exact entry number in database (chronological) + MAX_ENTRY = 2; // Find all entries in database up to specified entry number (chronological) + SIGNATURE = 3; // Find all entries in database that correspond to specific signature (signer) + TAG = 4; // Find all entries in database that have a specific tag + MAX_MESSAGES = 5; // Return at most some specified number of messages +} + +message MessageFilter { + + FilterType type = 1; + + // Concrete data input to filter + bytes filter = 2; +} + +message MessageFilterList { + + // Combination of filters. + // To be implemented using intersection ("AND") operations. + repeated MessageFilter filters = 1; + +} \ No newline at end of file diff --git a/meerkat-common/src/main/proto/meerkat/voting.proto b/meerkat-common/src/main/proto/meerkat/voting.proto index 34be8fb..beb4e0c 100644 --- a/meerkat-common/src/main/proto/meerkat/voting.proto +++ b/meerkat-common/src/main/proto/meerkat/voting.proto @@ -6,59 +6,6 @@ import 'meerkat/crypto.proto'; option java_package = "meerkat.protobuf"; -message MessageID { - // The ID of a message for unique retrieval. - // Note that it is assumed that this ID is a function of the message itself. - bytes ID = 1; -} - -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; -} - -message BulletinBoardMessageList { - - repeated BulletinBoardMessage messages = 1; - -} - -enum FilterType { - ID = 0; // Match exact message ID - EXACT_ENTRY = 1; // Match exact entry number in database (chronological) - MAX_ENTRY = 2; // Find all entries in database up to specified entry number (chronological) - SIGNATURE = 3; // Find all entries in database that correspond to specific signature (signer) - TAG = 4; // Find all entries in database that have a specific tag - MAX_MESSAGES = 5; // Return at most some specified number of messages -} - -message MessageFilter { - - FilterType type = 1; - - // Concrete data input to filter - bytes filter = 2; -} - -message MessageFilterList { - - // Combination of filters. - // To be implemented using intersection ("AND") operations. - repeated MessageFilter filters = 1; - -} - // A ballot question. This is an opaque // data type that is parsed by the UI to display // the question. diff --git a/meerkat-common/src/test/java/meerkat/crypto/concrete/TestECDSASignature.java b/meerkat-common/src/test/java/meerkat/crypto/concrete/TestECDSASignature.java index 4fbb35c..11c6b28 100644 --- a/meerkat-common/src/test/java/meerkat/crypto/concrete/TestECDSASignature.java +++ b/meerkat-common/src/test/java/meerkat/crypto/concrete/TestECDSASignature.java @@ -2,7 +2,7 @@ package meerkat.crypto.concrete; import com.google.protobuf.ByteString; import meerkat.protobuf.Crypto; -import meerkat.protobuf.Voting; +import meerkat.protobuf.Bulletinboardserver.*; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -149,13 +149,13 @@ public class TestECDSASignature { signer.loadSigningCertificate(keyStore); - Voting.UnsignedBulletinBoardMessage.Builder unsignedMsgBuilder = Voting.UnsignedBulletinBoardMessage.newBuilder(); + UnsignedBulletinBoardMessage.Builder unsignedMsgBuilder = UnsignedBulletinBoardMessage.newBuilder(); unsignedMsgBuilder.setData(ByteString.copyFromUtf8(HELLO_WORLD)); unsignedMsgBuilder.addTags("Tag1"); unsignedMsgBuilder.addTags("Tag2"); unsignedMsgBuilder.addTags("Tag3"); - Voting.UnsignedBulletinBoardMessage usMsg = unsignedMsgBuilder.build(); + UnsignedBulletinBoardMessage usMsg = unsignedMsgBuilder.build(); signer.updateContent(usMsg); Crypto.Signature sig = signer.sign();