Guillermo Grandes created SSHD-1033:
---------------------------------------
Summary: Unable to use DynamicPortForwarding + LocalPortForwarding
Key: SSHD-1033
URL: https://issues.apache.org/jira/browse/SSHD-1033
Project: MINA SSHD
Issue Type: Bug
Affects Versions: 2.5.1
Reporter: Guillermo Grandes
This is the error running LocalForwarder + DynamicForwarder:
{code:none}
[sshd-SshClient[457e2f02]-nio2-thread-6] WARN
org.apache.sshd.common.forward.DefaultForwardingFilter -
sessionCreated(Nio2Session[local=/127.0.0.1:8000,
remote=/127.0.0.1:57657])[local=/127.0.0.1:8000, remote=null] cannot locate
original local entry for accepted=/127.0.0.1:8000
[sshd-SshClient[457e2f02]-nio2-thread-2] WARN
org.apache.sshd.client.channel.ClientChannelPendingMessagesQueue -
operationComplete(ClientChannelPendingMessagesQueue[channel=TcpipClientChannel[id=1,
recipient=-1]-ClientSessionImpl[fake-test@/192.168.7.5:22], open=false])
SshChannelOpenException[open failed] signaled
[sshd-SshClient[457e2f02]-nio2-thread-2] WARN
org.apache.sshd.common.forward.DefaultForwardingFilter - Failed
(SshChannelOpenException) to open channel for
session=Nio2Session[local=/127.0.0.1:8000, remote=/127.0.0.1:57657]: open failed
{code}
This is the code to reproduce.
* When testLocal = true, testDynamic = true; dynamic fail.
* if the order of test are inverted, fail the local instead of dynamic.
* if one test is false, the other works well.
{code:java}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.future.ConnectFuture;
import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.session.forward.DynamicPortForwardingTracker;
import org.apache.sshd.client.session.forward.ExplicitPortForwardingTracker;
import org.apache.sshd.common.util.net.SshdSocketAddress;
public class SSHClient {
public void test(final String username, final String password, final
String host, final int port)
throws IOException {
boolean testLocal = true, testDynamic = true;
try (SshClient client = SshClient.setUpDefaultClient()) {
client.setServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE);
client.start();
try {
ConnectFuture connect =
client.connect(username, host, port);
connect.await(10000);
ClientSession session =
connect.getClientSession();
session.addPasswordIdentity(password);
session.auth().verify(10000);
if (testLocal) {
System.out.println("==================
Local ==================");
ExplicitPortForwardingTracker
localTracker = session.createLocalPortForwardingTracker(
new
SshdSocketAddress("localhost", 8082),
new
SshdSocketAddress("test.javastack.org", 80));
sleep(1000);
System.out.println("LocalPortForwarding: " //
+
localTracker.getLocalAddress() + " -> " //
+
localTracker.getRemoteAddress());
SshdSocketAddress localSocketAddress =
localTracker.getLocalAddress();
if (localSocketAddress != null) {
Proxy proxy = new
Proxy(Proxy.Type.HTTP,
new
InetSocketAddress(localSocketAddress.getHostName(), //
localSocketAddress.getPort()));
HttpURLConnection connection =
(HttpURLConnection) new URL(
"http://test.javastack.org/").openConnection(proxy);
System.out.println("Proxy URL:
" + connection.getURL());
try {
BufferedReader in = new
BufferedReader(
new
InputStreamReader(connection.getInputStream()));
System.out.println("Response from server:");
String inputLine;
while ((inputLine =
in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
} catch (Exception e) {
System.out.println("Failed: " + e);
}
}
}
if (testDynamic) {
System.out.println("==================
Dynamic ==================");
DynamicPortForwardingTracker
dynamicTracker = session
.createDynamicPortForwardingTracker(new SshdSocketAddress("localhost", 8000));
sleep(1000);
System.out.println("DynamicPortForwarding: " //
+
dynamicTracker.getLocalAddress());
SshdSocketAddress dynamicSocketAddress
= dynamicTracker.getLocalAddress();
if (dynamicSocketAddress != null) {
Proxy proxy = new
Proxy(Proxy.Type.SOCKS,
new
InetSocketAddress(dynamicSocketAddress.getHostName(), //
dynamicSocketAddress.getPort()));
HttpURLConnection connection =
(HttpURLConnection) new URL(
"http://test.javastack.org/").openConnection(proxy);
System.out.println("Proxy URL:
" + connection.getURL());
try {
BufferedReader in = new
BufferedReader(
new
InputStreamReader(connection.getInputStream()));
System.out.println("Response from server:");
String inputLine;
while ((inputLine =
in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
} catch (Exception e) {
System.out.println("Failed: " + e);
}
}
}
// @see
org.apache.sshd.common.forward.DefaultForwardingFilter#sessionCreated
sleep(1000);
} finally {
client.stop();
}
}
}
private static final void sleep(final long t) {
try {
Thread.sleep(t);
} catch (Exception ign) {
}
}
}
{code}
{code:xml}
<!-- dependencies used --->
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]