Skip to content

Commit

Permalink
I removed AES encryption, because we have TLS sockets anyways. I will…
Browse files Browse the repository at this point in the history
… try to have index passed for level-site thing, but I can get numbers for all in one server though
  • Loading branch information
AndrewQuijano committed Oct 29, 2023
1 parent 0cde7d5 commit 8e4ddf2
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-gradle-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
env:
ALIAS: andrew
KEYSTORE: andrew_keystore
KEYSTORE: keystore
PASSWORD: ${{ secrets.PASSWORD }}

steps:
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/build-push-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ on:
jobs:
build:
runs-on: ubuntu-latest
env:
ALIAS: andrew
KEYSTORE: andrew_keystore
PASSWORD: ${{ secrets.PASSWORD }}

steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -27,7 +32,10 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}


- name: Create Key Store
run: sh create_keystore.sh

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

Expand Down
6 changes: 6 additions & 0 deletions k8/client/client_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ spec:

- name: GRADLE_USER_HOME
value: "gradle_user_home"

- name: KEYSTORE
value: "keystore"

- name: PASSWORD
value: 'helloworld'
6 changes: 6 additions & 0 deletions k8/server-deploy/server_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ spec:

- name: GRADLE_USER_HOME
value: "gradle_user_home"

- name: KEYSTORE
value: "keystore"

- name: PASSWORD
value: 'helloworld'
89 changes: 0 additions & 89 deletions src/main/java/weka/finito/AES.java

This file was deleted.

