use of net.schmizz.sshj.DefaultConfig in project dbeaver by dbeaver.
the class SSHImplementationSshj method setupTunnel.
@Override
protected void setupTunnel(DBRProgressMonitor monitor, DBWHandlerConfiguration configuration, String dbHost, String sshHost, String aliveInterval, int sshPortNum, File privKeyFile, int connectTimeout, int dbPort, int localPort) throws DBException, IOException {
try {
Config clientConfig = new DefaultConfig();
clientConfig.setLoggerFactory(LoggerFactory.DEFAULT);
sshClient = new SSHClient(clientConfig);
// TODO: make real host verifier
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
String sshUser = configuration.getUserName();
String sshPassword = configuration.getPassword();
try {
sshClient.loadKnownHosts();
} catch (IOException e) {
log.warn("Error loading known hosts", e);
}
sshClient.connect(sshHost);
if (privKeyFile != null) {
if (!CommonUtils.isEmpty(sshPassword)) {
KeyProvider keyProvider = sshClient.loadKeys(privKeyFile.getAbsolutePath(), sshPassword.toCharArray());
sshClient.authPublickey(sshUser, keyProvider);
} else {
sshClient.authPublickey(sshUser, privKeyFile.getAbsolutePath());
}
} else {
sshClient.authPassword(sshUser, sshPassword);
}
log.debug("Instantiate SSH tunnel");
final LocalPortForwarder.Parameters params = new LocalPortForwarder.Parameters(SSHConstants.LOCALHOST_NAME, localPort, dbHost, dbPort);
portListener = new LocalPortListener(params);
portListener.start();
RuntimeUtils.pause(100);
} catch (Exception e) {
throw new DBException("Cannot establish tunnel", e);
}
}
Aggregations