public void run(String[] args) {
OptionParser parser = new OptionParser();
OptionSet options = parser.parse(args);
String path = options.nonOptionArguments().get(1);
OverEncryptClient client = new OverEncryptClient();
String folderName = null;
Boolean hasSEL = false;
String usersSelected = null;
String nextToken = "";
boolean destinationACLReached = false;
boolean result3 = false;
boolean firstAesKey = true;
if (path.contains(Configuration.URL_WEBDAV_SERVER + "/Shared")) {
// TODO Error
return;
}
String owner = null;
String passphrase = null;
LocalPrivateResource lpr = new LocalPrivateResource();
try {
owner = lpr.get("UserInfo", "userId");
passphrase = lpr.get("UserInfo", "pin");
passphrase = SecurityAlgorithms.decryptAES(passphrase);
} catch (Exception e) {
// TODO ??
}
Response resp = client.sendAndWait(
ClientPrimitives.OE_UPLMANAGER_FOLDER, path, owner,
usersSelected, path, folderName);
String folderIdGraph = resp.getValue("folderId");
String acl = resp.getValue("acl");
String relativePath = path.replace(Configuration.URL_WEBDAV_SERVER, "");
String ownerPath = "/" + owner + relativePath + "/" + folderName;
FileSystemUtils.deletePrivateFiles();
new TokensResource(path).updateToken(owner, passphrase, acl);
int aclType = 0;
do {
aclType = Integer.valueOf(client.sendAndWait(
ClientPrimitives.OE_FIRST_STEP_JSON, path, owner).getValue(
"result"));
if (aclType == 1) {
boolean firstStep = true;
do {
firstStep = true;
do {
String json1 = client.sendAndWait(
ClientPrimitives.OE_JSON_UPLOAD, path, owner,
nextToken, String.valueOf(firstStep)).getValue(
"json");
if (json1.equals("{\"values\":[]}")) {
destinationACLReached = true;
} else {
FileSystemUtils.writePrivateFile("json.txt", json1);
String command = Configuration.EXECUTABLES_PATH
+ "/wpes1_linux";
command += firstStep ? "new1" : "newn";
command += Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/json.txt";
if (firstAesKey) {
command += Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKeyFin.txt";
}
command += firstStep ? passphrase
: Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKey.txt";
command += Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKey.txt";
command += folderIdGraph;
command += Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/next.txt";
command += acl;
RunnerExecutables.execute(command);
firstStep = false;
String next = FileSystemUtils
.readPrivateFile("next.txt");
nextToken = next;
destinationACLReached = Boolean
.valueOf(client
.sendAndWait(
ClientPrimitives.OE_FINISHED_UPLOAD_TOKEN,
path, owner, next)
.getValue("result"));
String jsonout = FileSystemUtils
.readPrivateFile("jsonout.txt");
client.sendAndWait(
ClientPrimitives.OE_PUT_TOKEN_DB, path,
owner, jsonout);
}
} while (!destinationACLReached);
File aesKeyFile = new File(
Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKey.txt");
if (firstAesKey && aesKeyFile.exists()) {
aesKeyFile.renameTo(new File(
Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKeyFin.txt"));
firstAesKey = false;
}
result3 = Boolean.valueOf(client.sendAndWait(
ClientPrimitives.OE_MORE_USERS_ACL, path, owner)
.getValue("result"));
} while (result3);
} else if (aclType == 3) {
String json2 = client.sendAndWait(
ClientPrimitives.OE_JSON_UPLOAD, path, owner, "",
String.valueOf(true)).getValue("json");
FileSystemUtils.writePrivateFile("json.txt", json2);
String command = Configuration.EXECUTABLES_PATH
+ "/wpes1_linux";
command += "new1";
command += Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/json.txt";
if (firstAesKey) {
command += Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKeyFin.txt";
}
command += passphrase;
command += Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKey.txt";
command += folderIdGraph;
command += Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/next.txt";
command += acl;
RunnerExecutables.execute(command);
firstAesKey = false;
if (firstAesKey) {
File aesKeyFile = new File(
Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKey.txt");
aesKeyFile.renameTo(new File(
Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKeyFin.txt"));
}
String jsonout = "";
jsonout = FileSystemUtils.readPrivateFile("jsonout.txt");
client.sendAndWait(ClientPrimitives.OE_PUT_TOKEN_DB, path,
owner, jsonout);
} else if (aclType == 2) {
String act = "";
String notes = "";
Response resp2 = client.sendAndWait(
ClientPrimitives.OE_CURRENT_NOTE, path, owner);
act = resp2.getValue("act");
notes = resp2.getValue("notes");
FileSystemUtils.writePrivateFile("NoteJson.txt", notes);
String command[] = {
Configuration.EXECUTABLES_PATH + "/wpes1_linux",
"note",
act,
Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/AesKeyFin.txt",
Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/Note.txt",
folderIdGraph,
acl,
Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/NoteJson.txt", passphrase };
RunnerExecutables.execute(command);
String note = FileSystemUtils.readPrivateFile("Note.txt");
client.sendAndWait(ClientPrimitives.OE_PUT_NOTE, path, owner,
note);
} else {
aclType = 0;
}
} while (aclType != 0);
String folderIdDB = client.sendAndWait(ClientPrimitives.OE_PUT_FOLDER, path, owner,
ownerPath).getValue("folderIdDB");
String aclBEL = acl;
String aclSEL = "0-" + acl;
FileSystemUtils.deletePrivateFiles();
String json = client.sendAndWait(ClientPrimitives.OE_VIEW_INFO, path,
owner, aclBEL, String.valueOf(true)).getValue("json");
FileSystemUtils.writePrivateFile("json.txt", json);
String command[] = { Configuration.EXECUTABLES_PATH + "/wpes1_linux",
"eACL", aclBEL, aclSEL, folderIdDB,
Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/json.txt",
Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/jsonout.txt",
passphrase,
Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/aclBEL.txt",
Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/aclSEL.txt", };
RunnerExecutables.execute(command);
String jsout = FileSystemUtils.readPrivateFile("jsonout.txt");
client.sendAndWait(ClientPrimitives.OE_SET_VIEW, path, jsout);
String encAclBEL = FileSystemUtils.readPrivateFile("aclBEL.txt");
String encAclSEL = FileSystemUtils.readPrivateFile("aclSEL.txt");
client.sendAndWait(ClientPrimitives.OE_PUT_ACL, path, encAclSEL,
encAclBEL);
TokensResource tokenFile = new TokensResource(path);
TokenStruct tokens = new TokenStruct();
tokens.setFolderIdDB(folderIdDB);
tokens.setFolderName(folderName);
tokens.setFolderIdGraph(folderIdGraph);
tokens.setOwnerID(owner);
tokens.setSEL(hasSEL);
tokens.setEncryptedAclBEL(encAclBEL);
tokens.setEncryptedAclSEL(encAclSEL);
tokenFile.addTokens(tokens);
FileSystemUtils.deletePrivateFiles();
client.sendAndWait(ClientPrimitives.OE_COMMIT, path, owner, "UM");
// TODO Retrieve URL WEBDAV SERVER FROM PYTHON
String folderPath1 = path.replace(Configuration.URL_WEBDAV_SERVER, "");
folderPath1 = "/" + owner
+ ((folderPath1.isEmpty()) ? "" : folderPath1) + "/"
+ folderName;
client.sendAndWait(ClientPrimitives.OE_UPDATE_PERMS_AFT_FOLDER, path,
owner, folderPath1, usersSelected);
}