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);
}
}
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);
}
}
Aggregations