Search in sources :

Example 1 with SshClient

use of com.sshtools.client.SshClient in project agileway by fangjinuo.

the class SynergyConnection method authenticateWithPublicKey.

@Override
public boolean authenticateWithPublicKey(String user, byte[] pemPrivateKey, String passphrase) throws SshException {
    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(pemPrivateKey);
        SshKeyPair keyPair = SshKeyUtils.getPrivateKey(inputStream, passphrase);
        SshClientContext context = new SshClientContext();
        context.setUsername(user);
        context.setHostKeyVerification(new ToSynergyHostKeyVerifierAdapter(this.hostKeyVerifier));
        client = new SshClient(sshConfig.getHost(), sshConfig.getPort(), user, context, keyPair);
        if (client.isConnected()) {
            setStatus(SshConnectionStatus.CONNECTED);
        }
        return true;
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : SshKeyPair(com.sshtools.common.ssh.components.SshKeyPair) SshClientContext(com.sshtools.client.SshClientContext) ToSynergyHostKeyVerifierAdapter(com.jn.agileway.ssh.client.impl.synergy.verifier.ToSynergyHostKeyVerifierAdapter) SshClient(com.sshtools.client.SshClient) ByteArrayInputStream(java.io.ByteArrayInputStream) SshException(com.jn.agileway.ssh.client.SshException)

Example 2 with SshClient

use of com.sshtools.client.SshClient in project agileway by fangjinuo.

the class SynergyConnection method authenticateWithPassword.

@Override
public boolean authenticateWithPassword(String user, String password) throws SshException {
    try {
        SshClientContext context = new SshClientContext();
        context.setHostKeyVerification(new ToSynergyHostKeyVerifierAdapter(this.hostKeyVerifier));
        client = new SshClient(sshConfig.getHost(), sshConfig.getPort(), user, context, 30000L, password.toCharArray());
        if (client.isConnected()) {
            setStatus(SshConnectionStatus.CONNECTED);
        }
        return true;
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : SshClientContext(com.sshtools.client.SshClientContext) ToSynergyHostKeyVerifierAdapter(com.jn.agileway.ssh.client.impl.synergy.verifier.ToSynergyHostKeyVerifierAdapter) SshClient(com.sshtools.client.SshClient) SshException(com.jn.agileway.ssh.client.SshException)

Aggregations

SshException (com.jn.agileway.ssh.client.SshException)2 ToSynergyHostKeyVerifierAdapter (com.jn.agileway.ssh.client.impl.synergy.verifier.ToSynergyHostKeyVerifierAdapter)2 SshClient (com.sshtools.client.SshClient)2 SshClientContext (com.sshtools.client.SshClientContext)2 SshKeyPair (com.sshtools.common.ssh.components.SshKeyPair)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1