|
@@ -1,26 +1,24 @@
|
|
|
package dslab.client;
|
|
|
|
|
|
+import dslab.ComponentFactory;
|
|
|
+import dslab.enums.Outcome;
|
|
|
+import dslab.util.*;
|
|
|
+
|
|
|
+import javax.crypto.*;
|
|
|
import java.io.*;
|
|
|
import java.net.Socket;
|
|
|
-import java.net.UnknownHostException;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
-import java.rmi.NotBoundException;
|
|
|
-import java.rmi.RemoteException;
|
|
|
import java.security.InvalidAlgorithmParameterException;
|
|
|
import java.security.InvalidKeyException;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
-import java.util.*;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.NoSuchElementException;
|
|
|
+import java.util.Scanner;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
-import dslab.ComponentFactory;
|
|
|
-import dslab.enums.Outcome;
|
|
|
-import dslab.util.*;
|
|
|
-
|
|
|
-import javax.crypto.*;
|
|
|
-
|
|
|
public class MessageClient implements IMessageClient, Runnable {
|
|
|
|
|
|
// configuration keys that have to be present
|
|
@@ -131,9 +129,9 @@ public class MessageClient implements IMessageClient, Runnable {
|
|
|
dmapWriter.flush();
|
|
|
|
|
|
// present the raw data to the user
|
|
|
- System.out.printf("%n%s%n", id);
|
|
|
+ out.printf("%n%s%n", id);
|
|
|
while (!(line = dmapReader.readLine()).startsWith("ok"))
|
|
|
- System.out.println(line);
|
|
|
+ out.println(line);
|
|
|
}
|
|
|
} catch (IOException | DMAPProtocolException exception) {
|
|
|
System.err.printf("@%s: there was an error querying your inbox%n", componentId);
|
|
@@ -149,7 +147,7 @@ public class MessageClient implements IMessageClient, Runnable {
|
|
|
dmapWriter.flush();
|
|
|
|
|
|
// check result
|
|
|
- System.out.println(dmapReader.readLine());
|
|
|
+ out.println(dmapReader.readLine());
|
|
|
} catch (IOException exception) {
|
|
|
System.err.printf("@%s: there was an error deleting mail %s%n", componentId, id);
|
|
|
}
|
|
@@ -176,14 +174,14 @@ public class MessageClient implements IMessageClient, Runnable {
|
|
|
message.fill(line);
|
|
|
} while (!(line = dmapReader.readLine()).startsWith("ok"));
|
|
|
|
|
|
- System.out.println(message);
|
|
|
+ out.println(message);
|
|
|
if (message.hash == null) {
|
|
|
System.err.printf("error hash is not set for this message%n", componentId);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
boolean success = CryptoUtil.verifyHash(message, hmac);
|
|
|
- System.out.printf(
|
|
|
+ out.printf(
|
|
|
"%s message integrity %ssuccessfully verified%n",
|
|
|
success ? "ok" : "error",
|
|
|
success ? "" : "un-"
|
|
@@ -224,9 +222,9 @@ public class MessageClient implements IMessageClient, Runnable {
|
|
|
|
|
|
// notify user of what has transpired
|
|
|
if (outcome != Outcome.Success)
|
|
|
- System.err.printf("error %s%n", outcome.getMessage());
|
|
|
+ out.printf("error %s%n", outcome.getMessage());
|
|
|
else
|
|
|
- System.out.printf("ok%n");
|
|
|
+ out.printf("ok%n");
|
|
|
}
|
|
|
|
|
|
@Override
|