You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/12/17 11:27:03 UTC
[2/4] mina-sshd git commit: [SSHD-792] Echo original host used to
establish a 'fowarded-tcpip' channel when creating the client-side forwarding
channel
[SSHD-792] Echo original host used to establish a 'fowarded-tcpip' channel when creating the client-side forwarding channel
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/25df45bc
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/25df45bc
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/25df45bc
Branch: refs/heads/master
Commit: 25df45bc9da3e1162d0368cdf42bc12444ac561a
Parents: ab96618
Author: Lyor Goldstein <lg...@apache.org>
Authored: Sun Dec 16 12:00:42 2018 +0200
Committer: Lyor Goldstein <lg...@apache.org>
Committed: Mon Dec 17 13:26:56 2018 +0200
----------------------------------------------------------------------
.../common/forward/DefaultForwardingFilter.java | 35 +++++++++++++++++---
.../sshd/common/forward/TcpipClientChannel.java | 29 ++++++++--------
.../sshd/server/global/TcpipForwardHandler.java | 2 +-
3 files changed, 47 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25df45bc/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java
index 9100f4e..7235b26 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java
@@ -1008,14 +1008,39 @@ public class DefaultForwardingFilter
InetSocketAddress local = (InetSocketAddress) session.getLocalAddress();
int localPort = local.getPort();
SshdSocketAddress remote = localToRemote.get(localPort);
- if (debugEnabled) {
- log.debug("sessionCreated({}) remote={}", session, remote);
- }
-
- TcpipClientChannel.Type channelType = (remote == null) ? TcpipClientChannel.Type.Forwarded : TcpipClientChannel.Type.Direct;
+ TcpipClientChannel.Type channelType = (remote == null)
+ ? TcpipClientChannel.Type.Forwarded
+ : TcpipClientChannel.Type.Direct;
TcpipClientChannel channel = new TcpipClientChannel(channelType, session, remote);
session.setAttribute(TcpipClientChannel.class, channel);
+ // Propagate original requested host name - see SSHD-792
+ if (channelType == TcpipClientChannel.Type.Forwarded) {
+ SocketAddress accepted = session.getAcceptanceAddress();
+ LocalForwardingEntry localEntry = null;
+ if (accepted instanceof InetSocketAddress) {
+ synchronized (localForwards) {
+ localEntry = LocalForwardingEntry.findMatchingEntry(
+ ((InetSocketAddress) accepted).getHostString(), localPort, localForwards);
+ }
+ }
+
+ if (localEntry != null) {
+ if (debugEnabled) {
+ log.debug("sessionCreated({})[local={}, remote={}, accepted={}] localEntry={}",
+ session, local, remote, accepted, localEntry);
+ }
+ channel.updateLocalForwardingEntry(localEntry);
+ } else {
+ log.warn("sessionCreated({})[local={}, remote={}] cannot locate original local entry for accepted={}",
+ session, local, remote, accepted);
+ }
+ } else {
+ if (debugEnabled) {
+ log.debug("sessionCreated({}) local={}, remote={}", session, local, remote);
+ }
+ }
+
service.registerChannel(channel);
channel.open().addListener(future -> {
Throwable t = future.getException();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25df45bc/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
index 0e1e2aa..37dd824 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
@@ -19,7 +19,6 @@
package org.apache.sshd.common.forward;
import java.io.IOException;
-import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.EnumSet;
@@ -75,6 +74,7 @@ public class TcpipClientChannel extends AbstractClientChannel implements Forward
protected final SshdSocketAddress remote;
protected final IoSession serverSession;
+ protected SshdSocketAddress localEntry;
private final Type typeEnum;
private final ClientChannelPendingMessagesQueue messagesQueue;
@@ -85,6 +85,7 @@ public class TcpipClientChannel extends AbstractClientChannel implements Forward
super(Objects.requireNonNull(type, "No type specified").getName());
this.typeEnum = type;
this.serverSession = Objects.requireNonNull(serverSession, "No server session provided");
+ this.localEntry = new SshdSocketAddress((InetSocketAddress) serverSession.getLocalAddress());
this.remote = remote;
this.messagesQueue = new ClientChannelPendingMessagesQueue(this);
}
@@ -101,25 +102,29 @@ public class TcpipClientChannel extends AbstractClientChannel implements Forward
return messagesQueue;
}
+ public void updateLocalForwardingEntry(LocalForwardingEntry entry) {
+ Objects.requireNonNull(entry, "No local forwarding entry provided");
+ localEntry = new SshdSocketAddress(entry.getAlias(), entry.getPort());
+ }
+
@Override
public synchronized OpenFuture open() throws IOException {
InetSocketAddress src;
- InetSocketAddress dst;
+ SshdSocketAddress dst;
+ InetSocketAddress loc = (InetSocketAddress) serverSession.getLocalAddress();
Type openType = getTcpipChannelType();
switch (openType) {
- case Direct: {
+ case Direct:
src = (InetSocketAddress) serverSession.getRemoteAddress();
- dst = this.remote.toInetSocketAddress();
- InetSocketAddress loc = (InetSocketAddress) serverSession.getLocalAddress();
+ dst = this.remote;
tunnelEntrance = new SshdSocketAddress(loc.getHostString(), loc.getPort());
- tunnelExit = new SshdSocketAddress(dst.getHostString(), dst.getPort());
+ tunnelExit = new SshdSocketAddress(dst.getHostName(), dst.getPort());
break;
- }
case Forwarded:
src = (InetSocketAddress) serverSession.getRemoteAddress();
- dst = (InetSocketAddress) serverSession.getLocalAddress();
+ dst = localEntry;
tunnelEntrance = new SshdSocketAddress(src.getHostString(), src.getPort());
- tunnelExit = new SshdSocketAddress(dst.getHostString(), dst.getPort());
+ tunnelExit = new SshdSocketAddress(loc.getHostString(), loc.getPort());
break;
default:
throw new SshException("Unknown client channel type: " + openType);
@@ -137,10 +142,8 @@ public class TcpipClientChannel extends AbstractClientChannel implements Forward
}
Session session = getSession();
- InetAddress srcAddress = src.getAddress();
- String srcHost = srcAddress.getHostAddress();
- InetAddress dstAddress = dst.getAddress();
- String dstHost = dstAddress.getHostAddress();
+ String srcHost = src.getHostString();
+ String dstHost = dst.getHostName();
Window wLocal = getLocalWindow();
String type = getChannelType();
Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25df45bc/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
index b0ecbf3..a35def2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
@@ -63,7 +63,7 @@ public class TcpipForwardHandler extends AbstractConnectionServiceRequestHandler
SshdSocketAddress bound = forwarder.localPortForwardingRequested(socketAddress);
if (log.isDebugEnabled()) {
log.debug("process({})[{}][want-reply-{}] {} => {}",
- connectionService, request, wantReply, socketAddress, bound);
+ connectionService, request, wantReply, socketAddress, bound);
}
if (bound == null) {