23 changes: 5 additions & 18 deletions src/main/java/weka/finito/client.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public final class client implements Runnable {
private KeyPair dgk;
private KeyPair paillier;
private Hashtable<String, BigIntegers> feature = null;
private String next_index = null;
private String iv = null;

private boolean classification_complete = false;
private String [] classes;

Expand All @@ -56,6 +55,7 @@ public final class client implements Runnable {
private final HashMap<String, String> hashed_classification = new HashMap<>();
private final String server_ip;
private final int server_port;
private Integer next_index = 0;

//For k8s deployment.
public static void main(String[] args) {
Expand Down Expand Up @@ -342,14 +342,7 @@ private void communicate_with_level_site(Socket level_site)
// Send bool:
// 1- true, there is an encrypted index coming
// 2- false, there is NO encrypted index coming
if (next_index == null) {
to_level_site.writeBoolean(false);
}
else {
to_level_site.writeBoolean(true);
to_level_site.writeObject(next_index);
to_level_site.writeObject(iv);
}
to_level_site.writeInt(next_index);
to_level_site.flush();

// Work with the comparison
Expand Down Expand Up @@ -377,21 +370,15 @@ else if (comparison_type == 1) {
// true - get leaf value
// false - get encrypted AES index for next round
classification_complete = from_level_site.readBoolean();
o = from_level_site.readObject();
if (classification_complete) {
o = from_level_site.readObject();
if (o instanceof String) {
classification = (String) o;
classification = hashed_classification.get(classification);
}
}
else {
if (o instanceof String) {
next_index = (String) o;
}
o = from_level_site.readObject();
if (o instanceof String) {
iv = (String) o;
}
next_index = from_level_site.readInt();
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/weka/finito/level_site_server.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class level_site_server implements Runnable {
protected level_order_site level_site_parameters = null;
protected int precision;

protected AES crypto;
protected SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();

public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException {
Expand All @@ -41,7 +40,7 @@ public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgo
System.out.println("AES_PASS is empty.");
System.exit(1);
}
level_site_server server = new level_site_server(our_port, our_precision, new AES(AES_Pass));
level_site_server server = new level_site_server(our_port, our_precision);
new Thread(server).start();
System.out.println("LEVEL SITE SERVER STARTED!");
while (true) {
Expand All @@ -54,10 +53,9 @@ public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgo
server.stop();
}

public level_site_server (int port, int precision, AES crypto) {
public level_site_server (int port, int precision) {
this.serverPort = port;
this.precision = precision;
this.crypto = crypto;
}

public void run() {
Expand All @@ -81,7 +79,7 @@ public void run() {
throw new RuntimeException("Error accepting client connection", e);
}
level_site_thread current_level_site_class = new level_site_thread(clientSocket,
this.level_site_parameters, this.crypto);
this.level_site_parameters);

level_order_site new_data = current_level_site_class.getLevelSiteParameters();
if (this.level_site_parameters == null) {
Expand Down
42 changes: 6 additions & 36 deletions src/main/java/weka/finito/level_site_thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ public class level_site_thread implements Runnable {
private level_order_site level_site_data = null;

private final Hashtable<String, BigIntegers> encrypted_features = new Hashtable<>();
private final AES crypto;

public level_site_thread(Socket client_socket, level_order_site level_site_data, AES crypto) {
public level_site_thread(Socket client_socket, level_order_site level_site_data) {
this.client_socket = client_socket;
this.crypto = crypto;

Object x;
try {
Expand Down Expand Up @@ -74,10 +71,8 @@ private void closeClientConnection() throws IOException {

// This will run the communication with client and next level site
public final void run() {
Object o;
String previous_index = null;
String iv = null;
boolean get_previous_index;

int get_previous_index;
long start_time = System.nanoTime();

try {
Expand All @@ -90,32 +85,12 @@ public final void run() {

niu.setDGKPublicKey(this.level_site_data.dgk_public_key);
niu.setPaillierPublicKey(this.level_site_data.paillier_public_key);
level_site_data.set_current_index(fromClient.readInt());

get_previous_index = fromClient.readBoolean();
if (get_previous_index) {
o = fromClient.readObject();
if (o instanceof String) {
previous_index = (String) o;
}
o = fromClient.readObject();
if (o instanceof String) {
iv = (String) o;
}
previous_index = crypto.decrypt(previous_index, iv);
}

// Level Data is the Node Data...
// it is set to 0 by default...
if (previous_index != null) {
this.level_site_data.set_current_index(Integer.parseInt(previous_index));
}

// Null, keep going down the tree,
// Null, keep going down the tree,
// Not null, you got the correct leaf node of your DT!
NodeInfo reply = traverse_level(level_site_data, encrypted_features, toClient, niu);

String encrypted_next_index;

// Place -1 to break Protocol4 loop
toClient.writeInt(-1);
toClient.flush();
Expand All @@ -126,13 +101,8 @@ public final void run() {
toClient.writeObject(reply.getVariableName());
}
else {

toClient.writeBoolean(false);
// encrypt with AES, send to the client which will send to next level-site
encrypted_next_index = crypto.encrypt(String.valueOf(this.level_site_data.get_next_index()));
iv = crypto.getIV();
toClient.writeObject(encrypted_next_index);
toClient.writeObject(iv);
toClient.writeInt(level_site_data.get_next_index());
}
long stop_time = System.nanoTime();
double run_time = (double) (stop_time - start_time);
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/PrivacyTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import org.junit.Before;
import org.junit.Test;
import weka.finito.AES;
import weka.finito.client;
import weka.finito.level_site_server;
import weka.finito.server;

import javax.crypto.NoSuchPaddingException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Properties;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -127,7 +124,7 @@ public void test_all_level_sites() throws Exception {
public static String test_level_site(String training_data, String features_file, int levels,
int key_size, int precision,
String [] level_site_ips, String [] level_site_ports_string, String server_ip, int server_port)
throws InterruptedException, NoSuchPaddingException, NoSuchAlgorithmException {
throws InterruptedException {

int [] level_site_ports = new int[levels];

Expand All @@ -136,8 +133,7 @@ public static String test_level_site(String training_data, String features_file,
for (int i = 0; i < level_sites.length; i++) {
String port_string = level_site_ports_string[i].replaceAll("[^0-9]", "");
level_site_ports[i] = Integer.parseInt(port_string);
level_sites[i] = new level_site_server(level_site_ports[i], precision,
new AES("AppSecSpring2023"));
level_sites[i] = new level_site_server(level_site_ports[i], precision);
new Thread(level_sites[i]).start();
}

Expand Down

0 comments on commit 8e4ddf2

Please sign in to comment.