Skip to content

Commit

Permalink
Viewer: Remove SSHUser parameter
Browse files Browse the repository at this point in the history
The parameter was redundant, and removing it allows separate SSH
usernames to be specified for the Server and Via parameters (which will
be important when supporting SSH jump hosts.)

Also modify JSch so that it always prints the final host, port, and SSH
username, regardless of the logging level.
  • Loading branch information
dcommander committed Nov 23, 2024
1 parent fe4c2de commit e1f81d2
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 94 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ SSH client now allows the value of the `SSHPort` parameter, if specified on the
command line or in a connection info file, to override any SSH ports specified
in the OpenSSH config file.

10. The TurboVNC Viewer's `SSHUser` parameter has been removed. SSH usernames
should now be specified by prefixing the VNC host or the gateway host with the
username followed by @. This fixes an issue whereby separate SSH usernames
could not be specified for the `Server` and `Via` parameters.


3.1.3
=====
Expand Down
4 changes: 2 additions & 2 deletions java/com/jcraft/jsch/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ public void connect(int connectTimeout) throws JSchException{
}
Packet.setRandom(random);

if(JSch.getLogger().isEnabled(Logger.INFO)){
JSch.getLogger().log(Logger.INFO,
if(JSch.getLogger().isEnabled(Logger.ERROR)){
JSch.getLogger().log(Logger.ERROR,
"Connecting to "+host+" port "+port+" with username "+username);
}

Expand Down
4 changes: 2 additions & 2 deletions java/com/turbovnc/rfb/Hostname.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static String getSSHUser(String vncServerName) {
String sshUser = null;

if (atPos >= 0) {
sshUser = vncServerName.substring(0, atPos).replaceAll("\\s", "");
sshUser = vncServerName.substring(0, atPos);
if (sshUser.length() > 0)
return sshUser;
}
Expand All @@ -92,7 +92,7 @@ public static String getHost(String vncServerName) {
return "localhost";
if (colonPos == -1 || colonPos < atPos)
colonPos = vncServerName.length();
return vncServerName.substring(atPos + 1, colonPos).replaceAll("\\s", "");
return vncServerName.substring(atPos + 1, colonPos);
}

public static int getPort(String vncServerName) {
Expand Down
31 changes: 16 additions & 15 deletions java/com/turbovnc/rfb/Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ public void save(String node) {
"you to remotely start a new TurboVNC session or to choose an existing " +
"session to which to connect.\n " : "\n ") +

"When using the Tunnel parameter" +
(Utils.getBooleanProperty("turbovnc.sessmgr", true) ?
" or the TurboVNC Session Manager, " : ", ") +
"the SSH username (default = local username) can be specified by " +
"prefixing the VNC host with the username followed by @.\n " +

"In Unix domain socket paths, ~ is expanded to the user's home directory " +
"on the VNC host, %h is expanded to the VNC host name (from the point of " +
"view of the VNC host), %i is expanded to the numeric user ID on the VNC " +
Expand Down Expand Up @@ -999,9 +1005,11 @@ public void save(String node) {

"Patterns beginning with the \"%\" character are expanded as follows:\r " +
"%% --> a literal \"%\" character\r " +
"%G --> gateway host name or IP address\r " +
"%H --> remote VNC host name or IP address (if using the Via parameter, " +
"then this is specified from the point of view of the gateway)\r " +
"%G --> gateway host name or IP address, including the SSH username if " +
"specified\r " +
"%H --> remote VNC host name or IP address, including the SSH username if " +
"specified (if using the Via parameter, then the VNC host is specified " +
"from the point of view of the gateway)\r " +
"%L --> local TCP port number\r " +
"%R --> remote TCP port number or the escaped name of a Unix domain " +
"socket on the VNC host\r " +
Expand Down Expand Up @@ -1169,17 +1177,6 @@ public void save(String node) {
"When using the built-in SSH client, this parameter specifies the TCP " +
"port on which the SSH server is listening.", 22, 0, 65535);

public StringParameter sshUser =
new StringParameter("SSHUser", this, true, false,
"The username (default = local username) that should be used when " +
"authenticating with the SSH server. When using the Tunnel parameter" +
(Utils.getBooleanProperty("turbovnc.sessmgr", true) ?
" or the TurboVNC Session Manager, " : ", ") +
"the SSH username can also be specified by prefixing the VNC host with " +
"the username followed by @. When using the Via parameter with an SSH " +
"server, the SSH username can also be specified by prefixing the gateway " +
"host with the username followed by @.", null);

public BoolParameter tunnel =
new BoolParameter("Tunnel", this, true, false,
"Setting this parameter is equivalent to using the Via parameter with an " +
Expand Down Expand Up @@ -1216,7 +1213,11 @@ public void save(String node) {
"the same host and listening on port 5900 (VNC display :0.) If using the " +
"UltraVNC Repeater in \"Mode II\", specify ID:xxxx as the VNC server " +
"name, where xxxx is the ID number of the VNC server to which you want to " +
"connect.", null);
"connect.\n " +

"When using an SSH gateway, the SSH username (default = local username) " +
"can be specified by prefixing the gateway host with the username " +
"followed by @.", null);

public StringParameter x509ca =
new StringParameter("X509CA", this, true, false,
Expand Down
18 changes: 2 additions & 16 deletions java/com/turbovnc/rfb/ServerNameParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,14 @@ public ServerNameParameter(String name, Params params, boolean isGUI,
}

public synchronized boolean set(String str) {
if (str != null && !str.isEmpty()) {
if (str != null && !str.isEmpty())
str = str.replaceAll("\\s", "");
int atIndex = str.lastIndexOf('@');
if (atIndex >= 0) {
params.sshUser.set(str.substring(0, atIndex));
if (isCommandLine() || getName().equalsIgnoreCase("Server"))
params.sshUser.setCommandLine(true);
return super.set(str.substring(atIndex + 1));
}
}
return super.set(str);
}

public synchronized boolean setDefault(String str) {
if (str != null && !str.isEmpty()) {
if (str != null && !str.isEmpty())
str = str.replaceAll("\\s", "");
int atIndex = str.lastIndexOf('@');
if (atIndex >= 0) {
params.sshUser.setDefault(str.substring(0, atIndex));
return super.setDefault(str.substring(atIndex + 1));
}
}
return super.setDefault(str);
}
}
48 changes: 21 additions & 27 deletions java/com/turbovnc/vncviewer/OptionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class OptionsDialog extends Dialog implements ActionListener, ChangeListener,
secTLSPlain, secX509None, secX509Vnc, secX509Plain, secUnixLogin;
private JPanel encNonePanel, encTLSPanel, encX509Panel;
private JCheckBox sendLocalUsername, tunnel;
private JTextField username, sshUser, gateway;
private JLabel usernameLabel, sshUserLabel, gatewayLabel;
private JTextField username, gateway;
private JLabel usernameLabel, gatewayLabel, gatewayLabel2;
private JButton okButton, cancelButton;
private JButton x509caButton, x509crlButton;
private JLabel x509caLabel, x509crlLabel;
Expand Down Expand Up @@ -667,37 +667,33 @@ class OptionsDialog extends Dialog implements ActionListener, ChangeListener,

JPanel gatewayPanel = new JPanel(new GridBagLayout());
gatewayPanel.setBorder(
BorderFactory.createTitledBorder("Gateway (SSH server or UltraVNC repeater)"));
BorderFactory.createTitledBorder("Gateway"));
gatewayLabel =
new JLabel("host:displayNum, host::port = UltraVNC repeater");
gatewayLabel2 =
new JLabel("[user@]host = SSH server");
gateway = new JTextField("", 1);
filterWhitespace(gateway);
gatewayLabel = new JLabel("Host:");
sshUser = new JTextField("", 1);
sshUserLabel = new JLabel("SSH user:");
tunnel = new JCheckBox("Use VNC server as gateway");
tunnel.addItemListener(this);

Dialog.addGBComponent(sshUserLabel, gatewayPanel,
0, 0, 1, 1, 2, 2, 0, 0,
GridBagConstraints.NONE,
GridBagConstraints.FIRST_LINE_START,
new Insets(8, 8, 0, 2));
Dialog.addGBComponent(sshUser, gatewayPanel,
1, 0, 1, 1, 2, 2, 0.7, 0,
GridBagConstraints.HORIZONTAL,
GridBagConstraints.FIRST_LINE_START,
new Insets(4, 2, 0, 2));
Dialog.addGBComponent(gatewayLabel, gatewayPanel,
2, 0, 1, 1, 2, 2, 0, 0,
GridBagConstraints.NONE,
GridBagConstraints.FIRST_LINE_START,
new Insets(8, 2, 0, 2));
0, 0, 1, 1, 0, 0, 1, 1,
GridBagConstraints.HORIZONTAL,
GridBagConstraints.CENTER,
new Insets(0, 5, 0, 5));
Dialog.addGBComponent(gatewayLabel2, gatewayPanel,
0, 1, 1, 1, 0, 0, 1, 1,
GridBagConstraints.HORIZONTAL,
GridBagConstraints.CENTER,
new Insets(0, 5, 0, 5));
Dialog.addGBComponent(gateway, gatewayPanel,
3, 0, 1, 1, 2, 2, 1, 0,
0, 2, 1, 1, 2, 2, 1, 0,
GridBagConstraints.HORIZONTAL,
GridBagConstraints.FIRST_LINE_START,
new Insets(4, 2, 0, 5));
Dialog.addGBComponent(tunnel, gatewayPanel,
0, 1, 4, 1, 2, 2, 1, 1,
0, 3, 4, 1, 2, 2, 1, 1,
GridBagConstraints.HORIZONTAL,
GridBagConstraints.FIRST_LINE_START,
new Insets(4, 5, 0, 5));
Expand Down Expand Up @@ -991,6 +987,7 @@ else if (sf == ScaleParameter.FIXEDRATIO)
if (s instanceof JCheckBox && (JCheckBox)s == tunnel) {
gateway.setEnabled(!tunnel.isSelected());
gatewayLabel.setEnabled(!tunnel.isSelected());
gatewayLabel2.setEnabled(!tunnel.isSelected());
}
}

Expand Down Expand Up @@ -1262,7 +1259,6 @@ public void setOptions(boolean enableDesktopSize, boolean disableShared,
x509crl.setText(params.x509crl.get());

// Security: Gateway
sshUser.setText(params.sshUser.get());
gateway.setText(params.via.get());
tunnel.setSelected(params.tunnel.get());

Expand Down Expand Up @@ -1295,10 +1291,9 @@ public void setOptions(boolean enableDesktopSize, boolean disableShared,
x509crlLabel.setEnabled(false);
}
if (disableSSH) {
sshUser.setEnabled(false);
sshUserLabel.setEnabled(false);
gateway.setEnabled(false);
gatewayLabel.setEnabled(false);
gatewayLabel2.setEnabled(false);
gateway.setEnabled(false);
tunnel.setEnabled(false);
}
}
Expand Down Expand Up @@ -1374,7 +1369,6 @@ public void getOptions() {
params.x509crl.set(x509crl.getText().isEmpty() ? null : x509crl.getText());

// Security: Gateway
params.sshUser.set(sshUser.getText().isEmpty() ? null : sshUser.getText());
params.via.set(gateway.getText().isEmpty() ? null : gateway.getText());
params.tunnel.set(tunnel.isSelected());

Expand Down
2 changes: 1 addition & 1 deletion java/com/turbovnc/vncviewer/SessionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static String createSession(Params params) throws Exception {
vlog.debug("Opening SSH connection to host " + host);
VncViewer.noExceptionDialog =
Utils.getBooleanProperty("turbovnc.sshkeytest", false);
createTunnelJSch(host, params);
createTunnelJSch(Hostname.getSSHUser(params.server.get()), host, params);
if (Utils.getBooleanProperty("turbovnc.sshkeytest", false)) {
System.out.println("SSH SUCCEEDED");
System.exit(0);
Expand Down
Loading

0 comments on commit e1f81d2

Please sign in to comment.