Skip to content

Commit

Permalink
JSch: Fix SSH conn fail if ConnectTimeout too low
Browse files Browse the repository at this point in the history
JSch expects ConnectTimeout to be in milliseconds, but OpenSSH specifies
that it should be in seconds, so we need to convert the value after it
is read from the OpenSSH config file.

Fixes #439
  • Loading branch information
dcommander committed Jan 22, 2025
1 parent 095c380 commit 8b01463
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ NullPointerException if a cipher algorithm supported by the SSH server but not
by the SSH client was specified using the `Ciphers` OpenSSH config file
keyword.

9. Fixed an issue in the TurboVNC Viewer's built-in SSH client whereby the SSH
connection timeout specified using the `ConnectTimeout` OpenSSH config file
keyword was interpreted as milliseconds rather than seconds. This caused the
SSH connection to fail if the timeout was too low.


3.1.3
=====
Expand Down
15 changes: 14 additions & 1 deletion java/com/jcraft/jsch/OpenSSHConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2013-2018 ymnk, JCraft,Inc. All rights reserved.
Copyright (c) 2019, 2023 D. R. Commander. All rights reserved.
Copyright (c) 2019, 2023, 2025 D. R. Commander. All rights reserved.
Copyright (c) 2020-2021 Jeremy Norris. All rights reserved.
Copyright (c) 2021 Matthias Wiedemann. All rights reserved.
Expand Down Expand Up @@ -157,6 +157,19 @@ else if(key_value[0].equalsIgnoreCase("ServerAliveInterval")){
}
kv.addElement(key_value);
}
else if(key_value[0].equalsIgnoreCase("ConnectTimeout")){
int connectTimeout = -1;
try {
connectTimeout = Integer.parseInt(key_value[1]);
}
catch(NumberFormatException e){
// wrong format
}
if(connectTimeout>=0){
key_value[1]=Integer.toString(connectTimeout*1000);
}
kv.addElement(key_value);
}
else {
kv.addElement(key_value);
}
Expand Down

0 comments on commit 8b01463

Please sign in to comment.