Skip to content

Commit

Permalink
Use Log4J logging
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewQuijano committed May 7, 2024
1 parent 0e70354 commit fe138a0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
9 changes: 7 additions & 2 deletions src/main/java/BobThread.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,7 +46,7 @@ public void run() {
}
}
catch (IOException | ClassNotFoundException | HomomorphicException e) {
e.printStackTrace();
logger.fatal(e.getStackTrace());
}
finally {
try {
Expand All @@ -52,7 +57,7 @@ public void run() {
bob_socket.close();
}
} catch (IOException e) {
e.printStackTrace();
logger.fatal(e.getStackTrace());
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/EncryptedPathsComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/PathsAlice.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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());
}
}
}
26 changes: 11 additions & 15 deletions src/main/java/PathsBob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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();
}


Expand All @@ -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();

Expand Down Expand Up @@ -114,17 +108,19 @@ 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();
}
if (bob_socket != null) {
bob_socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
catch (IOException e) {
logger.fatal(e.getStackTrace());
}
}
}
Expand Down

0 comments on commit fe138a0

Please sign in to comment.