remoteFolder.length() - 1);
remoteFolderName = remoteFolderName.substring(remoteFolderName
.lastIndexOf('/') + 1);
TokensResource tokenFile = new TokensResource(remoteParentFolder);
TokenStruct token = tokenFile.getTokens(remoteFolderName);
String aclBEL = tokenFile.getDecryptedACLBEL(remoteFolderName,
OperationType.DOWNLOAD);
OverEncryptClient client = new OverEncryptClient();
client.sendAndWait(ClientPrimitives.OE_UPLMANAGER_FILE, remoteFolder,
aclBEL, userId);
String dsaKey = client.sendAndWait(ClientPrimitives.OE_GET_DSA_JSON,
remoteFolder, "Upload", userId, userId).getValue("dsa");
String dsaFileName = "DSAKey.txt";
FileSystemUtils.writePrivateFile(dsaFileName, dsaKey);
String aesFileName = tokenFile.getAESKey(remoteFolderName, aclBEL,
"BEL", true);
Executable exec = new Executable("wpes2_linux");
exec.add("eBEL");
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/" + dsaFileName);
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/" + aesFileName);
exec.add(localFolder + "/" + fileName);
exec.add(Configuration.LOCAL_TMP_PATH + "/" + fileName);
exec.add(passphrase);
exec.run();
String localFilePath = Configuration.LOCAL_TMP_PATH + "/" + fileName;
WebDAVClient davClient = new ApacheWebDAVClient();
davClient.upload(localFilePath, remoteFolder + fileName);
new File(localFilePath).delete();
String[] splitted = aclBEL.split("-");
String users = "";
for (int i = 0; i < splitted.length; i++) {
if (!splitted[i].equals(userId)) {
users += splitted[i];
}
}
users = userId + "," + users;
if (token.hasSEL()) {
client.sendAndWait(ClientPrimitives.OE_ENCRYPT_SEL, remoteFolder,
userId, fileName, users);
}
// TODO Aggiornare i riferimenti alle risorse condivise e i permessi