From 93cafafbc6fe53628be1b4ef08b6d9ca48ec6bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Tue, 14 Jan 2020 22:50:10 +0100 Subject: Add validation in Stanik --- .../mimuw/cloudatlas/agent/modules/GossipGirl.java | 1 + .../edu/mimuw/cloudatlas/agent/modules/Stanik.java | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules') 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 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 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 || -- cgit v1.2.3