Skip to content

Commit

Permalink
Added ObjectInputValidating Stream. Now I need to see how to pass fea…
Browse files Browse the repository at this point in the history
…tures down the chain of level-sites
  • Loading branch information
AndrewQuijano committed Jan 15, 2024
1 parent 4837d9d commit a8fcb70
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 27 deletions.
16 changes: 0 additions & 16 deletions classes.txt

This file was deleted.

Binary file removed dgk
Binary file not shown.
Binary file removed dgk.pub
Binary file not shown.
Binary file removed paillier
Binary file not shown.
Binary file removed paillier.pub
Binary file not shown.
5 changes: 3 additions & 2 deletions src/main/java/weka/finito/client.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashMap;
import java.lang.System;

import org.apache.commons.io.serialization.ValidatingObjectInputStream;
import security.dgk.DGKKeyPairGenerator;
import security.dgk.DGKOperations;
import security.dgk.DGKPrivateKey;
Expand Down Expand Up @@ -231,7 +232,7 @@ private void setup_with_server_site(PaillierPublicKey paillier, DGKPublicKey dgk
server_site.startHandshake();

ObjectOutputStream to_server_site = new ObjectOutputStream(server_site.getOutputStream());
ObjectInputStream from_server_site = new ObjectInputStream(server_site.getInputStream());
ValidatingObjectInputStream from_server_site = get_ois(server_site);

// Receive a message from the client to get their keys
to_server_site.writeObject(paillier);
Expand Down Expand Up @@ -332,7 +333,7 @@ private void communicate_with_level_site(Socket level_site)

// Create I/O streams
ObjectOutputStream to_level_site = new ObjectOutputStream(level_site.getOutputStream());
ObjectInputStream from_level_site = new ObjectInputStream(level_site.getInputStream());
ValidatingObjectInputStream from_level_site = get_ois(level_site);

// Send the encrypted data to Level-Site
to_level_site.writeObject(this.feature);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/weka/finito/level_site_server.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package weka.finito;

import org.apache.commons.io.serialization.ValidatingObjectInputStream;
import weka.finito.structs.level_order_site;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
import java.io.IOException;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import java.lang.System;
Expand Down Expand Up @@ -58,7 +57,7 @@ public void run() {
this.runningThread = Thread.currentThread();
}
openServerSocket();
ObjectInputStream ois;
ValidatingObjectInputStream ois;
ObjectOutputStream oos;
Object o;

Expand All @@ -79,7 +78,7 @@ public void run() {
// Collect the object, and see what to do depending on the object.
try {
oos = new ObjectOutputStream(client_socket.getOutputStream());
ois = new ObjectInputStream(client_socket.getInputStream());
ois = get_ois(client_socket);
o = ois.readObject();
if (o instanceof level_order_site) {
// Traffic from Server, collect the level-site data
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/weka/finito/server.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package weka.finito;

import java.io.File;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
Expand All @@ -14,6 +13,7 @@
import java.lang.System;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.serialization.ValidatingObjectInputStream;
import security.dgk.DGKPublicKey;
import security.misc.HomomorphicException;
import security.socialistmillionaire.alice_joye;
Expand Down Expand Up @@ -158,7 +158,7 @@ private void evaluate_with_client_directly(SSLSocket client_site)
Niu.setDGKPublicKey(dgk_public);

// Get encrypted features
ObjectInputStream ois = new ObjectInputStream(client_site.getInputStream());
ValidatingObjectInputStream ois = get_ois(client_site);
client_input = ois.readObject();
if (client_input instanceof HashMap) {
for (Entry<?, ?> entry: ((HashMap<?, ?>) client_input).entrySet()){
Expand Down Expand Up @@ -209,7 +209,7 @@ private void client_communication() throws Exception {
client_site.startHandshake();

ObjectOutputStream to_client_site = new ObjectOutputStream(client_site.getOutputStream());
ObjectInputStream from_client_site = new ObjectInputStream(client_site.getInputStream());
ValidatingObjectInputStream from_client_site = get_ois(client_site);

// Receive a message from the client to get their keys
Object o = from_client_site.readObject();
Expand Down Expand Up @@ -499,7 +499,7 @@ public void run() {

private void train_level_sites() {
ObjectOutputStream to_level_site;
ObjectInputStream from_level_site;
ValidatingObjectInputStream from_level_site;
int connection_port;

// There should be at least 1 IP Address for each level site
Expand Down Expand Up @@ -537,7 +537,7 @@ private void train_level_sites() {

System.out.println("training level-site " + i + " on port:" + connection_port);
to_level_site = new ObjectOutputStream(level_site.getOutputStream());
from_level_site = new ObjectInputStream(level_site.getInputStream());
from_level_site = get_ois(level_site);
to_level_site.writeObject(current_level_site);
if(from_level_site.readBoolean()) {
System.out.println("Training Successful on port:" + connection_port);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/weka/finito/utils/shared.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package weka.finito.utils;

import org.apache.commons.io.serialization.ValidatingObjectInputStream;
import security.misc.HomomorphicException;
import security.socialistmillionaire.alice;
import weka.finito.structs.BigIntegers;
Expand Down Expand Up @@ -174,4 +175,25 @@ public static void closeConnection(ObjectOutputStream oos,
client_socket.close();
}
}

public static ValidatingObjectInputStream get_ois(Socket socket) throws IOException {
ValidatingObjectInputStream ois = new ValidatingObjectInputStream(socket.getInputStream());
ois.accept(
weka.finito.structs.NodeInfo.class,
weka.finito.structs.level_order_site.class,
weka.finito.structs.BigIntegers.class,

java.util.HashMap.class,
java.lang.String.class,
security.paillier.PaillierPublicKey.class,
security.dgk.DGKPublicKey.class,

java.lang.Number.class,
java.math.BigInteger.class,
java.lang.Long.class
);
ois.accept("[B");
ois.accept("[L*");
return ois;
}
}

0 comments on commit a8fcb70

Please sign in to comment.