Added getSignerID method to signatures.
Added timing output for Server tests.Bulletin-Board-Client-phase_1
parent
0b847dcaf4
commit
3f21f30f35
|
@ -2,6 +2,8 @@ package meerkat.bulletinboard;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.math.BigInteger;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.KeyStore;
|
||||
|
@ -30,7 +32,6 @@ public class GenericBulletinBoardServerTest {
|
|||
|
||||
protected BulletinBoardServer bulletinBoardServer;
|
||||
private ECDSASignature signers[];
|
||||
private ByteString[] signerIDs;
|
||||
|
||||
private Random random;
|
||||
|
||||
|
@ -43,6 +44,14 @@ public class GenericBulletinBoardServerTest {
|
|||
public static String CERT1_PEM_EXAMPLE = "/certs/enduser-certs/user1.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.
|
||||
* @throws InstantiationException
|
||||
|
@ -55,11 +64,13 @@ public class GenericBulletinBoardServerTest {
|
|||
* @throws CommunicationException
|
||||
*/
|
||||
public void init(BulletinBoardServer bulletinBoardServer) {
|
||||
|
||||
|
||||
System.err.println("Starting to initialize GenericBulletinBoardServerTest");
|
||||
long start = threadBean.getCurrentThreadCpuTime();
|
||||
|
||||
this.bulletinBoardServer = bulletinBoardServer;
|
||||
|
||||
signers = new ECDSASignature[2];
|
||||
signerIDs = new ByteString[signers.length];
|
||||
signers[0] = new ECDSASignature();
|
||||
signers[1] = new ECDSASignature();
|
||||
|
||||
|
@ -98,42 +109,22 @@ public class GenericBulletinBoardServerTest {
|
|||
System.err.println("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
|
||||
|
||||
long end = threadBean.getCurrentThreadCpuTime();
|
||||
System.err.println("Finished initializing GenericBulletinBoardServerTest");
|
||||
System.err.println("Time of operation: " + (end - start));
|
||||
}
|
||||
|
||||
private byte randomByte(){
|
||||
return (byte) random.nextInt();
|
||||
}
|
||||
|
||||
|
||||
private String randomString(){
|
||||
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.
|
||||
* @throws CommunicationException
|
||||
|
@ -144,6 +135,9 @@ public class GenericBulletinBoardServerTest {
|
|||
*/
|
||||
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.
|
||||
|
||||
tags = new String[TAG_NUM];
|
||||
|
@ -214,6 +208,11 @@ public class GenericBulletinBoardServerTest {
|
|||
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(){
|
||||
|
||||
System.err.println("Starting to test tag and signature mechanism");
|
||||
long start = threadBean.getCurrentThreadCpuTime();
|
||||
|
||||
List<BulletinBoardMessage> messages;
|
||||
|
||||
// Check tag mechanism
|
||||
|
@ -288,7 +290,11 @@ 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(){
|
||||
|
||||
System.err.println("Starting to test multiple tags and signatures");
|
||||
long start = threadBean.getCurrentThreadCpuTime();
|
||||
|
||||
List<BulletinBoardMessage> messages;
|
||||
MessageFilterList.Builder filterListBuilder = MessageFilterList.newBuilder();
|
||||
|
||||
|
@ -336,11 +345,11 @@ public class GenericBulletinBoardServerTest {
|
|||
filterListBuilder = MessageFilterList.newBuilder()
|
||||
.addFilter(MessageFilter.newBuilder()
|
||||
.setType(FilterType.SIGNER_ID)
|
||||
.setId(signerIDs[0])
|
||||
.setId(signers[0].getSignerID())
|
||||
.build())
|
||||
.addFilter(MessageFilter.newBuilder()
|
||||
.setType(FilterType.SIGNER_ID)
|
||||
.setId(signerIDs[1])
|
||||
.setId(signers[1].getSignerID())
|
||||
.build()
|
||||
);
|
||||
|
||||
|
@ -358,6 +367,10 @@ public class GenericBulletinBoardServerTest {
|
|||
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(){
|
||||
|
|
|
@ -9,6 +9,8 @@ import org.junit.Test;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.security.*;
|
||||
import java.security.cert.CertificateException;
|
||||
|
||||
|
@ -23,9 +25,14 @@ public class SQLiteBulletinBoardServerTest{
|
|||
|
||||
private GenericBulletinBoardServerTest serverTest;
|
||||
|
||||
private final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); // Used to time the tests
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
|
||||
System.err.println("Starting to initialize SQLiteBulletinBoardServerTest");
|
||||
long start = threadBean.getCurrentThreadCpuTime();
|
||||
|
||||
File old = new File(testFilename);
|
||||
old.delete();
|
||||
|
||||
|
@ -46,10 +53,17 @@ public class SQLiteBulletinBoardServerTest{
|
|||
System.err.println(e.getMessage());
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
long end = threadBean.getCurrentThreadCpuTime();
|
||||
System.err.println("Finished initializing SQLiteBulletinBoardServerTest");
|
||||
System.err.println("Time of operation: " + (end - start));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bulkTest() {
|
||||
System.err.println("Starting bulkTest of SQLiteBulletinBoardServerTest");
|
||||
long start = threadBean.getCurrentThreadCpuTime();
|
||||
|
||||
try {
|
||||
serverTest.testInsert();
|
||||
serverTest.testSimpleTagAndSignature();
|
||||
|
@ -57,11 +71,22 @@ public class SQLiteBulletinBoardServerTest{
|
|||
System.err.println(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
|
||||
public void close() {
|
||||
System.err.println("Starting to close SQLiteBulletinBoardServerTest");
|
||||
long start = threadBean.getCurrentThreadCpuTime();
|
||||
|
||||
serverTest.close();
|
||||
|
||||
long end = threadBean.getCurrentThreadCpuTime();
|
||||
System.err.println("Finished closing SQLiteBulletinBoardServerTest");
|
||||
System.err.println("Time of operation: " + (end - start));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package meerkat.crypto;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.Message;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -82,6 +83,10 @@ public interface DigitalSignature {
|
|||
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).
|
||||
|
|
|
@ -300,6 +300,11 @@ public class ECDSASignature extends GlobalCryptoSetup implements DigitalSignatur
|
|||
throw new UnrecoverableKeyException("Didn't find valid private key entry in keystore!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteString getSignerID() {
|
||||
return loadedSigningKeyId;
|
||||
}
|
||||
|
||||
public void clearSigningKey() {
|
||||
try {
|
||||
// TODO: Check if this really clears the key from memory
|
||||
|
|
Loading…
Reference in New Issue