aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian P. Hinz <bphinz@users.sf.net>2019-11-03 16:00:50 -0500
committerBrian P. Hinz <bphinz@users.sf.net>2019-11-03 16:02:42 -0500
commit71ffc0e70eedf1b71fa92cd0bdc4767c705da953 (patch)
tree749121fed7a6b3cec02f57e9084fe719ee0955c7
parent65b21db9775228506c745ce93cc18aa0b1378da5 (diff)
downloadtigervnc-71ffc0e70eedf1b71fa92cd0bdc4767c705da953.tar.gz
tigervnc-71ffc0e70eedf1b71fa92cd0bdc4767c705da953.zip
Fix for issue #796
-rw-r--r--java/com/tigervnc/vncviewer/CConn.java9
-rw-r--r--java/com/tigervnc/vncviewer/Parameters.java5
-rw-r--r--java/com/tigervnc/vncviewer/Tunnel.java39
3 files changed, 25 insertions, 28 deletions
diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java
index 3aee46d5..75f6b74b 100644
--- a/java/com/tigervnc/vncviewer/CConn.java
+++ b/java/com/tigervnc/vncviewer/CConn.java
@@ -128,15 +128,20 @@ public class CConn extends CConnection implements
int localPort = TcpSocket.findFreeTcpPort();
if (localPort == 0)
throw new Exception("Could not obtain free TCP port");
- Tunnel.createTunnel(this, localPort);
+ String gatewayHost = Tunnel.getSshHost();
+ if (gatewayHost.isEmpty())
+ gatewayHost = getServerName();
+ Tunnel.createTunnel(gatewayHost, getServerName(),
+ getServerPort(), localPort);
sock = new TcpSocket("localhost", localPort);
+ vlog.info("connected to localhost port "+localPort);
} else {
sock = new TcpSocket(getServerName(), getServerPort());
+ vlog.info("connected to host "+getServerName()+" port "+getServerPort());
}
} catch (java.lang.Exception e) {
throw new Exception(e.getMessage());
}
- vlog.info("connected to host "+getServerName()+" port "+getServerPort());
} else {
String name = sock.getPeerEndpoint();
if (listenMode.getValue())
diff --git a/java/com/tigervnc/vncviewer/Parameters.java b/java/com/tigervnc/vncviewer/Parameters.java
index 2f8a585f..aa4be90a 100644
--- a/java/com/tigervnc/vncviewer/Parameters.java
+++ b/java/com/tigervnc/vncviewer/Parameters.java
@@ -183,11 +183,6 @@ public class Parameters {
"specified in an applet parameter or on the command line",
false);
- public static StringParameter vncServerName
- = new StringParameter("Server",
- "The VNC server <host>[:<dpyNum>] or <host>::<port>",
- "");
-
public static BoolParameter acceptBell
= new BoolParameter("AcceptBell",
"Produce a system beep when requested to by the server.",
diff --git a/java/com/tigervnc/vncviewer/Tunnel.java b/java/com/tigervnc/vncviewer/Tunnel.java
index 2e19160a..ecb048b7 100644
--- a/java/com/tigervnc/vncviewer/Tunnel.java
+++ b/java/com/tigervnc/vncviewer/Tunnel.java
@@ -52,18 +52,10 @@ public class Tunnel {
private final static String DEFAULT_VIA_TEMPLATE
= "-f -L %L:%H:%R %G sleep 20";
- public static void createTunnel(CConn cc, int localPort) throws Exception {
- int remotePort;
- String gatewayHost;
- String remoteHost;
-
- remotePort = cc.getServerPort();
- gatewayHost = cc.getServerName();
- remoteHost = "localhost";
- if (!via.getValue().isEmpty()) {
- gatewayHost = getSshHost();
- remoteHost = cc.getServerName();
- }
+ public static void createTunnel(String gatewayHost,
+ String remoteHost,
+ int remotePort,
+ int localPort) throws Exception {
String pattern = extSSHArgs.getValue();
if (pattern == null || pattern.isEmpty()) {
@@ -102,12 +94,12 @@ public class Tunnel {
public static String getSshHost() {
String sshHost = via.getValue();
- if (sshHost.isEmpty())
- return vncServerName.getValue();
- int end = sshHost.indexOf(":");
- if (end < 0)
- end = sshHost.length();
- sshHost = sshHost.substring(sshHost.indexOf("@")+1, end);
+ if (!sshHost.isEmpty()) {
+ int end = sshHost.indexOf(":");
+ if (end < 0)
+ end = sshHost.length();
+ sshHost = sshHost.substring(sshHost.indexOf("@")+1, end);
+ }
return sshHost;
}
@@ -132,7 +124,8 @@ public class Tunnel {
return sshKeyFile.getValue();
String[] ids = { "id_dsa", "id_rsa" };
for (String id : ids) {
- File f = new File(FileUtils.getHomeDir()+".ssh/"+id);
+ File f = new File(FileUtils.getHomeDir()+".ssh"+
+ FileUtils.getFileSeparator()+id);
if (f.exists() && f.canRead())
return(f.getAbsolutePath());
}
@@ -154,7 +147,8 @@ public class Tunnel {
// NOTE: jsch does not support all ciphers. User may be
// prompted to accept host key authenticy even if
// the key is in the known_hosts file.
- File knownHosts = new File(FileUtils.getHomeDir()+".ssh/known_hosts");
+ File knownHosts = new File(FileUtils.getHomeDir()+".ssh"+
+ FileUtils.getFileSeparator()+"known_hosts");
if (knownHosts.exists() && knownHosts.canRead())
jsch.setKnownHosts(knownHosts.getAbsolutePath());
ArrayList<File> privateKeys = new ArrayList<File>();
@@ -196,7 +190,10 @@ public class Tunnel {
if (session.getConfig("StrictHostKeyChecking") == null)
session.setConfig("StrictHostKeyChecking", "ask");
session.connect();
- session.setPortForwardingL(localPort, remoteHost, remotePort);
+ if (gatewayHost.equals(remoteHost))
+ session.setPortForwardingL(localPort, new String("localhost"), remotePort);
+ else
+ session.setPortForwardingL(localPort, remoteHost, remotePort);
} catch (java.lang.Exception e) {
throw new Exception(e.getMessage());
}