Examples of OverEncryptClient


Examples of unibg.overencrypt.client.OverEncryptClient

        // Send current logged id to server
        String viewInfos = "";
        switch (type) {
        case DOWNLOAD:
            viewInfos = new OverEncryptClient().sendAndWait(
                    ClientPrimitives.OE_GET_VIEW_INFOS, folderPath, userID,
                    token.getOwnerID(), String.valueOf(false)).getValue(
                    "viewInfos");
            break;
        case EDIT:
            viewInfos = new OverEncryptClient().sendAndWait(
                    ClientPrimitives.OE_GET_VIEW_INFOS, folderPath, userID,
                    userID, String.valueOf(true)).getValue("viewInfos");
        }

        // Save viewInfos in a temp files
View Full Code Here

Examples of unibg.overencrypt.client.OverEncryptClient

     *         "AESKeyBEL.txt")
     */
    public String getAESKey(String folderName, String acl,
            String encryptionLevel, boolean isUpload) {

        OverEncryptClient client = new OverEncryptClient();

        // Retrieve user id and passphrase from local resource
        LocalPrivateResource localPrivateResource = new LocalPrivateResource();
        String userID = "";
        String passphrase = "";
        try {
            userID = localPrivateResource.get("UserInfo", "userId");
            passphrase = localPrivateResource.get("UserInfo", "pin");
            passphrase = SecurityAlgorithms.decryptAES(passphrase);
        } catch (Exception e) {
            // TODO ??
        }

        TokenStruct token = getTokens(folderName);

        if (isUpload) {
            client.sendAndWait(ClientPrimitives.OE_FIRST_STEP_JSON, folderPath,
                    userID);

            String json = client.sendAndWait(ClientPrimitives.OE_JSON_UPLOAD,
                    folderPath, userID, "", String.valueOf(true)).getValue(
                    "json");
            FileSystemUtils.writePrivateFile("json.txt", json);

            Executable exec = new Executable("wpes1_linux");
            exec.add("new1");
            exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/json.txt");
            exec.add(passphrase);
            exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/AESKey.txt");
            exec.add(token.getFolderIdGraph());
            exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/next.txt");
            exec.add(acl);
            exec.run();
        } else {
            String tokenID = client
                    .sendAndWait(ClientPrimitives.OE_GET_INFO, folderPath, acl,
                            encryptionLevel, token.getOwnerID(), userID,
                            token.getFolderIdGraph()).getValue("tokenID")
                    .trim();

            if ("BEL".equals(encryptionLevel)) {
                updateToken(token.getOwnerID(), passphrase, acl);
            }

            String nextToken = "";
            boolean finished = true;
            int i = 1;
            do {
                boolean firstStep = (i == 1);

                String json = client.sendAndWait(
                        ClientPrimitives.OE_CREATE_JSON_DL, folderPath,
                        Boolean.toString(firstStep), nextToken, userID)
                        .getValue("json");

                FileSystemUtils.writePrivateFile("Json.txt", json);

                // Decrypt acl informations
                Executable exec = new Executable("wpes1_linux");
                exec.add(firstStep ? "dec1" : "decn");
                exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                        + "/Json.txt");
                exec.add(firstStep ? passphrase
                        : Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                                + "/AESKey.txt");
                exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                        + "/AESKey.txt");
                exec.add(tokenID);
                exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                        + "/nextToken.txt");
                exec.run();

                nextToken = FileSystemUtils.readPrivateFile("nextToken.txt");

                FileSystemUtils.deletePrivateFile("Json.txt");

                String result = client.sendAndWait(
                        ClientPrimitives.OE_FINISHED_DL_TOKEN, folderPath,
                        nextToken, userID).getValue("finished");

                finished = Boolean.parseBoolean(result);

View Full Code Here

