mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (Jira)" <j...@apache.org>
Subject [jira] [Work logged] (SSHD-1066) Support multiple local interfaces in PortForwarding
Date Thu, 29 Oct 2020 17:31:00 GMT

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

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

                Author: ASF GitHub Bot
            Created on: 29/Oct/20 17:30
            Start Date: 29/Oct/20 17:30
    Worklog Time Spent: 10m 
      Work Description: lgoldstein closed pull request #175:
URL: https://github.com/apache/mina-sshd/pull/175


   


----------------------------------------------------------------
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: 506309)
    Time Spent: 0.5h  (was: 20m)

> 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
>            Assignee: Lyor Goldstein
>            Priority: Major
>          Time Spent: 0.5h
>  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: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org


Mime
View raw message