m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-13 20:56:41 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-13 20:56:41 +0100
commit23b8714b29816b608cb3aa330b6e93610e107126 (patch)
tree4cb9bf4d64ec1d2987ec4b44692fdd42280ab91d
parent81d1abbbad1f1e9c7774c7162b23fc804f7989a3 (diff)
Create simple query data structure so that RMI doesn't blow up
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java7
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java7
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/api/Api.java5
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java5
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java9
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java26
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySigner.java20
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java34
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/querysignerapi/QuerySignerApi.java17
9 files changed, 80 insertions, 50 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java
index e9dbb7e..90e7789 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java
@@ -28,6 +28,7 @@ import pl.edu.mimuw.cloudatlas.model.Type;
import pl.edu.mimuw.cloudatlas.model.TypePrimitive;
import pl.edu.mimuw.cloudatlas.model.ZMI;
import pl.edu.mimuw.cloudatlas.api.Api;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryData;
import pl.edu.mimuw.cloudatlas.querysigner.QueryUtils;
public class ApiImplementation implements Api {
@@ -61,11 +62,11 @@ public class ApiImplementation implements Api {
}
}
- public void installQuery(String name, ValueQuery query) throws RemoteException {
+ public void installQuery(String name, QueryData query) throws RemoteException {
QueryUtils.validateQueryName(name);
try {
Attribute attributeName = new Attribute(name);
- installQueryInHierarchy(root, attributeName, query);
+ installQueryInHierarchy(root, attributeName, new ValueQuery(query));
executeAllQueries(root);
} catch (Exception e) {
throw new RemoteException("Failed to install query", e);
@@ -81,7 +82,7 @@ public class ApiImplementation implements Api {
}
}
- public void uninstallQuery(String queryName, ValueQuery query) throws RemoteException {
+ public void uninstallQuery(String queryName, QueryData query) throws RemoteException {
QueryUtils.validateQueryName(queryName);
uninstallQueryInHierarchy(root, new Attribute(queryName));
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
index bf75210..0bf4338 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java
@@ -22,6 +22,7 @@ import pl.edu.mimuw.cloudatlas.interpreter.Main;
import pl.edu.mimuw.cloudatlas.interpreter.QueryResult;
import pl.edu.mimuw.cloudatlas.model.*;
import pl.edu.mimuw.cloudatlas.api.Api;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryData;
import pl.edu.mimuw.cloudatlas.querysigner.QueryUtils;
public class NewApiImplementation implements Api {
@@ -80,13 +81,13 @@ public class NewApiImplementation implements Api {
}
}
- public void installQuery(String name, ValueQuery query) throws RemoteException {
+ public void installQuery(String name, QueryData query) throws RemoteException {
QueryUtils.validateQueryName(name);
try {
Attribute attributeName = new Attribute(name);
ValueTime timestamp = new ValueTime(System.currentTimeMillis());
Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap();
- queries.put(attributeName, new SimpleImmutableEntry(query, timestamp));
+ queries.put(attributeName, new SimpleImmutableEntry(new ValueQuery(query), timestamp));
UpdateQueriesMessage message = new UpdateQueriesMessage("", 0, queries);
eventBus.addMessage(message);
} catch (Exception e) {
@@ -94,7 +95,7 @@ public class NewApiImplementation implements Api {
}
}
- public void uninstallQuery(String queryName, ValueQuery query) throws RemoteException {
+ public void uninstallQuery(String queryName, QueryData query) throws RemoteException {
QueryUtils.validateQueryName(queryName);
try {
Attribute attributeName = new Attribute(queryName);
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/api/Api.java b/src/main/java/pl/edu/mimuw/cloudatlas/api/Api.java
index 2936b13..7cc629d 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/api/Api.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/api/Api.java
@@ -7,6 +7,7 @@ import pl.edu.mimuw.cloudatlas.model.Value;
import pl.edu.mimuw.cloudatlas.model.ValueContact;
import pl.edu.mimuw.cloudatlas.model.AttributesMap;
import pl.edu.mimuw.cloudatlas.model.ValueQuery;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryData;
/**
*
@@ -28,9 +29,9 @@ public interface Api extends Remote {
public AttributesMap getZoneAttributeValues(String zoneName) throws RemoteException;
- public void installQuery(String queryName, ValueQuery query) throws RemoteException;
+ public void installQuery(String queryName, QueryData query) throws RemoteException;
- public void uninstallQuery(String queryName, ValueQuery query) throws RemoteException;
+ public void uninstallQuery(String queryName, QueryData query) throws RemoteException;
public void setAttributeValue(String zoneName, String attributeName, Value value) throws RemoteException;
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
index 56b478c..5f34fe9 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import pl.edu.mimuw.cloudatlas.api.Api;
import pl.edu.mimuw.cloudatlas.model.*;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryData;
import pl.edu.mimuw.cloudatlas.querysignerapi.QuerySignerApi;
import java.net.InetAddress;
@@ -79,7 +80,7 @@ public class ClientController {
boolean success = true;
try {
- ValueQuery query = this.querySignerApi.signInstallQuery(queryObject.getName(), queryObject.getValue());
+ QueryData query = this.querySignerApi.signInstallQuery(queryObject.getName(), queryObject.getValue());
this.agentApi.installQuery(queryObject.getName(), query);
} catch (Exception e) {
success = false;
@@ -105,7 +106,7 @@ public class ClientController {
boolean success = true;
try {
- ValueQuery query = querySignerApi.signUninstallQuery(queryObject.getName());
+ QueryData query = querySignerApi.signUninstallQuery(queryObject.getName());
this.agentApi.uninstallQuery(queryObject.getName(), query);
} catch (Exception e) {
success = false;
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java
index 6839e4c..ece50b5 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java
@@ -6,6 +6,7 @@ import pl.edu.mimuw.cloudatlas.interpreter.query.Absyn.Program;
import pl.edu.mimuw.cloudatlas.interpreter.query.parser;
import pl.edu.mimuw.cloudatlas.interpreter.query.Yylex;
import pl.edu.mimuw.cloudatlas.model.Value;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryData;
/**
* A class that holds a CloudAtlas query.
@@ -41,6 +42,14 @@ public class ValueQuery extends Value {
this.timestamp = System.currentTimeMillis();
}
+ public ValueQuery(QueryData queryData) throws Exception {
+ this.code = queryData.getCode();
+ Yylex lex = new Yylex(new ByteArrayInputStream(queryData.getCode().getBytes()));
+ this.query = (new parser(lex)).pProgram();
+ this.signature = queryData.getSignature();
+ this.timestamp = System.currentTimeMillis();
+ }
+
private ValueQuery() {
this.code = null;
this.query = 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 a09c823..7a85d7c 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java
@@ -1,4 +1,30 @@
package pl.edu.mimuw.cloudatlas.querysigner;
+import pl.edu.mimuw.cloudatlas.interpreter.query.Absyn.Program;
+
public class QueryData {
+ // Original source code
+ private String code;
+ // Query signature
+ private byte[] signature;
+ // Query signing timestamp
+ private long timestamp;
+
+ public QueryData(String code, byte[] signature) {
+ this.code = code;
+ this.signature = signature;
+ this.timestamp = System.currentTimeMillis();;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public byte[] getSignature() {
+ return signature;
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySigner.java b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySigner.java
index 90a86b7..d60a75d 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySigner.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySigner.java
@@ -1,10 +1,16 @@
package pl.edu.mimuw.cloudatlas.querysigner;
+import pl.edu.mimuw.cloudatlas.KeyGenerator;
+import pl.edu.mimuw.cloudatlas.agent.NewApiImplementation;
+import pl.edu.mimuw.cloudatlas.api.Api;
import pl.edu.mimuw.cloudatlas.querysignerapi.QuerySignerApi;
+import java.io.IOException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
+import java.security.PrivateKey;
+import java.security.PublicKey;
public class QuerySigner {
public static class InvalidQueryException extends Exception {
@@ -13,12 +19,18 @@ public class QuerySigner {
}
}
+ private static QuerySignerApiImplementation initApi() throws IOException {
+ String publicKeyFile = System.getProperty("public_key_file");
+ String privateKeyFile = System.getProperty("private_key_file");
+ PublicKey publicKey = null; //KeyGenerator.getPublicKey(KeyGenerator.readKeyFromFile(publicKeyFile));
+ PrivateKey privateKey = null; // KeyGenerator.getPrivateKey(KeyGenerator.readKeyFromFile(privateKeyFile));
+ return new QuerySignerApiImplementation(publicKey, privateKey);
+ }
+
public static void runRegistry() {
try {
- // TODO reading from files
- String publicKey = System.getProperty("public_key");
- String privateKey = System.getProperty("private_key");
- QuerySignerApiImplementation api = new QuerySignerApiImplementation(publicKey.getBytes(), privateKey.getBytes());
+ QuerySignerApiImplementation api = initApi();
+// NewApiImplementation apii = new NewApiImplementation(null);
QuerySignerApi apiStub =
(QuerySignerApi) UnicastRemoteObject.exportObject(api, 0);
Registry registry = LocateRegistry.getRegistry();
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java
index d1c0e7c..32bc634 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java
@@ -10,7 +10,6 @@ import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.rmi.RemoteException;
import java.security.*;
-import java.security.interfaces.RSAPrivateCrtKey;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -25,10 +24,12 @@ public class QuerySignerApiImplementation implements QuerySignerApi {
private Set<String> attribsSetByQueries;
private ByteSerializer byteSerializer;
- QuerySignerApiImplementation(byte[] serializedPublicKey, byte[] serializedPrivateKey) {
+ QuerySignerApiImplementation(PublicKey publicKey, PrivateKey privateKey) {// (byte[] serializedPublicKey, byte[] serializedPrivateKey) {
this.byteSerializer = new ByteSerializer();
- this.publicKey = (PublicKey) byteSerializer.deserialize(serializedPublicKey, PublicKey.class);
- this.privateKey = (PrivateKey) byteSerializer.deserialize(serializedPrivateKey, PrivateKey.class);
+// this.publicKey = (PublicKey) byteSerializer.deserialize(serializedPublicKey, PublicKey.class);
+// this.privateKey = (PrivateKey) byteSerializer.deserialize(serializedPrivateKey, PrivateKey.class);
+ this.publicKey = publicKey;
+ this.privateKey = privateKey;
this.queries = new HashMap<>();
this.attribsSetByQueries = new HashSet<>();
}
@@ -84,13 +85,13 @@ public class QuerySignerApiImplementation implements QuerySignerApi {
}
@Override
- public ValueQuery signInstallQuery(String queryName, String queryCode) throws RemoteException {
+ public QueryData signInstallQuery(String queryName, String queryCode) throws RemoteException {
QueryUtils.validateQueryName(queryName);
try {
byte[] serializedQuery = serializeQuery(queryName, queryCode);
byte[] hashedQuery = cryptographicHash(serializedQuery);
byte[] querySignature = encryptQuery(hashedQuery);
- return new ValueQuery(queryCode, querySignature);
+ return new QueryData(queryCode, querySignature);
} catch (Exception e) {
e.printStackTrace();
throw new RemoteException(e.getLocalizedMessage());
@@ -98,7 +99,7 @@ public class QuerySignerApiImplementation implements QuerySignerApi {
}
@Override
- public void validateInstallQuery(String queryName, ValueQuery query) throws RemoteException {
+ public void validateInstallQuery(String queryName, QueryData query) throws RemoteException {
QueryUtils.validateQueryName(queryName);
try {
byte[] decryptedQuery = decryptQuery(query.getSignature());
@@ -115,28 +116,13 @@ public class QuerySignerApiImplementation implements QuerySignerApi {
// TODO
@Override
- public ValueQuery signUninstallQuery(String queryName) throws RemoteException {
+ public QueryData signUninstallQuery(String queryName) throws RemoteException {
return null;
}
// TODO
@Override
- public void validateUninstallQuery(String queryName, ValueQuery query) throws RemoteException {
-
- }
-
- @Override
- public PublicKey getPublicKey() throws RemoteException {
- return publicKey;
- }
+ public void validateUninstallQuery(String queryName, QueryData query) throws RemoteException {
- @Override
- public void setPublicKey(PublicKey publicKey) throws RemoteException {
- this.publicKey = publicKey;
- }
-
- @Override
- public byte[] getQuerySignature(String queryName) throws RemoteException {
- return queries.get(queryName).getSignature();
}
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/querysignerapi/QuerySignerApi.java b/src/main/java/pl/edu/mimuw/cloudatlas/querysignerapi/QuerySignerApi.java
index fa46da3..6b42d32 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/querysignerapi/QuerySignerApi.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/querysignerapi/QuerySignerApi.java
@@ -1,23 +1,16 @@
package pl.edu.mimuw.cloudatlas.querysignerapi;
-import pl.edu.mimuw.cloudatlas.model.ValueQuery;
+import pl.edu.mimuw.cloudatlas.querysigner.QueryData;
import java.rmi.Remote;
import java.rmi.RemoteException;
-import java.security.PublicKey;
public interface QuerySignerApi extends Remote {
- public ValueQuery signInstallQuery(String queryName, String queryCode) throws RemoteException;
+ public QueryData signInstallQuery(String queryName, String queryCode) throws RemoteException;
- public ValueQuery signUninstallQuery(String queryName) throws RemoteException;
+ public QueryData signUninstallQuery(String queryName) throws RemoteException;
- public void validateInstallQuery(String queryName, ValueQuery query) throws RemoteException;
+ public void validateInstallQuery(String queryName, QueryData query) throws RemoteException;
- public void validateUninstallQuery(String queryName, ValueQuery query) throws RemoteException;
-
- public PublicKey getPublicKey() throws RemoteException;
-
- public void setPublicKey(PublicKey publicKey) throws RemoteException;
-
- public byte[] getQuerySignature(String queryName) throws RemoteException;
+ public void validateUninstallQuery(String queryName, QueryData query) throws RemoteException;
}