Package unibg.overencrypt.protocol

Examples of unibg.overencrypt.protocol.TokensResource


        String folderName = path.substring(0, path.length() - 1);
        folderName = folderName.substring(folderName.lastIndexOf('/') + 1);

        logger.debug(folderName);

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

        String acls[] = tokenFile.getDecryptedACL(folderName,
                OperationType.DOWNLOAD);
        String aclBEL = acls[0];
        String aclSEL = acls[1];

        String[] splittedSELACL = aclSEL.split("-");
        if (splittedSELACL.length > 2
                && splittedSELACL[1].equals(splittedSELACL[2])) {
            aclSEL = "0-" + splittedSELACL[1];
        }

        String tempEncryptedFilePath = Configuration.LOCAL_TMP_PATH + "/enc_"
                + fileName;
        WebDAVClient client = new ApacheWebDAVClient();
        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);

        logger.debug(destinationPath);

        Executable exec = new Executable("wpes2_linux");
        if (token.hasSEL()) {
            exec.add("dSELBEL");
        } else {
            exec.add("dBEL");
        }
        exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/"
                + dsaFileName);
        exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/"
                + aesBELFileName);
        if (token.hasSEL()) {
            exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/"
                    + tokenFile.getAESKey(folderName, aclSEL, "SEL", false));
        }
        exec.add(tempEncryptedFilePath);

        logger.debug(destinationPath);
View Full Code Here


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

        String remoteFolderName = remoteFolder.substring(0,
                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);
View Full Code Here

            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

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

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

        logger.debug(folderName);

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

        String acl = tokenFile.getDecryptedACLSEL(folderName,
                OperationType.EDIT);

        logger.debug("acl: " + acl);

        String ownerId = token.getOwnerID();
View Full Code Here

TOP

Related Classes of unibg.overencrypt.protocol.TokensResource

Copyright © 2018 www.massapicom. 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.