in src/main/java/co/elastic/support/util/RemoteSystem.java [34:99]
public RemoteSystem(String osName,
String remoteUser,
String remotePassword,
String host,
int port,
String keyFile,
String keyFilePass,
String knownHostsFile,
boolean trustRemote,
boolean isSudo) throws DiagnosticException {
this.osName = osName;
try {
if(osName.equals(Constants.winPlatform)){
logger.info(Constants.CONSOLE, "Windows is not supported for remote calls at this time. Session not created.");
disabledForPlatform = true;
return;
}
JSch jsch; jsch = new JSch();
if(StringUtils.isNotEmpty(keyFile)){
jsch.addIdentity(keyFile);
if(StringUtils.isEmpty(keyFilePass)){
keyFilePass = null;
}
}
if(StringUtils.isNotEmpty(remotePassword)){
if(isSudo){
sudo = sudoPrefix.replace("{{PASSWORD}}", remotePassword);
}
}
else{
remotePassword = null;
if(isSudo){
sudo = sudoNoPasswordPrefix;
}
}
if(StringUtils.isNotEmpty(knownHostsFile)){
jsch.setKnownHosts(knownHostsFile);
}
String hostKeyChecking = "yes";
if (trustRemote) {
hostKeyChecking = "no";
}
UserInfo userInfo = new RemoteUserInfo(remoteUser, remotePassword, keyFilePass);
session = jsch.getSession(remoteUser, host, port);
final Hashtable config = new Hashtable();
config.put("StrictHostKeyChecking", hostKeyChecking);
config.put("PreferredAuthentications",
"publickey,keyboard-interactive,password");
session.setConfig(config);
session.setUserInfo(userInfo);
session.setServerAliveCountMax(3);
session.setServerAliveInterval(10000);
session.connect();
} catch (JSchException e) {
throw new DiagnosticException("Error obtaining session for remote server - try running with diagnostic type: api.");
}
}