private void makeRemoteChanges(File configFile, File masterFile, File repoFile) throws Exception { initRemoteRepository(configFile); try { if (options.isEncryptionEnabled()) { uploadMasterFile(masterFile, transferManager); } uploadRepoFile(repoFile, transferManager); } catch (StorageException | IOException e) { cleanLocalRepository(e); } }
public InitOperation(InitOperationOptions options, UserInteractionListener listener) { super(null, listener); this.options = options; this.result = new InitOperationResult(); }
public ConnectOperation(ConnectOperationOptions options, UserInteractionListener listener) { super(null, listener); this.options = options; this.result = new ConnectOperationResult(); }
private GenlinkOperationResult generateLink(ConfigTO configTO) throws Exception { return new GenlinkOperation(options.getConfigTO(), options.getGenlinkOptions()).execute(); }
@Override public int execute(String[] operationArgs) throws Exception { boolean retryNeeded = true; boolean performOperation = true; operationOptions = parseOptions(operationArgs); while (retryNeeded && performOperation) { InitOperationResult operationResult = new InitOperation(operationOptions, this).execute(); printResults(operationResult); retryNeeded = operationResult.getResultCode() != InitResultCode.OK; if (retryNeeded) { performOperation = isInteractive && askRetryConnection(); if (performOperation) { updateTransferSettings(operationOptions.getConfigTO().getTransferSettings()); } } } return 0; }
@Override public int execute(String[] operationArgs) throws Exception { boolean retryNeeded = true; boolean performOperation = true; ConnectOperationOptions operationOptions = parseOptions(operationArgs); while (retryNeeded && performOperation) { ConnectOperationResult operationResult = new ConnectOperation(operationOptions, this).execute(); printResults(operationResult); retryNeeded = operationResult.getResultCode() != ConnectResultCode.OK && operationResult.getResultCode() != ConnectResultCode.NOK_DECRYPT_ERROR; if (retryNeeded) { performOperation = isInteractive && askRetryConnection(); if (performOperation) { updateTransferSettings(operationOptions.getConfigTO().getTransferSettings()); } } } return 0; }
public GenlinkOperationResult genlink(GenlinkOperationOptions options) throws Exception { return new GenlinkOperation(config, options).execute(); }
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) { return createConfigTOFromLink(configTO, options.getConnectLink(), options.getPassword()); } else { throw new RuntimeException("Unhandled connect strategy: " + options.getStrategy()); } }
private void saveLocalConfig(File configFile, File repoFile, File masterFile, String masterKeyPassword) throws Exception { if (options.isEncryptionEnabled()) { SaltedSecretKey masterKey = createMasterKeyFromPassword(masterKeyPassword); // This takes looong! options.getConfigTO().setMasterKey(masterKey); new MasterTO(masterKey.getSalt()).save(masterFile); options.getRepoTO().save(repoFile, options.getCipherSpecs(), masterKey); } else { options.getRepoTO().save(repoFile); } options.getConfigTO().save(configFile); }
private void initRemoteRepository(File configFile) throws Exception { try { // Create 'syncany' and 'master' file, and all the remote folders transferManager.init(options.isCreateTarget()); // Some plugins change the transfer settings, re-save options.getConfigTO().save(configFile); } catch (StorageException e) { // Storing remotely failed. Remove all the directories and files we just created cleanLocalRepository(e); } }
public InitOperationResult init(InitOperationOptions options, UserInteractionListener listener) throws Exception { return new InitOperation(options, listener).execute(); }
public ConnectOperationResult connect(ConnectOperationOptions options, UserInteractionListener listener) throws Exception, CipherException { return new ConnectOperation(options, listener).execute(); }
private void addToDaemonIfEnabled() { if (options.isDaemon()) { try { boolean addedToDaemonConfig = DaemonConfigHelper.addFolder(options.getLocalDir()); result.setAddedToDaemon(addedToDaemonConfig); } catch (Exception e) { logger.log(Level.WARNING, "Cannot add folder to daemon config.", e); result.setAddedToDaemon(false); } } }
public InitOperationOptions() { this.genlinkOptions = new GenlinkOperationOptions(); }
private boolean decryptAndVerifyRepoFile(File tmpRepoFile, SaltedSecretKey masterKey) throws StorageException { try { String repoFileStr = decryptRepoFile(tmpRepoFile, masterKey); verifyRepoFile(repoFileStr); return true; } catch (CipherException e) { logger.log(Level.FINE, "Could not decrypt the repository file", e); return false; } }
private void cleanLocalRepository(Exception e) throws Exception { try { deleteAppDirs(options.getLocalDir()); } catch (Exception e1) { throw new StorageException("Couldn't upload to remote repo. Cleanup failed. There may be local directories left"); } throw new StorageException("Couldn't upload to remote repo. Cleaned local repository.", e); }
public TransferSettings createTransferSettings() throws Exception { if (encrypted || plaintextSettingsBytes == null) { throw new IllegalArgumentException("Link is encrypted. Cannot call this method."); } return createTransferSettings(plaintextSettingsBytes); }
private SaltedSecretKey createMasterKeyFromPassword(String masterPassword, byte[] masterKeySalt) throws CipherException { fireNotifyCreateMaster(); SaltedSecretKey masterKey = CipherUtil.createMasterKey(masterPassword, masterKeySalt); return masterKey; }
private SaltedSecretKey createMasterKeyFromPassword(String masterPassword) throws Exception { fireNotifyCreateMaster(); SaltedSecretKey masterKey = CipherUtil.createMasterKey(masterPassword); return masterKey; }
@Override public int execute(String[] operationArgs) throws Exception { GenlinkOperationOptions operationOptions = parseOptions(operationArgs); GenlinkOperationResult operationResult = new GenlinkOperation(config, operationOptions).execute(); printResults(operationResult); return 0; }