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

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

                Author: ASF GitHub Bot
            Created on: 23/Sep/20 08:54
            Start Date: 23/Sep/20 08:54
    Worklog Time Spent: 10m 
      Work Description: gnodet opened a new pull request #170:
URL: https://github.com/apache/mina-sshd/pull/170


   This PR simply adds a unit test for SSHD-1066.


----------------------------------------------------------------
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:
[email protected]


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

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

> Support multiple local interfaces in PortForwarding
> ---------------------------------------------------
>
>                 Key: SSHD-1066
>                 URL: https://issues.apache.org/jira/browse/SSHD-1066
>             Project: MINA SSHD
>          Issue Type: New Feature
>    Affects Versions: 2.5.1
>            Reporter: Guillermo Grandes
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> I'm trying to listen in same port on 2 IPs of same machine, _multihomed_, the 
> equivalent in openssh is:
> {noformat}
> # ssh -L 127.0.0.2:8080:test.javastack.org:80 -L 
> 127.0.0.3:8080:test.javastack.org:80 test-sshd@server -N
> # sudo netstat -lntp | grep :8080
> tcp  0 0  127.0.0.3:8080  0.0.0.0:*  LISTEN  2650/ssh
> tcp  0 0  127.0.0.2:8080  0.0.0.0:*  LISTEN  2650/ssh
> {noformat}
> Sample code to reproduce the test case:
> {code:java}
>       public static final int DEFAULT_TIMEOUT = 10000;
>       public static void test(final String username, final String password, 
> final String host, final int port)
>                       throws IOException {
>               boolean testLocal = true;
>               try (SshClient client = SshClient.setUpDefaultClient()) {
>                       
> client.setServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE);
>                       client.start();
>                       try {
>                               ConnectFuture connect = 
> client.connect(username, host, port);
>                               connect.await(DEFAULT_TIMEOUT);
>                               ClientSession session = 
> connect.getClientSession();
>                               session.addPasswordIdentity(password);
>                               session.auth().verify(DEFAULT_TIMEOUT);
>                               if (testLocal) {
>                                       System.out.println("================== 
> Local 1 ==================");
>                                       ExplicitPortForwardingTracker 
> localTracker1 = session.createLocalPortForwardingTracker(
>                                                       new 
> SshdSocketAddress("127.0.0.2", 8080),
>                                                       new 
> SshdSocketAddress("test.javastack.org", 80));
>                                       sleep(1000);
>                                       
> System.out.println("LocalPortForwarding: " //
>                                                       + 
> localTracker1.getLocalAddress() + " -> " //
>                                                       + 
> localTracker1.getRemoteAddress());
>                                       SshdSocketAddress localSocketAddress1 = 
> localTracker1.getLocalAddress();
>                                       if (localSocketAddress1 != null) {
>                                               Proxy proxy = new 
> Proxy(Proxy.Type.HTTP,
>                                                               new 
> InetSocketAddress(localSocketAddress1.getHostName(), //
>                                                                               
> localSocketAddress1.getPort()));
>                                               testRemoteURL(proxy, 
> "http://test.javastack.org/";);
>                                       }
>                                       System.out.println("================== 
> Local 2 ==================");
>                                       ExplicitPortForwardingTracker 
> localTracker2 = session.createLocalPortForwardingTracker(
>                                                       new 
> SshdSocketAddress("127.0.0.3", 8080),
>                                                       new 
> SshdSocketAddress("test.javastack.org", 80));
>                                       sleep(1000);
>                                       
> System.out.println("LocalPortForwarding: " //
>                                                       + 
> localTracker2.getLocalAddress() + " -> " //
>                                                       + 
> localTracker2.getRemoteAddress());
>                                       SshdSocketAddress localSocketAddress2 = 
> localTracker2.getLocalAddress();
>                                       if (localSocketAddress2 != null) {
>                                               Proxy proxy = new 
> Proxy(Proxy.Type.HTTP,
>                                                               new 
> InetSocketAddress(localSocketAddress2.getHostName(), //
>                                                                               
> localSocketAddress2.getPort()));
>                                               testRemoteURL(proxy, 
> "http://test.javastack.org/";);
>                                       }
>                               }
>                       } 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, final String 
> url) throws IOException {
>               HttpURLConnection connection = (HttpURLConnection) new 
> URL(url).openConnection(proxy);
>               connection.setConnectTimeout(DEFAULT_TIMEOUT);
>               connection.setReadTimeout(DEFAULT_TIMEOUT);
>               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);
>               }
>       }
>       public static void main(String[] args) throws Throwable {
>               test("test-sshd", "secret", "server", 22);
>               sleep(3000);
>       }
> {code}
> Error received:
> {code:none}
> Exception in thread "main" java.io.IOException: Multiple local port 
> forwarding addressing on port=8080: current=test.javastack.org:80, 
> previous=test.javastack.org:80
>       at 
> org.apache.sshd.common.forward.DefaultForwardingFilter.startLocalPortForwarding(DefaultForwardingFilter.java:208)
>       at 
> org.apache.sshd.client.session.AbstractClientSession.startLocalPortForwarding(AbstractClientSession.java:374)
>       at 
> org.apache.sshd.client.session.ClientSession.createLocalPortForwardingTracker(ClientSession.java:316)
>       at 
> org.javastack.jentunnel.sandbox.SimpleBindingTest.test(SimpleBindingTest.java:52)
> {code}
> Result Expected:
> {noformat}
> ================== Local 1 ==================
> LocalPortForwarding: 127.0.0.2:8080 -> test.javastack.org:80
> Get URL: http://test.javastack.org/
> Response from server:
> OK
> ================== Local 2 ==================
> LocalPortForwarding: 127.0.0.3:8080 -> test.javastack.org:80
> Get URL: http://test.javastack.org/
> Response from server:
> OK
> {noformat}
> * Note-1: The usage of loopback addresses (127.0.0.0/8) and same destination 
> is to simplify/reproduce easily, don't care.
> * Note-2: I don't checked if 
> startRemotePortForwarding/startDynamicPortForwarding reproduce same issue as 
> startLocalPortForwarding. But I suppose that yes.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to