Hi Basically I need to forward a locally accepted connection using a jsch connection. However I cannot use jsch's own port forwarding, as the ssh connection may only be established, when there is a pending tcp connect request... I have the following code (snippets):
In class Server:
private void accept( SelectionKey key )
throws IOException, JSchException
{
ServerSocketChannel serverSocketChannel =
(ServerSocketChannel) key.channel();
SocketChannel channel = serverSocketChannel.accept();
Server.Port port = (Server.Port) key.attachment();
System.out.println( "Detected SYN for " + port.bindHost +
":" + port.bindPort );
channel.configureBlocking( true );
port.portConnect( channel.socket() );
}
In class Server.Port:
public boolean portConnect( Socket socket )
throws JSchException, IOException
{
if ( ! serverConnect() )
return false;
System.out.println( "Connecting " + bindHost + ":" +
bindPort + " -> " + targetHost + ":" + targetPort );
socket.setTcpNoDelay( true );
Channel channel = session.openChannel( "direct-tcpip" );
( (ChannelDirectTCPIP) channel ).setInputStream(
socket.getInputStream() );
( (ChannelDirectTCPIP) channel ).setOutputStream(
socket.getOutputStream() );
( (ChannelDirectTCPIP) channel ).setHost( targetHost );
( (ChannelDirectTCPIP) channel ).setPort( targetPort );
( (ChannelDirectTCPIP) channel ).setOrgIPAddress(
socket.getInetAddress().getHostAddress() );
( (ChannelDirectTCPIP) channel ).setOrgPort(
socket.getPort() );
try {
channel.connect();
return true;
} catch ( Throwable t ) {
t.printStackTrace();
return false;
}
}
The code should be pretty much self-explaining, but don't hesitate to ask
anything.
This simply does not work. I don't understand why:
I know that it does work up the debug output inside portConnect() by this
output.
Detected SYN for 127.0.0.1:3389
Connecting to xxxxx:22
1: Connecting to xxxxx port 22
1: Connection established
1: Remote version string: SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu1.2
1: Local version string: SSH-2.0-JSCH-0.1.33
1: SSH_MSG_KEXINIT received
1: SSH_MSG_KEXINIT sent
1: kex: server->client 3des-cbc hmac-md5 none
1: kex: client->server 3des-cbc hmac-md5 none
1: SSH_MSG_KEXDH_INIT sent
1: expecting SSH_MSG_KEXDH_REPLY
1: ssh_rsa_verify: signature true
2: Permanently added 'xxxxx' (RSA) to the list of known hosts.
1: SSH_MSG_NEWKEYS sent
1: SSH_MSG_NEWKEYS received
1: SSH_MSG_SERVICE_REQUEST sent
1: SSH_MSG_SERVICE_ACCEPT received
1: Authentications that can continue:
publickey,keyboard-interactive,password
1: Next authentication method: publickey
1: Authentication succeeded (publickey).
Connecting 127.0.0.1:3389 -> xx.xx.xx.xx:3389
Am I doing something strange?
Any hints are welcome.
Regards,
Steffen
smime.p7s
Description: S/MIME cryptographic signature
------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev
_______________________________________________ JSch-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jsch-users
