public ConnectOperationResult connect(ConnectOperationOptions options, UserInteractionListener listener) throws Exception, CipherException { return new ConnectOperation(options, listener).execute(); }
private SaltedSecretKey askPasswordAndCreateMasterKey() throws CipherException, StorageException { File tmpMasterFile = downloadFile(transferManager, new MasterRemoteFile()); MasterTO masterTO = readMasterFile(tmpMasterFile); tmpMasterFile.delete(); String masterKeyPassword = getOrAskPassword(); byte[] masterKeySalt = masterTO.getSalt(); return createMasterKeyFromPassword(masterKeyPassword, masterKeySalt); // This takes looong! }
configTO = createConfigTO(); transferManager = createTransferManagerFromNullConfig(options.getConfigTO()); if (!performRepoTest(transferManager)) { logger.log(Level.INFO, "- Connecting to the repo failed, repo already exists or cannot be created: " + result.getResultCode()); return result; File tmpRepoFile = downloadFile(transferManager, new SyncanyRemoteFile()); 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."); retryPassword = askRetryPassword(); 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); verifyRepoFile(repoFileStr); File appDir = createAppDirs(options.getLocalDir());
logger.log(Level.INFO, " - Link is encrypted. Password available."); SaltedSecretKey masterKey = createMasterKeyFromPassword(masterPassword, applicationLink.getMasterKeySalt()); TransferSettings transferSettings = applicationLink.createTransferSettings(masterKey); masterPassword = getOrAskPassword(); SaltedSecretKey masterKey = createMasterKeyFromPassword(masterPassword, applicationLink.getMasterKeySalt()); retryPassword = askRetryPassword();
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()); } }
@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; }
@Override public void run() { try { ConnectOperation initOperation = new ConnectOperation(concreteRequest.getOptions(), new EventUserInteractionListener()); ConnectOperationResult operationResult = initOperation.execute(); switch (operationResult.getResultCode()) { case OK: eventBus.post(new ConnectManagementResponse(ConnectManagementResponse.OK, operationResult, request.getId())); break; case NOK_TEST_FAILED: eventBus.post(new ConnectManagementResponse(ConnectManagementResponse.NOK_FAILED_TEST, operationResult, request.getId())); break; default: eventBus.post(new ConnectManagementResponse(ConnectManagementResponse.NOK_FAILED_UNKNOWN, operationResult, request.getId())); break; } } catch (Exception e) { logger.log(Level.WARNING, "Error adding watch to daemon config.", e); eventBus.post(new ConnectManagementResponse(ConnectManagementResponse.NOK_OPERATION_FAILED, new ConnectOperationResult(), request .getId())); } } }, "ConRq/" + concreteRequest.getOptions().getLocalDir().getName());