Package org.syncany.config.to

Examples of org.syncany.config.to.ConfigTO


    Serializer serializer = new Persister();

    // Always LocalTransferSettings
    serializer.write(TestConfigUtil.createTestInitOperationOptions("syncanytest").getConfigTO(), tmpFile);

    ConfigTO confRestored = ConfigTO.load(tmpFile);

    assertEquals(LocalTransferSettings.class, confRestored.getTransferSettings().getClass());
  }
View Full Code Here


    logger.log(Level.INFO, "");
    logger.log(Level.INFO, "Running 'Connect'");
    logger.log(Level.INFO, "--------------------------------------------");

    // Decrypt and init configTO
    ConfigTO configTO = null;

    try {
      configTO = createConfigTO();
    }
    catch (CipherException e) {
      return new ConnectOperationResult(ConnectResultCode.NOK_DECRYPT_ERROR);
    }

    // Init plugin and transfer manager
    String pluginId = options.getConfigTO().getTransferSettings().getType();
    plugin = Plugins.get(pluginId, TransferPlugin.class);

    TransferSettings transferSettings = (TransferSettings) options.getConfigTO().getTransferSettings();
    transferSettings.setUserInteractionListener(listener);

    transferManager = plugin.createTransferManager(transferSettings, null); // "null" because no config exists yet!

    // Test the repo
    if (!performRepoTest(transferManager)) {
      logger.log(Level.INFO, "- Connecting to the repo failed, repo already exists or cannot be created: " + result.getResultCode());
      return result;
    }

    logger.log(Level.INFO, "- Connecting to the repo was successful; now downloading repo file ...");

    // Create local .syncany directory
    File tmpRepoFile = downloadFile(transferManager, new SyncanyRemoteFile());

    if (CipherUtil.isEncrypted(tmpRepoFile)) {
      logger.log(Level.INFO, "- Repo is ENCRYPTED. Decryption necessary.");

      if (configTO.getMasterKey() == null) {
        logger.log(Level.INFO, "- No master key present; Asking for password ...");

        boolean retryPassword = true;

        while (retryPassword) {
          SaltedSecretKey possibleMasterKey = askPasswordAndCreateMasterKey();
          logger.log(Level.INFO, "- Master key created. Now verifying by decrypting repo file...");

          if (decryptAndVerifyRepoFile(tmpRepoFile, possibleMasterKey)) {
            logger.log(Level.INFO, "- SUCCESS: Repo file decrypted successfully.");

            configTO.setMasterKey(possibleMasterKey);
            retryPassword = false;
          }
          else {
            logger.log(Level.INFO, "- FAILURE: Repo file decryption failed. Asking for retry.");
            retryPassword = askRetryPassword();

            if (!retryPassword) {
              logger.log(Level.INFO, "- No retry possible/desired. Returning NOK_DECRYPT_ERROR.");
              return new ConnectOperationResult(ConnectResultCode.NOK_DECRYPT_ERROR);
            }
          }
        }
      }
      else {
        logger.log(Level.INFO, "- Master key present; Now verifying by decrypting repo file...");

        if (!decryptAndVerifyRepoFile(tmpRepoFile, configTO.getMasterKey())) {
          logger.log(Level.INFO, "- FAILURE: Repo file decryption failed. Returning NOK_DECRYPT_ERROR.");
          return new ConnectOperationResult(ConnectResultCode.NOK_DECRYPT_ERROR);
        }
      }
    }
    else {
      String repoFileStr = FileUtils.readFileToString(tmpRepoFile);
      verifyRepoFile(repoFileStr);
    }

    // Success, now do the work!
    File appDir = createAppDirs(options.getLocalDir());

    // Write file 'config.xml'
    File configFile = new File(appDir, Config.FILE_CONFIG);
    configTO.save(configFile);

    // Write file 'syncany'
    File repoFile = new File(appDir, Config.FILE_REPO);
    FileUtils.copyFile(tmpRepoFile, repoFile);
    tmpRepoFile.delete();

    // Write file 'master'
    if (configTO.getMasterKey() != null) {
      File masterFile = new File(appDir, Config.FILE_MASTER);
      new MasterTO(configTO.getMasterKey().getSalt()).save(masterFile);
    }

    // Shutdown plugin
    transferManager.disconnect();
View Full Code Here

    return createMasterKeyFromPassword(masterKeyPassword, masterKeySalt); // This takes looong!
  }

  private ConfigTO createConfigTO() throws StorageException, CipherException {
    ConfigTO configTO = options.getConfigTO();

    if (options.getStrategy() == ConnectOptionsStrategy.CONNECTION_TO) {
      return configTO;
    }
    else if (options.getStrategy() == ConnectOptionsStrategy.CONNECTION_LINK) {
View Full Code Here

  private static void fixMachineName(Map<String, String> client) throws Exception {
    File configFile = new File(client.get("localdir") + "/" + Config.DIR_APPLICATION + "/" + Config.FILE_CONFIG);
    Serializer serializer = new Persister();

    ConfigTO configTO = serializer.read(ConfigTO.class, configFile);
    configTO.setMachineName(client.get("machinename"));

    serializer.write(configTO, configFile);
  }
View Full Code Here

  public AbstractInitCommand() {
    console = InitConsole.getInstance();
  }

  protected ConfigTO createConfigTO(TransferSettings transferSettings) throws Exception {
    ConfigTO configTO = new ConfigTO();

    configTO.setDisplayName(getDefaultDisplayName());
    configTO.setMachineName(getRandomMachineName());
    configTO.setMasterKey(null);
    configTO.setTransferSettings(transferSettings); // can be null

    return configTO;
  }
View Full Code Here

    // Set repo password
    String password = validateAndGetPassword(options, optionNoEncryption, optionPassword);
    operationOptions.setPassword(password);
   
    // Create configTO and repoTO
    ConfigTO configTO = createConfigTO(transferSettings);
    RepoTO repoTO = createRepoTO(chunkerTO, multiChunkerTO, transformersTO);

    operationOptions.setLocalDir(localDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setRepoTO(repoTO);
View Full Code Here

    }
    else {
      throw new Exception("Invalid syntax.");
    }

    ConfigTO configTO = createConfigTO(transferSettings);

    operationOptions.setLocalDir(localDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setDaemon(options.has(optionAddDaemon));
    operationOptions.setPassword(validateAndGetPassword(options, optionPassword));
View Full Code Here

TOP

Related Classes of org.syncany.config.to.ConfigTO

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.