Skip to content

Commit

Permalink
Viewer: Fix SSH port configuration hierarchy
Browse files Browse the repository at this point in the history
dda0283 intended to implement the
following configuration hierarchy for the SSH port:

1. The SSHPort parameter (specified on the command line or in a
   connection info file)
2. The OpenSSH config file (specified in the SSHConfig parameter, which
   defaults to ~/.ssh/config)
3. The default value of the SSHPort parameter (specified in
   ~/.vnc/default.turbovnc, otherwise 22)

Due to an oversight, however, the initial implementation required the
SSH port to be specified either in the SSHPort parameter or an OpenSSH
config file, or an IllegalArgumentException occurred (as a result of -1
being passed to the java.net.Socket constructor.)
053e754 attempted to address that issue
by modifying com.jcraft.jsch.Session.applyConfig(), but that method is
only called if an OpenSSH config file exists or is specified.  Otherwise
an IllegalArgumentException still occurred.  Furthermore, the value of
SSHPort in ~/.vnc/default.turbovnc was ignored.  This commit addresses
both issues.
  • Loading branch information
dcommander committed Jan 9, 2025
1 parent 80b6d96 commit c113222
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions java/com/turbovnc/vncviewer/Tunnel.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2012-2015, 2017-2018, 2020-2024 D. R. Commander.
/* Copyright (C) 2012-2015, 2017-2018, 2020-2025 D. R. Commander.
* All Rights Reserved.
* Copyright (C) 2021 Steffen Kieß
* Copyright (C) 2012, 2016 Brian P. Hinz. All Rights Reserved.
Expand Down Expand Up @@ -174,7 +174,7 @@ protected static void createTunnelJSch(String host, Params params)
}

// username and passphrase will be given via UserInfo interface.
int port = params.sshPort.isDefault() ? -1 : params.sshPort.get();
int port = params.sshPort.get();
String user = params.sshUser.get();

File sshConfigFile = new File(params.sshConfig.get());
Expand All @@ -186,6 +186,9 @@ protected static void createTunnelJSch(String host, Params params)
String repoUser = repo.getConfig(host).getUser();
if (repoUser != null && user == null)
user = repoUser;
int repoPort = repo.getConfig(host).getPort();
if (repoPort != -1 && params.sshPort.isDefault())
port = repoPort;
String[] identityFiles = repo.getConfig(host).getValues("IdentityFile");
if (identityFiles != null) {
for (String file : identityFiles) {
Expand Down

0 comments on commit c113222

Please sign in to comment.