Examples of unibg.overencrypt.client.OverEncryptClient

     * @param inpd
     *            the indefinite progress JDialog
     */
    public void updateToken(String owner, String passphrase, String aclUpdate) {

        OverEncryptClient client = new OverEncryptClient();

        Boolean noteEmpty = Boolean.valueOf(client.sendAndWait(
                ClientPrimitives.OE_START_UPDATE, folderPath, owner, aclUpdate)
                .getValue("isEmpty"));

        while (!noteEmpty) {
            String note = client.sendAndWait(ClientPrimitives.OE_NOTE,
                    folderPath, owner).getValue("note");
            FileSystemUtils.writePrivateFile("Note.txt", note);

            Response resp = client.sendAndWait(ClientPrimitives.OE_CURR,
                    folderPath, owner);
            String acl = resp.getValue("acl");
            String destId = resp.getValue("destId");
            Boolean currentEmpty = Boolean.valueOf(resp.getValue("currEmpty"));

            while (!currentEmpty) {
                boolean firstStepUpdate = false;
                String nextToken = "";
                String finishedUpdateToken = "";

                do {
                    String jsonUp = client.sendAndWait(
                            ClientPrimitives.OE_JSON_UPDATE, folderPath, owner,
                            nextToken, String.valueOf(firstStepUpdate))
                            .getValue("jsonUp");

                    if (jsonUp.equals("{\"values\":[]}")) {
                        break;
                    } else {
                        FileSystemUtils.writePrivateFile("Json.txt", jsonUp);
                    }

                    firstStepUpdate = false;

                    Executable exec = new Executable("wpes1_linux");
                    exec.add(firstStepUpdate ? "upd1" : "unpdn");
                    exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                            + "/Json.txt");
                    exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                            + "/Note.txt");
                    if (firstStepUpdate) {
                        exec.add(passphrase);
                    }
                    exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                            + "/AesKey.txt");
                    if (!firstStepUpdate) {
                        exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                                + "/AesKey.txt");
                    }
                    exec.add(destId);
                    exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                            + "/next.txt");
                    if (!firstStepUpdate) {
                        exec.add(passphrase);
                    }
                    exec.add(acl);
                    exec.run();

                    nextToken = FileSystemUtils.readPrivateFile("next.txt");
                    String jsonOut = FileSystemUtils
                            .readPrivateFile("Noteout.txt");

                    finishedUpdateToken = client.sendAndWait(
                            ClientPrimitives.OE_PUT_UPDATE_TOKEN, folderPath,
                            owner, jsonOut, nextToken).getValue(
                            "finishedUpdateToken");
                } while ("false".equals(finishedUpdateToken));

                currentEmpty = Boolean.valueOf(client.sendAndWait(
                        ClientPrimitives.OE_CURR, folderPath, owner).getValue(
                        "currEmpty"));
            }

            String nextTokenLast = "{\"next_token\":\"" + acl + "\"}";
            boolean stepLast = false;
            String jsonUpLast = client.sendAndWait(
                    ClientPrimitives.OE_JSON_UPDATE, folderPath, owner,
                    nextTokenLast, String.valueOf(stepLast)).getValue("jsonUp");

            FileSystemUtils.writePrivateFile("JsonLast.txt", jsonUpLast);

            Executable exec = new Executable("wpes1_linux");
            exec.add("updL");
            exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                    + "/JsonLast.txt");
            exec.add(passphrase);
            exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/AesKey.txt");
            exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/Note.txt");
            exec.add(acl);
            exec.run();

            String jsonOut = FileSystemUtils.readPrivateFile("Noteout.txt");

            client.sendAndWait(ClientPrimitives.OE_TOKEN, folderPath, owner,
                    jsonOut);
            client.sendAndWait(ClientPrimitives.OE_EMPTY_NOTE, folderPath,
                    owner).getValue("isEmpty");
        }

        // solo comando di eliminazione note, non aspetta la risposta dal
        // server
        client.send(ClientPrimitives.OE_DELETE_NOTES, folderPath, owner);

        // solo comando di commit, non aspetta la risposta dal server
        client.send(ClientPrimitives.OE_COMMIT, folderPath, owner, "update");
    }
View Full Code Here

Examples of unibg.overencrypt.client.OverEncryptClient

        client.download(path + fileName, tempEncryptedFilePath);

        String aesBELFileName = tokenFile.getAESKey(folderName, aclBEL, "BEL",
                false);

        String dsaKey = new OverEncryptClient().sendAndWait(
                ClientPrimitives.OE_GET_DSA_JSON, path, "Download",
                token.getOwnerID(), userID).getValue("dsa");
        String dsaFileName = "DSAKey.txt";
        FileSystemUtils.writePrivateFile(dsaFileName, dsaKey);
View Full Code Here

Examples of unibg.overencrypt.client.OverEncryptClient

    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);
    }
View Full Code Here

Examples of unibg.overencrypt.client.OverEncryptClient

        OptionSet options = parser.parse(args);

        String path = options.nonOptionArguments().get(1);
        logger.debug(path);

        OverEncryptClient client = new OverEncryptClient();
        AuthenticationClient pinManagementClient = new AuthenticationClient();
        PermissionsClient permissionsClient = new PermissionsClient();

        Response resp = client.readResponse(path);
        logger.debug("Response:\n===\n" + resp.toString() + "===");

        if (resp.getPrimitive() == ServerPrimitives.OE_DHKEYPAIRS) {
            exitWithError(1, "The user hasn't chosen a passphrase yet. "
                    + "Use the '" + new GenerateKeysCommand().getKeyword()
                    + "' command to choose one.");
        }

        String userId = resp.getValue("userId");
        String passphrase = "";

        if (options.has("p") || options.has("passphrase")) {
            passphrase = (String) options.valueOf("p");
        } else {
            exitWithError(2, "No passphrase supplied. Please use " +
                    "the -p/--passphrase option to supply a valid passphrase.");
        }

        client.deleteResponse(path);
        while (resp.getPrimitive() == ServerPrimitives.OE_AUTHENTICATION) {
            resp = pinManagementClient.checkPin(path, userId, passphrase);
            logger.debug("Response:\n===\n" + resp.toString() + "===");
        }
