// Non-interactive mode
if (masterPassword != null) {
logger.log(Level.INFO, " - Link is encrypted. Password available.");
SaltedSecretKey masterKey = createMasterKeyFromPassword(masterPassword, applicationLink.getMasterKeySalt());
TransferSettings transferSettings = applicationLink.createTransferSettings(masterKey);
configTO.setMasterKey(masterKey);
configTO.setTransferSettings(transferSettings);
}
else {
logger.log(Level.INFO, " - Link is encrypted. Asking for password.");
boolean retryPassword = true;
while (retryPassword) {
// Ask password
masterPassword = getOrAskPassword();
// Generate master key
SaltedSecretKey masterKey = createMasterKeyFromPassword(masterPassword, applicationLink.getMasterKeySalt());
// Decrypt config
try {
TransferSettings transferSettings = applicationLink.createTransferSettings(masterKey);
configTO.setMasterKey(masterKey);
configTO.setTransferSettings(transferSettings);
retryPassword = false;
}
catch (CipherException e) {
retryPassword = askRetryPassword();
}
}
}
if (configTO.getTransferSettings() == null) {
throw new CipherException("Unable to decrypt link.");
}
}
else {
logger.log(Level.INFO, " - Link is NOT encrypted. No password needed.");
TransferSettings transferSettings = applicationLink.createTransferSettings();
configTO.setTransferSettings(transferSettings);
}
}
catch (Exception e) {
throw new StorageException("Unable to extract connection settings: " + e.getMessage(), e);