Skip to content

Commit

Permalink
I forgot I need the client to also remember the classes too not just …
Browse files Browse the repository at this point in the history
…the keys
  • Loading branch information
AndrewQuijano committed Jun 21, 2023
1 parent 3ba3231 commit a1a1496
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/main/java/weka/finito/client.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.security.KeyPair;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.Hashtable;
Expand All @@ -26,6 +27,7 @@
import weka.finito.structs.BigIntegers;

public final class client implements Runnable {
private final String classes_file = "classes.txt";
private final String features_file;
private final int key_size;
private final int precision;
Expand Down Expand Up @@ -165,11 +167,36 @@ private boolean need_keys() {
paillier_private_key = PaillierPrivateKey.readKey("paillier");
dgk = new KeyPair(dgk_public_key, dgk_private_key);
paillier = new KeyPair(paillier_public_key, paillier_private_key);
classes = read_classes();
for (String aClass : classes) {
hashed_classification.put(hash(aClass), aClass);
}
return false;
}
catch (RuntimeException e) {
return true;
}
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

private String [] read_classes() {
// Don't forget to remember the classes of DT as well
StringBuilder content = new StringBuilder();
String line;

try (BufferedReader reader =
new BufferedReader(new FileReader(classes_file))) {
while ((line = reader.readLine()) != null) {
content.append(line);
content.append(System.lineSeparator());
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
return content.toString().split(System.lineSeparator());
}

// Used for set-up
Expand Down Expand Up @@ -383,5 +410,16 @@ public void run() {
paillier_public_key.writeKey("paillier.pub");
dgk_private_key.writeKey("dgk");
paillier_private_key.writeKey("paillier");

// Remember the classes as well too...
try (BufferedWriter writer = new BufferedWriter(new FileWriter(classes_file, true))) {
for (String aClass: classes) {
writer.write(aClass);
writer.write("\n");
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/PrivacyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class PrivacyTest {
private String data_directory;
private int server_port;
private String server_ip;
private final static String [] delete_files = {"dgk", "dgk.pub", "paillier", "paillier.pub"};
private final static String [] delete_files = {"dgk", "dgk.pub", "paillier", "paillier.pub", "classes.txt"};
@Before
public void read_properties() throws IOException {
// Arguments:
Expand Down

0 comments on commit a1a1496

Please sign in to comment.