m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/querysigner
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 /src/main/java/pl/edu/mimuw/cloudatlas/querysigner
parent81d1abbbad1f1e9c7774c7162b23fc804f7989a3 (diff)
Create simple query data structure so that RMI doesn't blow up
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/querysigner')
-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
3 files changed, 52 insertions, 28 deletions
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();
}
}