Added getSignerID method to signatures.

Added timing output for Server tests.
Bulletin-Board-Client-phase_1
Arbel Deutsch Peled 2015-12-08 09:11:22 +02:00
parent 0b847dcaf4
commit 3f21f30f35
4 changed files with 79 additions and 31 deletions

View File

@ -2,6 +2,8 @@ package meerkat.bulletinboard;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.KeyStore; import java.security.KeyStore;
@ -30,7 +32,6 @@ public class GenericBulletinBoardServerTest {
protected BulletinBoardServer bulletinBoardServer; protected BulletinBoardServer bulletinBoardServer;
private ECDSASignature signers[]; private ECDSASignature signers[];
private ByteString[] signerIDs;
private Random random; private Random random;
@ -43,6 +44,14 @@ public class GenericBulletinBoardServerTest {
public static String CERT1_PEM_EXAMPLE = "/certs/enduser-certs/user1.crt"; public static String CERT1_PEM_EXAMPLE = "/certs/enduser-certs/user1.crt";
public static String CERT3_PEM_EXAMPLE = "/certs/enduser-certs/user3.crt"; public static String CERT3_PEM_EXAMPLE = "/certs/enduser-certs/user3.crt";
private final int TAG_NUM = 5; // Number of tags.
private final int MESSAGE_NUM = 32; // Number of messages (2^TAG_NUM).
private String[] tags;
private byte[][] data;
private final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); // Used to time the tests
/** /**
* @param bulletinBoardServer is an initialized server. * @param bulletinBoardServer is an initialized server.
* @throws InstantiationException * @throws InstantiationException
@ -56,10 +65,12 @@ public class GenericBulletinBoardServerTest {
*/ */
public void init(BulletinBoardServer bulletinBoardServer) { public void init(BulletinBoardServer bulletinBoardServer) {
System.err.println("Starting to initialize GenericBulletinBoardServerTest");
long start = threadBean.getCurrentThreadCpuTime();
this.bulletinBoardServer = bulletinBoardServer; this.bulletinBoardServer = bulletinBoardServer;
signers = new ECDSASignature[2]; signers = new ECDSASignature[2];
signerIDs = new ByteString[signers.length];
signers[0] = new ECDSASignature(); signers[0] = new ECDSASignature();
signers[1] = new ECDSASignature(); signers[1] = new ECDSASignature();
@ -99,24 +110,11 @@ public class GenericBulletinBoardServerTest {
fail("Couldn't find signing key " + e.getMessage()); fail("Couldn't find signing key " + e.getMessage());
} }
// Get signer IDs
// TODO: remove this after creation of getSignerID method
UnsignedBulletinBoardMessage msg = UnsignedBulletinBoardMessage.newBuilder().build();
for (int i = 0 ; i < signers.length ; i++) {
try {
signers[i].updateContent(UnsignedBulletinBoardMessage.newBuilder().build());
signerIDs[i] = signers[i].sign().getSignerId();
} catch (SignatureException e) {
System.err.println("Error signing message" + e.getMessage());
fail("Error signing message" + e.getMessage());
return;
}
}
random = new Random(0); // We use insecure randomness in tests for repeatability random = new Random(0); // We use insecure randomness in tests for repeatability
long end = threadBean.getCurrentThreadCpuTime();
System.err.println("Finished initializing GenericBulletinBoardServerTest");
System.err.println("Time of operation: " + (end - start));
} }
private byte randomByte(){ private byte randomByte(){
@ -127,13 +125,6 @@ public class GenericBulletinBoardServerTest {
return new BigInteger(130, random).toString(32); return new BigInteger(130, random).toString(32);
} }
private final int TAG_NUM = 5; // Number of tags.
private final int MESSAGE_NUM = 32; // Number of messages (2^TAG_NUM).
private String[] tags;
private byte[][] data;
/** /**
* Tests writing of several messages with multiple tags and signatures. * Tests writing of several messages with multiple tags and signatures.
* @throws CommunicationException * @throws CommunicationException
@ -144,6 +135,9 @@ public class GenericBulletinBoardServerTest {
*/ */
public void testInsert() { public void testInsert() {
System.err.println("Starting to insert messages to DB");
long start = threadBean.getCurrentThreadCpuTime();
final int BYTES_PER_MESSAGE_DATA = 50; // Message size. final int BYTES_PER_MESSAGE_DATA = 50; // Message size.
tags = new String[TAG_NUM]; tags = new String[TAG_NUM];
@ -214,6 +208,11 @@ public class GenericBulletinBoardServerTest {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
long end = threadBean.getCurrentThreadCpuTime();
System.err.println("Finished inserting messages to DB");
System.err.println("Time of operation: " + (end - start));
} }
/** /**
@ -222,6 +221,9 @@ public class GenericBulletinBoardServerTest {
*/ */
public void testSimpleTagAndSignature(){ public void testSimpleTagAndSignature(){
System.err.println("Starting to test tag and signature mechanism");
long start = threadBean.getCurrentThreadCpuTime();
List<BulletinBoardMessage> messages; List<BulletinBoardMessage> messages;
// Check tag mechanism // Check tag mechanism
@ -289,6 +291,10 @@ public class GenericBulletinBoardServerTest {
} }
long end = threadBean.getCurrentThreadCpuTime();
System.err.println("Finished testing tag and signature mechanism");
System.err.println("Time of operation: " + (end - start));
} }
/** /**
@ -296,6 +302,9 @@ public class GenericBulletinBoardServerTest {
*/ */
public void testEnhancedTagsAndSignatures(){ public void testEnhancedTagsAndSignatures(){
System.err.println("Starting to test multiple tags and signatures");
long start = threadBean.getCurrentThreadCpuTime();
List<BulletinBoardMessage> messages; List<BulletinBoardMessage> messages;
MessageFilterList.Builder filterListBuilder = MessageFilterList.newBuilder(); MessageFilterList.Builder filterListBuilder = MessageFilterList.newBuilder();
@ -336,11 +345,11 @@ public class GenericBulletinBoardServerTest {
filterListBuilder = MessageFilterList.newBuilder() filterListBuilder = MessageFilterList.newBuilder()
.addFilter(MessageFilter.newBuilder() .addFilter(MessageFilter.newBuilder()
.setType(FilterType.SIGNER_ID) .setType(FilterType.SIGNER_ID)
.setId(signerIDs[0]) .setId(signers[0].getSignerID())
.build()) .build())
.addFilter(MessageFilter.newBuilder() .addFilter(MessageFilter.newBuilder()
.setType(FilterType.SIGNER_ID) .setType(FilterType.SIGNER_ID)
.setId(signerIDs[1]) .setId(signers[1].getSignerID())
.build() .build()
); );
@ -358,6 +367,10 @@ public class GenericBulletinBoardServerTest {
assertThat(message.getEntryNum() % 4, is((long) 1)); assertThat(message.getEntryNum() % 4, is((long) 1));
} }
long end = threadBean.getCurrentThreadCpuTime();
System.err.println("Finished testing multiple tags and signatures");
System.err.println("Time of operation: " + (end - start));
} }
public void close(){ public void close(){

View File

@ -9,6 +9,8 @@ import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.security.*; import java.security.*;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
@ -23,9 +25,14 @@ public class SQLiteBulletinBoardServerTest{
private GenericBulletinBoardServerTest serverTest; private GenericBulletinBoardServerTest serverTest;
private final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); // Used to time the tests
@Before @Before
public void init(){ public void init(){
System.err.println("Starting to initialize SQLiteBulletinBoardServerTest");
long start = threadBean.getCurrentThreadCpuTime();
File old = new File(testFilename); File old = new File(testFilename);
old.delete(); old.delete();
@ -46,10 +53,17 @@ public class SQLiteBulletinBoardServerTest{
System.err.println(e.getMessage()); System.err.println(e.getMessage());
fail(e.getMessage()); fail(e.getMessage());
} }
long end = threadBean.getCurrentThreadCpuTime();
System.err.println("Finished initializing SQLiteBulletinBoardServerTest");
System.err.println("Time of operation: " + (end - start));
} }
@Test @Test
public void bulkTest() { public void bulkTest() {
System.err.println("Starting bulkTest of SQLiteBulletinBoardServerTest");
long start = threadBean.getCurrentThreadCpuTime();
try { try {
serverTest.testInsert(); serverTest.testInsert();
serverTest.testSimpleTagAndSignature(); serverTest.testSimpleTagAndSignature();
@ -57,11 +71,22 @@ public class SQLiteBulletinBoardServerTest{
System.err.println(e.getMessage()); System.err.println(e.getMessage());
fail(e.getMessage()); fail(e.getMessage());
} }
long end = threadBean.getCurrentThreadCpuTime();
System.err.println("Finished bulkTest of SQLiteBulletinBoardServerTest");
System.err.println("Time of operation: " + (end - start));
} }
@After @After
public void close() { public void close() {
System.err.println("Starting to close SQLiteBulletinBoardServerTest");
long start = threadBean.getCurrentThreadCpuTime();
serverTest.close(); serverTest.close();
long end = threadBean.getCurrentThreadCpuTime();
System.err.println("Finished closing SQLiteBulletinBoardServerTest");
System.err.println("Time of operation: " + (end - start));
} }
} }

View File

@ -1,5 +1,6 @@
package meerkat.crypto; package meerkat.crypto;
import com.google.protobuf.ByteString;
import com.google.protobuf.Message; import com.google.protobuf.Message;
import java.io.IOException; import java.io.IOException;
@ -82,6 +83,10 @@ public interface DigitalSignature {
throws IOException, CertificateException, UnrecoverableKeyException; throws IOException, CertificateException, UnrecoverableKeyException;
/**
* @return the signer ID if it exists; null otherwise.
*/
public ByteString getSignerID();
/** /**
* Clear the signing key (will require authentication to use again). * Clear the signing key (will require authentication to use again).

View File

@ -300,6 +300,11 @@ public class ECDSASignature extends GlobalCryptoSetup implements DigitalSignatur
throw new UnrecoverableKeyException("Didn't find valid private key entry in keystore!"); throw new UnrecoverableKeyException("Didn't find valid private key entry in keystore!");
} }
@Override
public ByteString getSignerID() {
return loadedSigningKeyId;
}
public void clearSigningKey() { public void clearSigningKey() {
try { try {
// TODO: Check if this really clears the key from memory // TODO: Check if this really clears the key from memory