diff --git a/src/main/java/BobThread.java b/src/main/java/BobThread.java index af4831e..927654b 100644 --- a/src/main/java/BobThread.java +++ b/src/main/java/BobThread.java @@ -1,11 +1,16 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import security.misc.HomomorphicException; import security.socialistmillionaire.bob_joye; public class BobThread implements Runnable { + private static final Logger logger = LogManager.getLogger(BobThread.class); + private final int port; private static ServerSocket bob_socket = null; private static Socket bob_client = null; @@ -41,7 +46,7 @@ public void run() { } } catch (IOException | ClassNotFoundException | HomomorphicException e) { - e.printStackTrace(); + logger.fatal(e.getStackTrace()); } finally { try { @@ -52,7 +57,7 @@ public void run() { bob_socket.close(); } } catch (IOException e) { - e.printStackTrace(); + logger.fatal(e.getStackTrace()); } } } diff --git a/src/main/java/EncryptedPathsComparison.java b/src/main/java/EncryptedPathsComparison.java index a1dea65..5cc7b97 100644 --- a/src/main/java/EncryptedPathsComparison.java +++ b/src/main/java/EncryptedPathsComparison.java @@ -97,8 +97,7 @@ public int encryptedOrientation(BigIntPoint p, BigIntPoint q, BigIntPoint r, Pai } catch (HomomorphicException | IOException | ClassNotFoundException a) { - System.err.println("Exception in encryptedOrientation: " + a.getMessage()); - a.printStackTrace(); + logger.fatal(a.getStackTrace()); throw new RuntimeException(a); } } diff --git a/src/main/java/PathsAlice.java b/src/main/java/PathsAlice.java index 8e8c4ee..dffec96 100644 --- a/src/main/java/PathsAlice.java +++ b/src/main/java/PathsAlice.java @@ -1,3 +1,5 @@ +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import security.misc.HomomorphicException; import security.paillier.PaillierCipher; import security.socialistmillionaire.alice_joye; @@ -11,6 +13,8 @@ import java.util.List; public class PathsAlice { + private static final Logger logger = LogManager.getLogger(PathsAlice.class); + private final int port; public PathsAlice(int port) { @@ -73,7 +77,7 @@ public static void main(String[] args) { System.out.println(result); } catch (IOException | ClassNotFoundException | HomomorphicException e){ - e.printStackTrace(); + logger.fatal(e.getStackTrace()); } } } diff --git a/src/main/java/PathsBob.java b/src/main/java/PathsBob.java index 6b0b3ba..cb85349 100644 --- a/src/main/java/PathsBob.java +++ b/src/main/java/PathsBob.java @@ -6,6 +6,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import security.dgk.DGKKeyPairGenerator; import security.dgk.DGKOperations; import security.dgk.DGKPrivateKey; @@ -18,19 +20,15 @@ import security.socialistmillionaire.bob_joye; public class PathsBob { + private static final Logger logger = LogManager.getLogger(PathsBob.class); - private int port; private static ServerSocket bob_socket = null; private static Socket bob_client = null; private KeyPair paillier; private KeyPair dgk; - private DGKPublicKey dgk_public_key; - private DGKPrivateKey dgk_private_key; private PaillierPublicKey paillier_public_key; - private PaillierPrivateKey paillier_private_key; - public PathsBob(int port, int key_size) { - this.port = port; + public PathsBob(int key_size) { generate_keys(key_size); } @@ -45,11 +43,7 @@ public void generate_keys(int key_size) { PaillierKeyPairGenerator pa = new PaillierKeyPairGenerator(); pa.initialize(key_size, null); paillier = pa.generateKeyPair(); - - dgk_public_key = (DGKPublicKey) dgk.getPublic(); paillier_public_key = (PaillierPublicKey) paillier.getPublic(); - dgk_private_key = (DGKPrivateKey) dgk.getPrivate(); - paillier_private_key = (PaillierPrivateKey) paillier.getPrivate(); } @@ -70,7 +64,7 @@ public static void main(String[] args) { System.exit(1); } - PathsBob iam = new PathsBob(port,2048); + PathsBob iam = new PathsBob(2048); bob_joye bob = new bob_joye(iam.paillier, iam.dgk); String my_path = new File(input_file).toString(); @@ -114,8 +108,9 @@ public static void main(String[] args) { } } catch (IOException | ClassNotFoundException | HomomorphicException e) { - e.printStackTrace(); - } finally { + logger.fatal(e.getStackTrace()); + } + finally { try { if (bob_client != null) { bob_client.close(); @@ -123,8 +118,9 @@ public static void main(String[] args) { if (bob_socket != null) { bob_socket.close(); } - } catch (IOException e) { - e.printStackTrace(); + } + catch (IOException e) { + logger.fatal(e.getStackTrace()); } } }