m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java1
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java31
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java7
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryUtils.java11
4 files changed, 50 insertions, 0 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java
index 5137e0b..a952274 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java
@@ -26,6 +26,7 @@ import pl.edu.mimuw.cloudatlas.model.ValueContact;
import pl.edu.mimuw.cloudatlas.model.ValueQuery;
import pl.edu.mimuw.cloudatlas.model.ValueTime;
import pl.edu.mimuw.cloudatlas.model.ZMI;
+import pl.edu.mimuw.cloudatlas.querysigner.QuerySignerApiImplementation;
public class GossipGirl extends Module {
private long nextGossipId = 0;
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
index 79728b5..efc5605 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
@@ -1,12 +1,21 @@
package pl.edu.mimuw.cloudatlas.agent.modules;
import java.nio.file.Path;
+import java.rmi.RemoteException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PublicKey;
import java.util.*;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map.Entry;
import pl.edu.mimuw.cloudatlas.agent.messages.*;
import pl.edu.mimuw.cloudatlas.model.*;
+import pl.edu.mimuw.cloudatlas.querysigner.*;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
public class Stanik extends Module {
private class InvalidUpdateAttributesMessage extends Exception {
@@ -21,6 +30,7 @@ public class Stanik extends Module {
private Set<ValueContact> contacts;
private ValueTime contactsTimestamp;
private PathName ourPath;
+ private PublicKey publicKey;
public Stanik(PathName ourPath, long freshnessPeriod) {
super(ModuleType.STATE);
@@ -31,6 +41,8 @@ public class Stanik extends Module {
this.freshnessPeriod = freshnessPeriod;
this.contactsTimestamp = ValueUtils.currentTime();
this.contacts = new HashSet<>();
+ String publicKeyFile = System.getProperty("public_key_file");
+ this.publicKey = KeyUtils.getPublicKey(publicKeyFile);
setDefaultQueries();
}
@@ -213,6 +225,25 @@ public class Stanik extends Module {
System.out.println("INFO: Stanik handles update queries");
for (Entry<Attribute, ValueQuery> entry : message.getQueries().entrySet()) {
Attribute attribute = entry.getKey();
+ ValueQuery query = entry.getValue();
+ try {
+ if (query.isInstalled()) {
+ QuerySignerApiImplementation.validateInstallQuery(
+ attribute.getName(),
+ QueryUtils.constructQueryData(query),
+ this.publicKey);
+
+ } else {
+ QuerySignerApiImplementation.validateUninstallQuery(
+ attribute.getName(),
+ QueryUtils.constructQueryData(query),
+ this.publicKey);
+ }
+ } catch (RemoteException | IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchAlgorithmException | NoSuchPaddingException | QuerySigner.InvalidQueryException e) {
+ System.out.println("ERROR: Query " + attribute.getName() + " was not updated in Stanik with error message " + e.getMessage());
+ e.printStackTrace();
+ continue;
+ }
ValueTime timestamp = new ValueTime(entry.getValue().getTimestamp());
ValueQuery currentTimestampedQuery = queries.get(attribute);
if (currentTimestampedQuery == null ||
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java
index 87b965c..a9e039e 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java
@@ -19,6 +19,13 @@ public class QueryData implements Serializable {
this.installed = true;
}
+ public QueryData(String code, byte[] signature, long timestamp, boolean installed) {
+ this.code = code;
+ this.signature = signature;
+ this.timestamp = timestamp;
+ this.installed = installed;
+ }
+
public String getCode() {
return code;
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryUtils.java b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryUtils.java
index 6ec62f4..c46e32d 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryUtils.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryUtils.java
@@ -1,5 +1,7 @@
package pl.edu.mimuw.cloudatlas.querysigner;
+import pl.edu.mimuw.cloudatlas.model.ValueQuery;
+
import java.rmi.RemoteException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -13,4 +15,13 @@ public class QueryUtils {
throw new RemoteException("Invalid query identifier");
}
}
+
+ public static QueryData constructQueryData(ValueQuery valueQuery) {
+ return new QueryData(
+ valueQuery.getCode(),
+ valueQuery.getSignature(),
+ valueQuery.getTimestamp(),
+ valueQuery.isInstalled()
+ );
+ }
}