You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/07/13 21:43:00 UTC

[jira] [Work logged] (SSHD-1033) Unable to use DynamicPortForwarding + LocalPortForwarding

     [ https://issues.apache.org/jira/browse/SSHD-1033?focusedWorklogId=458326&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-458326 ]

ASF GitHub Bot logged work on SSHD-1033:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Jul/20 21:42
            Start Date: 13/Jul/20 21:42
    Worklog Time Spent: 10m 
      Work Description: ggrandes opened a new pull request #140:
URL: https://github.com/apache/mina-sshd/pull/140


   [Bug SSHD-1033]: Unable to use DynamicPortForwarding + LocalPortForwarding


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 458326)
    Remaining Estimate: 0h
            Time Spent: 10m

> 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
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> 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[testuser@/192.168.x.x: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 static 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()));
> 						testRemoteURL(proxy);
> 					}
> 				}
> 				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()));
> 						testRemoteURL(proxy);
> 					}
> 				}
> 				// @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) {
> 		}
> 	}
> 	private static final void testRemoteURL(final Proxy proxy) throws IOException {
> 		HttpURLConnection connection = (HttpURLConnection) new URL("http://test.javastack.org/")
> 				.openConnection(proxy);
> 		System.out.println("Get 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);
> 		}
> 	}
> }
> {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: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org