From f3ec49acc767e24d9e4d79df587448d602bcca83 Mon Sep 17 00:00:00 2001 From: Vladimir Eliezer Tokarev Date: Sat, 26 Mar 2016 04:11:09 -0700 Subject: [PATCH] Removed the usage of the collection of digital signers --- .../java/meerkat/util/BulletinBoardUtils.java | 4 ++-- .../src/main/java/meerkat/AsyncRegistry.java | 15 +++++++-------- .../src/main/java/meerkat/VoterRegistry.java | 5 ++--- .../src/test/java/SimpleRegistryTest.java | 9 +++------ 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/meerkat-common/src/main/java/meerkat/util/BulletinBoardUtils.java b/meerkat-common/src/main/java/meerkat/util/BulletinBoardUtils.java index 9f8b322..ca94522 100644 --- a/meerkat-common/src/main/java/meerkat/util/BulletinBoardUtils.java +++ b/meerkat-common/src/main/java/meerkat/util/BulletinBoardUtils.java @@ -18,7 +18,8 @@ public class BulletinBoardUtils { * signed by all given DigitalSignatures * * @param unsignedMessage BasicMessage - * @param signer DigitalSignature which will sign the UnsignedBulletinBoardMessage message + * @param signer collection of DigitalSignature which will sign the + * UnsignedBulletinBoardMessage message * @return BulletinBoardMessage */ public static BulletinBoardMessage signBulletinBoardMessage(UnsignedBulletinBoardMessage unsignedMessage, @@ -28,7 +29,6 @@ public class BulletinBoardUtils { signer.updateContent(unsignedMessage); Crypto.Signature signature = signer.sign(); bulletinBoardMessage.addSig(signature); - return bulletinBoardMessage.build(); } diff --git a/voter-registry/src/main/java/meerkat/AsyncRegistry.java b/voter-registry/src/main/java/meerkat/AsyncRegistry.java index 5af7534..f0905b5 100644 --- a/voter-registry/src/main/java/meerkat/AsyncRegistry.java +++ b/voter-registry/src/main/java/meerkat/AsyncRegistry.java @@ -17,7 +17,6 @@ import meerkat.util.BulletinBoardUtils; import java.io.IOException; import java.security.SignatureException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import static meerkat.util.BulletinBoardUtils.signBulletinBoardMessage; @@ -31,16 +30,15 @@ import static meerkat.util.BulletinBoardUtils.signBulletinBoardMessage; */ public class AsyncRegistry implements VoterRegistry{ - protected Collection signers; + protected DigitalSignature signer; protected AsyncBulletinBoardClient bulletinBoardClient ; @Override - public void init(Collection signers, AsyncBulletinBoardClient communicator) { - this.signers = signers; + public void init(DigitalSignature signer, AsyncBulletinBoardClient communicator) { + this.signer = signer; this.bulletinBoardClient = communicator; } - @Override public void addVoter(VoterInfo voterInfo, FutureCallback callback) throws SignatureException { UnsignedBulletinBoardMessage basicMessage = @@ -51,7 +49,8 @@ public class AsyncRegistry implements VoterRegistry{ .setTimestamp(BulletinBoardUtils.getCurrentTimestampProto()) .build(); - bulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage, signers), callback); + + bulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage, signer), callback); } @Override @@ -63,7 +62,7 @@ public class AsyncRegistry implements VoterRegistry{ .setData(voterRegistryMessage.toByteString()) .setTimestamp(BulletinBoardUtils.getCurrentTimestampProto()); - bulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage.build(), signers), callback); + bulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage.build(), signer), callback); } @Override @@ -75,7 +74,7 @@ public class AsyncRegistry implements VoterRegistry{ .setTimestamp(BulletinBoardUtils.getCurrentTimestampProto()) .build(); - bulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage, signers), callback); + bulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage, signer), callback); } @Override diff --git a/voter-registry/src/main/java/meerkat/VoterRegistry.java b/voter-registry/src/main/java/meerkat/VoterRegistry.java index f1a5816..3a7794a 100644 --- a/voter-registry/src/main/java/meerkat/VoterRegistry.java +++ b/voter-registry/src/main/java/meerkat/VoterRegistry.java @@ -9,7 +9,6 @@ import meerkat.protobuf.VoterRegistry.VoterRegistryMessage; import java.io.IOException; import java.security.SignatureException; -import java.util.Collection; import java.util.List; /** @@ -20,10 +19,10 @@ public interface VoterRegistry { /** * Initialize the voter registry - * @param signers collection of singers every object will sign every output message + * @param signer object which sign the outputed message * @param communicator the object which communicates with the BulletinBoardServer */ - void init(Collection signers, AsyncBulletinBoardClient communicator); + void init(DigitalSignature signer, AsyncBulletinBoardClient communicator); /** * Adds new voter to the bulletin-board diff --git a/voter-registry/src/test/java/SimpleRegistryTest.java b/voter-registry/src/test/java/SimpleRegistryTest.java index 657a983..42e6ef4 100644 --- a/voter-registry/src/test/java/SimpleRegistryTest.java +++ b/voter-registry/src/test/java/SimpleRegistryTest.java @@ -23,7 +23,6 @@ import java.security.KeyStore; import java.security.SecureRandom; import java.security.SignatureException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.concurrent.Semaphore; @@ -44,7 +43,7 @@ import static meerkat.util.BulletinBoardUtils.getLatestMessage; */ public class SimpleRegistryTest { - private Collection signers; + private DigitalSignature signer; private AsyncBulletinBoardClient bulletinBoardClient; private InputStream certStream; private SecureRandom random = new SecureRandom(); @@ -105,7 +104,6 @@ public class SimpleRegistryTest { private void SetSigner(){ try { - signers = new ArrayList<>(); ECDSASignature signer = new ECDSASignature(); InputStream keyStream = getClass().getResourceAsStream(KEYFILE_EXAMPLE); char[] password = KEYFILE_PASSWORD.toCharArray(); @@ -115,8 +113,7 @@ public class SimpleRegistryTest { signer.loadVerificationCertificates(getClass().getResourceAsStream(CERT1_PEM_EXAMPLE)); keyStream.close(); - signers.add(signer); - + this.signer = signer; } catch (Exception e){ assert false : "The signers creation failed "; @@ -136,7 +133,7 @@ public class SimpleRegistryTest { private AsyncRegistry GetRegistry() { AsyncRegistry registry = new AsyncRegistry(); - registry.init(signers, bulletinBoardClient); + registry.init(signer, bulletinBoardClient); return registry; }