View Full Code Here

Examples of unibg.overencrypt.client.OverEncryptClient

        String userId = null;
        String passphrase = null;
        String aclUsers;
        String json = null;
        OverEncryptClient client = new OverEncryptClient();

        LocalPrivateResource lpr = new LocalPrivateResource();
        try {
            userId = lpr.get("UserInfo", "userId");
            passphrase = lpr.get("UserInfo", "pin");
            passphrase = SecurityAlgorithms.decryptAES(passphrase);
        } catch (Exception e) {
            // TODO Error
        }

        TokensResource tokenFile = new TokensResource(parentPath);
        TokenStruct token = tokenFile.getTokens(folderName);

        if (!token.hasSEL()) {
            String aclSEL = tokenFile.getDecryptedACLBEL(folderName,
                    OperationType.EDIT);
            aclUsers = aclSEL.substring(2, aclSEL.length());
        } else {
            aclUsers = tokenFile.getDecryptedACLSEL(folderName,
                    OperationType.EDIT);
        }

        FileSystemUtils.deletePrivateFiles();

        json = client.sendAndWait(ClientPrimitives.OE_VIEW_INFO, parentPath,
                userId, aclUsers, String.valueOf(true)).getValue("json");

        FileSystemUtils.writePrivateFile("json.txt", json);

        String command[] = { Configuration.EXECUTABLES_PATH + "/wpes1_linux",
                "remID", token.getFolderIdDB(),
                Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/json.txt",
                Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/jsonout.txt",
                passphrase };
        RunnerExecutables.execute(command);

        json = FileSystemUtils.readPrivateFile("jsonout.txt");

        client.sendAndWait(ClientPrimitives.OE_SET_VIEW, parentPath, json);

        FileSystemUtils.deletePrivateFiles();

        client.sendAndWait(ClientPrimitives.OE_DELETE_FOLDER, parentPath,
                token.getFolderIdDB(), folderName);

        tokenFile.deleteFolder(folderName);
    }
View Full Code Here

