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 1073d1a commit 13b65a6
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 @@ -74,6 +74,11 @@ a 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.

15. Fixed an issue in the Java 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.


2.2.9 ESR
=========
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-2016 ymnk, JCraft,Inc. All rights reserved.
Copyright (c) 2019 D. R. Commander. All rights reserved.
Copyright (c) 2019, 2025 D. R. Commander. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -148,6 +148,19 @@ else if(key_value[0].equals("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 13b65a6

Please sign in to comment.