use of com.sshtools.j2ssh.transport.HostKeyVerification in project qaf by qmetry.
the class SshUtil method connectSsh.
/**
* connect to host
*
* @return
* @throws Exception
*/
private static SshClient connectSsh() throws Exception {
SshClient ssh = new SshClient();
HostKeyVerification host = new IgnoreHostKeyVerification();
String hostStr = getBundle().getString("ssh.host");
ssh.connect(hostStr, host);
PasswordAuthenticationClient auth = new PasswordAuthenticationClient();
auth.setUsername(getBundle().getString("ssh.user"));
auth.setPassword(getBundle().getString("ssh.pwd"));
int result = ssh.authenticate(auth);
System.out.println("Status " + result);
if ((result == AuthenticationProtocolState.CANCELLED) || (result == AuthenticationProtocolState.FAILED)) {
throw new Exception("Authentication Error.");
}
return ssh;
}
use of com.sshtools.j2ssh.transport.HostKeyVerification in project agileway by fangjinuo.
the class J2sshConnectionFactory method setKnownHosts0.
protected void setKnownHosts0(SshConnection connection, J2sshConnectionConfig sshConfig) {
String filepath = sshConfig.getKnownHostsPath();
List<File> files = SshConfigs.getKnownHostsFiles(filepath);
HostKeyVerification verifier = null;
if (files.isEmpty()) {
verifier = new IgnoreHostKeyVerification();
} else {
try {
verifier = new KnownHostsVerifier(files.get(0).getAbsolutePath());
} catch (Throwable ex) {
throw new SshException(ex);
}
}
connection.addHostKeyVerifier(new FromJ2ssHostKeyVerifier(verifier));
}
Aggregations