Examples of unibg.overencrypt.client.OverEncryptClient

        } else {
            exitWithError("No passphrase supplied. Please use "
                    + "the -p/--passphrase option to supply a valid passphrase.");
        }

        OverEncryptClient client = new OverEncryptClient();
        AuthenticationClient pinManagementClient = new AuthenticationClient();

        Response resp = client.waitForResponse(path);
        String userId = resp.getValue("userId");
        logger.debug("Response:\n===\n" + resp.toString() + "===");

        if (resp.getPrimitive() == ServerPrimitives.OE_DHKEYPAIRS) {
            resp = pinManagementClient.generateKeyPairs(path, userId,
View Full Code Here

Examples of unibg.overencrypt.client.OverEncryptClient

        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
        // agli utenti relative
View Full Code Here

Examples of unibg.overencrypt.client.OverEncryptClient

        String path = options.nonOptionArguments().get(1);
        String folderName = options.nonOptionArguments().get(2);
        String users = options.nonOptionArguments().get(3);

        OverEncryptClient client = new OverEncryptClient();

        String userId = null;
        String passphrase = null;

        LocalPrivateResource lpr = new LocalPrivateResource();
        try {
            userId = lpr.get("UserInfo", "userId");
            passphrase = lpr.get("UserInfo", "pin");
            passphrase = SecurityAlgorithms.decryptAES(passphrase);
        } catch (Exception e) {
            // TODO ??
        }

        // GET DECRYPTED ACL BEL & SEL
        TokensResource tokenFile = new TokensResource(path);
        TokenStruct token = tokenFile.getTokens(folderName);
        String folderIdDB = token.getFolderIdDB();

        String[] acls = tokenFile.getDecryptedACL(folderName,
                OperationType.EDIT);

        String aclBEL = acls[0];
        String aclSEL = acls[1];

        String acl;
        String json = null;
        String jsout;

        String aesKeyBEL = tokenFile
                .getAESKey(folderName, aclBEL, "BEL", false);

        Response resp = client.sendAndWait(ClientPrimitives.OE_EDITPERM, path,
                users, userId, aclSEL, aclBEL);

        String newSEL = resp.getValue("newSel");
        String addUser = resp.getValue("addUser");
        String delUser = resp.getValue("delUser");

        if (!"nochange".equals(newSEL)) {
            Response tokenInfo = client.sendAndWait(
                    ClientPrimitives.OE_GET_TOKEN_INFO, path, userId);

            String idToken = tokenInfo.getValue("idToken");
            boolean hasMoreTokens = Boolean.valueOf(tokenInfo
                    .getValue("hasMoreTokens"));

            acl = aclBEL;

            while (hasMoreTokens) {
                String tokenHBEL = client.sendAndWait(
                        ClientPrimitives.OE_CREATE_JSON_HBEL, path, userId)
                        .getValue("tokenHBEL");

                // HBEL Tokens creation
                FileSystemUtils.writePrivateFile("json.txt", tokenHBEL);

                Executable exec = new Executable("wpes1_linux");
                exec.add("h");
                exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/"
                        + aesKeyBEL);
                exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                        + "/json.txt");
                exec.add(acl);
                exec.add(idToken);
                exec.add(passphrase);
                exec.run();

                String jsonout = FileSystemUtils.readPrivateFile("jsonout.txt");

                // Put new tokens HBEL in server DB
                hasMoreTokens = Boolean.valueOf(client.sendAndWait(
                        ClientPrimitives.OE_PUT_TOKEN_HBEL, path, userId,
                        jsonout).getValue("hasMoreTokens"));

                FileSystemUtils.deletePrivateFile("jsonout.txt");
            }
            // End HBEL tokens creation

            FileSystemUtils.deletePrivateFiles();

            // Update View Informations for added and deleted users
            if (!addUser.isEmpty()) {
                json = client.sendAndWait(ClientPrimitives.OE_VIEW_INFO, path,
                        userId, (userId + "-" + addUser), String.valueOf(true))
                        .getValue("json");
                FileSystemUtils.writePrivateFile("json.txt", json);

                Executable exec = new Executable("wpes1_linux");
                exec.add("addID");
                exec.add(folderIdDB);
                exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                        + "/json.txt");
                exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                        + "/jsonout.txt");
                exec.add(passphrase);
                exec.add(userId);
                exec.run();

                jsout = FileSystemUtils.readPrivateFile("jsonout.txt");

                client.sendAndWait(ClientPrimitives.OE_SET_VIEW, path, jsout);

                FileSystemUtils.deletePrivateFiles();
            }

            if (!delUser.isEmpty()) {
                json = client.sendAndWait(ClientPrimitives.OE_VIEW_INFO, path,
                        userId, delUser, String.valueOf(true)).getValue("json");
                FileSystemUtils.writePrivateFile("json.txt", json);

                Executable exec = new Executable("wpes1_linux");
                exec.add("remID");
                exec.add(folderIdDB);
                exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                        + "/json.txt");
                exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                        + "/jsonout.txt");
                exec.add(passphrase);
                exec.run();
                jsout = FileSystemUtils.readFile("jsonout.txt");

                client.sendAndWait(ClientPrimitives.OE_SET_VIEW, path, jsout);
                FileSystemUtils.deletePrivateFiles();
            }

            // If has SEL level decrypt and re-encrypt at SEL Level
            client.sendAndWait(ClientPrimitives.OE_SEL_REQ, path, folderName,
                    folderIdDB, userId, users, aclSEL,
                    Boolean.toString(token.hasSEL()));

            // Retrieve ViewInformations to encrypt acl to put into server db
            String viewInfos = client.sendAndWait(
                    ClientPrimitives.OE_VIEW_INFO, path, userId, userId,
                    String.valueOf(true)).getValue("json");

            FileSystemUtils.writePrivateFile("viewInfos.txt", viewInfos);

            Executable exec = new Executable("wpes1_linux");
            exec.add("eACLsel");
            exec.add(folderIdDB);
            exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
                    + "/viewInfos.txt");
            exec.add(passphrase);
            exec.add("0-" + newSEL);
            exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/aclSEL.txt");
            exec.run();

            String newEncryptedAclSEL = FileSystemUtils
                    .readPrivateFile("aclSEL.txt");

            // SAVE IN .tokens
            // After a permission editing also delta-SEL resources has SEL
            // encrypt level
            tokenFile
                    .setEncryptedAcl(token.getFolderIdDB(), newEncryptedAclSEL);

            // SAVE IN SERVER DB
            client.sendAndWait(ClientPrimitives.OE_SAVE_NEW_SEL, path,
                    folderIdDB, newEncryptedAclSEL);
            FileSystemUtils.deletePrivateFiles();
        } else {
            // TODO ??
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.