use of com.amaze.filemanager.filesystem.ssh.CustomSshJConfig in project AmazeFileManager by TeamAmaze.
the class GetSshHostFingerprintTask method doInBackground.
@Override
protected AsyncTaskResult<PublicKey> doInBackground(Void... voids) {
final AtomicReference<AsyncTaskResult<PublicKey>> holder = new AtomicReference<AsyncTaskResult<PublicKey>>();
final CountDownLatch latch = new CountDownLatch(1);
final SSHClient sshClient = new SSHClient(new CustomSshJConfig());
sshClient.setConnectTimeout(SSH_CONNECT_TIMEOUT);
sshClient.addHostKeyVerifier((hostname, port, key) -> {
holder.set(new AsyncTaskResult<PublicKey>(key));
latch.countDown();
return true;
});
try {
sshClient.connect(hostname, port);
latch.await();
} catch (IOException e) {
e.printStackTrace();
holder.set(new AsyncTaskResult<PublicKey>(e));
latch.countDown();
} catch (InterruptedException e) {
e.printStackTrace();
holder.set(new AsyncTaskResult<PublicKey>(e));
latch.countDown();
} finally {
SshClientUtils.tryDisconnect(sshClient);
return holder.get();
}
}
use of com.amaze.filemanager.filesystem.ssh.CustomSshJConfig in project AmazeFileManager by TeamAmaze.
the class SshAuthenticationTask method doInBackground.
@Override
protected AsyncTaskResult<SSHClient> doInBackground(Void... voids) {
final SSHClient sshClient = new SSHClient(new CustomSshJConfig());
sshClient.addHostKeyVerifier(hostKey);
sshClient.setConnectTimeout(SSH_CONNECT_TIMEOUT);
try {
sshClient.connect(hostname, port);
if (password != null && !"".equals(password)) {
sshClient.authPassword(username, password);
return new AsyncTaskResult<SSHClient>(sshClient);
} else {
sshClient.authPublickey(username, new KeyProvider() {
@Override
public PrivateKey getPrivate() throws IOException {
return privateKey.getPrivate();
}
@Override
public PublicKey getPublic() throws IOException {
return privateKey.getPublic();
}
@Override
public KeyType getType() throws IOException {
return KeyType.fromKey(getPublic());
}
});
return new AsyncTaskResult<SSHClient>(sshClient);
}
} catch (UserAuthException e) {
e.printStackTrace();
return new AsyncTaskResult<SSHClient>(e);
} catch (TransportException e) {
e.printStackTrace();
return new AsyncTaskResult<SSHClient>(e);
} catch (IOException e) {
e.printStackTrace();
return new AsyncTaskResult<SSHClient>(e);
}
}
Aggregations