Working version of Bulletin Board Server + refactoring of Bulletin Board ProtoBufs + successful integration test

Bulletin_Board_Server_phase_1
Arbel Deutsch Peled 2015-11-17 22:27:01 +02:00
parent 15859391a1
commit 47edf0df34
15 changed files with 109 additions and 127 deletions

View File

@ -71,7 +71,7 @@ task integrationTest(type: Test) {
}
gretty {
httpPort = 8081
httpPort = 8082
contextPath = '/'
integrationTestTask = 'integrationTest'
loggingLevel = 'TRACE'

View File

@ -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 {

View File

@ -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<String> tags = Arrays.asList("Greetings", "FirstPrograms");
unsigned.addAllTags(tags);

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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());

View File

@ -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();
}
}

View File

@ -1,5 +1,5 @@
import com.google.protobuf.ByteString;
import static meerkat.protobuf.Voting.*;
import static meerkat.protobuf.BulletinBoardAPI.*;
import java.io.IOException;
/**

View File

@ -1,7 +1,7 @@
package meerkat.bulletinboard;
import meerkat.comm.*;
import static meerkat.protobuf.Voting.*;
import static meerkat.protobuf.BulletinBoardAPI.*;
import java.util.List;

View File

@ -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.

View File

@ -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";

View File

@ -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;
}

View File

@ -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.

View File

@ -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();