use of net.schmizz.sshj.common.KeyType 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