I would like to use JSch to create a secure tunnel to the target host and
use this tunnel to transport bytes for a mysql connection. But I would not
like that this tunnel would be accessible from any other user logged in the
same machine.
Is that feasible?
TIA
Leo
example
public class Tunnel {
/**
* @param args
* @throws JSchException
* @throws SQLException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws JSchException,
ClassNotFoundException, SQLException {
Tunnel t = new Tunnel();
t.go();
}
private void go() throws JSchException, ClassNotFoundException,
SQLException {
JSch.setConfig("StrictHostKeyChecking", "no");
JSch j = new JSch();
Session s = j.getSession("mylogin", "192.168.56.101", 22);
s.setPassword("xxx");
UI ui = new UI();
s.setUserInfo(ui);
int tout = 100;
s.connect(tout);
int lport = 9999;
String host = "localhost";
int rport = 3306;
s.setPortForwardingL(lport, host, rport);//open tunnel
//this section, localhost accepts mysql connections so it's insecure
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:"+lport+"/DB","root",
"xxx");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("show tables");
while(rs.next()){
System.out.println(rs.getString(1));
}
rs.close();
conn.close();
//end of the insecure section
s.delPortForwardingL(lport);//close tunnel
s.disconnect();
System.out.println("ok");
}
}
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users