diff options
author | Magdalena Grodzińska <mag.grodzinska@gmail.com> | 2020-01-14 20:30:22 +0100 |
---|---|---|
committer | Magdalena Grodzińska <mag.grodzinska@gmail.com> | 2020-01-14 20:30:22 +0100 |
commit | 99b7023aba5c09f069badc35d05ea3ef53f3a6d2 (patch) | |
tree | 5e4559a79f5823d3927439c928c2d424fdb1ff70 /src/main/java/pl | |
parent | 3159df80ee02f6f65fe8e8ae1bae8fecb8fad070 (diff) |
Add query uninstall calls
Diffstat (limited to 'src/main/java/pl')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java | 5 | ||||
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java | 32 |
2 files changed, 24 insertions, 13 deletions
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 a2ac358..affad86 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java @@ -38,7 +38,7 @@ public class NewApiImplementation implements Api { StateMessage stateMessage = (StateMessage) response; Set<String> zones = new HashSet<String>(); collectZoneNames(stateMessage.getZMI(), zones); - return zones; + return zones; } else { System.out.println("ERROR: getZoneSet didn't receive a StateMessage"); throw new Exception("Failed to retrieve zone set"); @@ -92,8 +92,9 @@ public class NewApiImplementation implements Api { } public void uninstallQuery(String queryName, QueryData query) throws RemoteException { - QueryUtils.validateQueryName(queryName); try { + QueryUtils.validateQueryName(queryName); + QuerySignerApiImplementation.validateUninstallQuery(queryName, query, this.publicKey); Attribute attributeName = new Attribute(queryName); ValueTime timestamp = new ValueTime(System.currentTimeMillis()); Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap(); 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 3acaacf..3ab2931 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java @@ -75,16 +75,19 @@ public class QuerySignerApiImplementation implements QuerySignerApi { return digest; } - private static byte[] serializeQuery(String queryName, String queryCode) { + private static byte[] serializeQuery(String queryName, String queryCode, Boolean install) { ByteSerializer byteSerializer = new ByteSerializer(); - return byteSerializer.serialize(queryName + queryCode); + if (install) { + return byteSerializer.serialize(queryName + queryCode + install.toString()); + } else { + return byteSerializer.serialize(queryName + install.toString()); + } } - @Override - public QueryData signInstallQuery(String queryName, String queryCode) throws RemoteException { + private QueryData signQuery(String queryName, String queryCode, Boolean install) throws RemoteException { QueryUtils.validateQueryName(queryName); try { - byte[] serializedQuery = serializeQuery(queryName, queryCode); + byte[] serializedQuery = serializeQuery(queryName, queryCode, install); byte[] hashedQuery = cryptographicHash(serializedQuery); byte[] querySignature = encryptQuery(hashedQuery); return new QueryData(queryCode, querySignature); @@ -94,10 +97,19 @@ public class QuerySignerApiImplementation implements QuerySignerApi { } } + @Override + public QueryData signInstallQuery(String queryName, String queryCode) throws RemoteException { + return signQuery(queryName, queryCode, true); + } + public static void validateInstallQuery(String queryName, QueryData query, PublicKey publicKey) throws RemoteException,IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, QuerySigner.InvalidQueryException { + validateQuery(queryName, query, publicKey, true); + } + + public static void validateQuery(String queryName, QueryData query, PublicKey publicKey, boolean install) throws RemoteException,IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, QuerySigner.InvalidQueryException { QueryUtils.validateQueryName(queryName); byte[] decryptedQuery = decryptQuery(query.getSignature(), publicKey); - byte[] serializedQuery = serializeQuery(queryName, query.getCode()); + byte[] serializedQuery = serializeQuery(queryName, query.getCode(), install); byte[] hashedSerializedQuery = cryptographicHash(serializedQuery); String decryptedQueryString = byteArrayToString(decryptedQuery, 0, decryptedQuery.length); String hashedSerializedQueryString = byteArrayToString(hashedSerializedQuery, 0, hashedSerializedQuery.length); @@ -106,14 +118,12 @@ public class QuerySignerApiImplementation implements QuerySignerApi { } } - // TODO @Override public QueryData signUninstallQuery(String queryName) throws RemoteException { - return null; + return signQuery(queryName, "", false); } - // TODO - public static void validateUninstallQuery(String queryName, QueryData query, PublicKey publicKey) throws RemoteException { - + public static void validateUninstallQuery(String queryName, QueryData query, PublicKey publicKey) throws RemoteException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, QuerySigner.InvalidQueryException, NoSuchPaddingException, InvalidKeyException { + validateQuery(queryName, query, publicKey, false); } } |