Search in sources :

Example 1 with HostKeyVerification

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;
}
Also used : SshClient(com.sshtools.j2ssh.SshClient) IgnoreHostKeyVerification(com.sshtools.j2ssh.transport.IgnoreHostKeyVerification) HostKeyVerification(com.sshtools.j2ssh.transport.HostKeyVerification) IgnoreHostKeyVerification(com.sshtools.j2ssh.transport.IgnoreHostKeyVerification) PasswordAuthenticationClient(com.sshtools.j2ssh.authentication.PasswordAuthenticationClient) ConfigurationException(com.sshtools.j2ssh.configuration.ConfigurationException)

Example 2 with HostKeyVerification

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));
}
Also used : IgnoreHostKeyVerification(com.sshtools.j2ssh.transport.IgnoreHostKeyVerification) FromJ2ssHostKeyVerifier(com.jn.agileway.ssh.client.impl.j2ssh.verifier.FromJ2ssHostKeyVerifier) HostKeyVerification(com.sshtools.j2ssh.transport.HostKeyVerification) IgnoreHostKeyVerification(com.sshtools.j2ssh.transport.IgnoreHostKeyVerification) SshException(com.jn.agileway.ssh.client.SshException) File(java.io.File) KnownHostsVerifier(com.jn.agileway.ssh.client.impl.j2ssh.verifier.KnownHostsVerifier)

Aggregations

HostKeyVerification (com.sshtools.j2ssh.transport.HostKeyVerification)2 IgnoreHostKeyVerification (com.sshtools.j2ssh.transport.IgnoreHostKeyVerification)2 SshException (com.jn.agileway.ssh.client.SshException)1 FromJ2ssHostKeyVerifier (com.jn.agileway.ssh.client.impl.j2ssh.verifier.FromJ2ssHostKeyVerifier)1 KnownHostsVerifier (com.jn.agileway.ssh.client.impl.j2ssh.verifier.KnownHostsVerifier)1 SshClient (com.sshtools.j2ssh.SshClient)1 PasswordAuthenticationClient (com.sshtools.j2ssh.authentication.PasswordAuthenticationClient)1 ConfigurationException (com.sshtools.j2ssh.configuration.ConfigurationException)1 File (java.io.File)1