diff --git a/src/main/java/dslab/client/IMessageClient.java b/src/main/java/dslab/client/IMessageClient.java index a7d0397..5b4c5a8 100644 --- a/src/main/java/dslab/client/IMessageClient.java +++ b/src/main/java/dslab/client/IMessageClient.java @@ -1,5 +1,8 @@ package dslab.client; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; + /** * A Message Client application. * @@ -16,7 +19,7 @@ public interface IMessageClient extends Runnable { /** * Outputs the contents of the user's inbox on the shell. */ - void inbox(); + void inbox() throws BadPaddingException, IllegalBlockSizeException; /** * Deletes the mail with the given id. Prints 'ok' if the mail was deleted successfully, 'error {explanation}' @@ -24,7 +27,7 @@ public interface IMessageClient extends Runnable { * * @param id the mail id */ - void delete(String id); + void delete(String id) throws BadPaddingException, IllegalBlockSizeException; /** * Verifies the signature of the message by calculating its hash value using the shared secret. Prints 'ok' if the diff --git a/src/main/java/dslab/client/MessageClient.java b/src/main/java/dslab/client/MessageClient.java index 80510d9..51b56ff 100644 --- a/src/main/java/dslab/client/MessageClient.java +++ b/src/main/java/dslab/client/MessageClient.java @@ -324,16 +324,51 @@ public class MessageClient implements IMessageClient, Runnable { @Command @Override - public void inbox() { + public void inbox() throws BadPaddingException, IllegalBlockSizeException { + String message; logger.info("Received 'inbox' command"); + message = "list"; + this.dmapOut.println(getAesCiphertext(message)); + try { + String response = getAesPlaintext(this.dmapIn.readLine()); + if (response.equals("ok DMAP2.0") || response.equals("ok DMAP")) { + this.dmapOut.println(getAesCiphertext(message)); + response = getAesPlaintext(this.dmapIn.readLine()); + } + String [] temp = response.split("\\s+"); + String [] help = new String[temp.length / 3]; + int count = 0; + for (int i = 0; i < help.length; i++) { + help[i] = temp[count]; + count = count + 3; + } + String result = ""; + for (int i = 0; i < help.length; i++) { + message = "show " + help[i]; + this.dmapOut.println(getAesCiphertext(message)); + result = getAesPlaintext(this.dmapIn.readLine() + "\n"); + } + System.out.println("Your Mailbox: \n" + result); + } catch (IOException e) { + System.out.println("IO Exception " + e.getMessage()); + } } @Command @Override - public void delete(String id) { + public void delete(String id) throws BadPaddingException, IllegalBlockSizeException { + String message; logger.info("Received 'delete' command for id " + id); - + message = "delete " + id; + this.dmapOut.println(getAesCiphertext(message)); + try { + String result = ""; + result = getAesPlaintext(dmapIn.readLine()); + System.out.println(result); + } catch (IOException e) { + System.out.println("IO Exception " + e.getMessage()); + } } /**