diff options
author | Magdalena Grodzińska <mag.grodzinska@gmail.com> | 2020-01-14 22:50:10 +0100 |
---|---|---|
committer | Magdalena Grodzińska <mag.grodzinska@gmail.com> | 2020-01-14 22:50:10 +0100 |
commit | 93cafafbc6fe53628be1b4ef08b6d9ca48ec6bc9 (patch) | |
tree | fa8169af492e6cc58034f28f550549d16635d00f /src/main/java/pl/edu/mimuw/cloudatlas/agent | |
parent | 9681d76b15cc68f2f8246972ae8266522b92fefe (diff) |
Add validation in Stanik
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java | 1 | ||||
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java | 31 |
2 files changed, 32 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 || |