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/edu/mimuw/cloudatlas/querysigner | |
parent | 3159df80ee02f6f65fe8e8ae1bae8fecb8fad070 (diff) |
Add query uninstall calls
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/querysigner')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java | 32 |
1 files changed, 21 insertions, 11 deletions
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); } } |