Skip to content

Commit

Permalink
Use validating stream
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewQuijano committed May 7, 2024
1 parent fe138a0 commit 0794c90
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/main/java/BigIntPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ public class BigIntPoint implements Serializable
BigInteger x;
BigInteger y;

public BigIntPoint(BigInteger x, BigInteger y)
{
public BigIntPoint(BigInteger x, BigInteger y) {
this.x = x;
this.y = y;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/EncryptedPathsComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public boolean encryptedOnSegment (BigIntPoint p, BigIntPoint q, BigIntPoint r)

z = a && b && c && d;

} catch (HomomorphicException | IOException | ClassNotFoundException e){
}
catch (HomomorphicException | IOException | ClassNotFoundException e){
System.err.println("Exception in OnSegment" + e.getMessage());
}

return z;
}

Expand Down
18 changes: 16 additions & 2 deletions src/main/java/PathsAlice.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.apache.commons.io.serialization.ValidatingObjectInputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import security.misc.HomomorphicException;
Expand All @@ -6,7 +7,6 @@

import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.math.BigInteger;
import java.net.Socket;
import java.util.ArrayList;
Expand Down Expand Up @@ -51,7 +51,7 @@ public static void main(String[] args) {
Socket socket = new Socket (ip_address, pathsalice.port);
alice.set_socket(socket);
alice.receivePublicKeys();
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
ValidatingObjectInputStream input = get_ois(socket);
Object object = input.readObject();

if (object instanceof List<?>) {
Expand Down Expand Up @@ -80,4 +80,18 @@ public static void main(String[] args) {
logger.fatal(e.getStackTrace());
}
}

public static ValidatingObjectInputStream get_ois(Socket socket) throws IOException {
ValidatingObjectInputStream ois = new ValidatingObjectInputStream(socket.getInputStream());
ois.accept(
java.util.List.class,
BigIntPoint.class,
java.lang.Number.class,
java.math.BigInteger.class
);
ois.accept("[B");
ois.accept("[L*");
return ois;
}

}
21 changes: 13 additions & 8 deletions src/test/java/IntersectTest.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 org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
Expand All @@ -21,6 +23,7 @@
import java.util.List;

public class IntersectTest {
private static final Logger logger = LogManager.getLogger(IntersectTest.class);

private static KeyPair dgk = null;
private static KeyPair paillier = null;
Expand Down Expand Up @@ -69,11 +72,11 @@ public void encrypted_test_intersections() {
System.out.println("Reading the file: " + ownroute);
boolean will_collide = Boolean.parseBoolean(expected_result);

//Parsing routes
// Parsing routes
List<BigIntPoint> ownroute_list = CleartextPathsComparison.read_all_paths(ownroute);
List<BigIntPoint> cryptroute_list = CleartextPathsComparison.read_all_paths(cryptroute);

//encrypt routes
// Encrypt routes
List<BigIntPoint> encryptedownroute_list = new ArrayList<>();
List<BigIntPoint> encryptedcryptroute_list = new ArrayList<>();

Expand Down Expand Up @@ -111,7 +114,7 @@ public void encrypted_test_intersections() {
}
}
catch (IOException | ClassNotFoundException | HomomorphicException | InterruptedException e) {
System.err.println("Error reading files" + e.getMessage());
logger.fatal(e.getStackTrace());
}
}

Expand All @@ -129,12 +132,14 @@ public static Socket connectWithRetry(String host, int port) {
// Connection refused, print a message and retry after a delay
System.out.println("Connection refused. Retrying in 1 second...");
try {
Thread.sleep(1000); // Wait for 5 seconds before retrying
} catch (InterruptedException ex) {
ex.printStackTrace();
Thread.sleep(1000); // Wait for 1 second before retrying
}
catch (InterruptedException ex) {
logger.info(ex.getStackTrace());
}
} catch (Exception e) {
e.printStackTrace();
}
catch (Exception e) {
logger.fatal(e.getStackTrace());
}
}
}
Expand Down

0 comments on commit 0794c90

Please sign in to comment.