Hi All,
I am developing a multi-threaded SSH protocol that will send multiple commands that are in a table to the server. I am using an RSA key to authenticate with the server. The key was tested with a normal SSH driver that communicates with the same server.
I am following the instructions stated on this page: Multi-Threaded SSH
I am providing the file name in the SSH settings array while preparing the request and I leave the password variable empty.
string[] sshSettings = new string[6];
sshSettings[0] = userName;
sshSettings[1] = ""; //Password is empty
sshSettings[2] = @"key=C:\SSH_Keys\vitcmon-id_rsa";
sshSettings[3] = Convert.ToString(timeout);
sshSettings[4] = responseTrailer;
sshSettings[5] = Convert.ToString(trailerResponseOccurrenceCount);
In addition, I provide the key algorithm in the requestInfo[2] as follow:
object[] requestInfo = new object[3];
requestInfo[0] = sshSettings;
requestInfo[1] = sshCommands;
requestInfo[2] = new string[1] { "ssha-rsa"};
The SLSSH logs file shows the following error:
2021-03-03 08:40:36 - 5727 - Open 1
2021-03-03 08:40:36 - 5727 - 'Open' completed
2021-03-03 08:40:36 - 5727 - Notify (SetOptions) exception: Tamir.SharpSsh.jsch.JSchException: System.IO.FileNotFoundException: Could not find file 'C:\SSH_Keys\vitcmon-id_rsakexAlgorithms=ssha-rsa'.
File name: 'C:\SSH_Keys\vitcmon-id_rsakexAlgorithms=ssha-rsa'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Tamir.SharpSsh.jsch.IdentityFile..ctor(String identity, JSch jsch)
at Tamir.SharpSsh.jsch.IdentityFile..ctor(String identity, JSch jsch)
at Tamir.SharpSsh.jsch.JSch.addIdentity(String privateKeyFile, String passPhrase)
at Tamir.SharpSsh.SshBase.AddIdentityFile(String privateKeyFile, String passphrase)
at Skyline.SSH.SshConnection.ParseOptions(String optionsString)
at Skyline.SSH.SshConnection.Notify(Int32 type, Object val1, Object val2, Object& outval)
2021-03-03 08:40:36 - 5727 - Close
2021-03-03 08:40:36 - 5727 - Close Shell
2021-03-03 08:40:36 - 5727 - Close complete
The file name is concatenated with the kexAlgorithms which makes the file name invalid!
Did anyone notice this happening before? Could this be a software bug?
Hi Saddam,
This appears to be an issue which existed in versions prior to 10.0.3 / 10.1.0 and was fixed as part of the changes to support SSL/TLS for serial connections (RN)
A possible workaround might be to add a semicolon when specifying the key=xxxx option:
sshSettings[2] = @"key=C:\SSH_Keys\vitcmon-id_rsa;";
The extra semicolon should make it so the options get properly separated when parsing.
The fix for this second issue was to add an IP:Port column in the table of commands and fill it with the IP:Port of the host I am communicating with. In addition, I updated the Multithreaded Timer “ip” value to use the IP:Port Column instead of the keys column
Thanks, Wouter.
That exception disappeared from the logs. However, I started to see this new exception.
2021-03-04 06:35:55 – 5895 – Create Object
2021-03-04 06:35:55 – 5895 – Open 1
2021-03-04 06:35:55 – 5895 – ‘Open’ completed
2021-03-04 06:35:55 – 5895 – Set Timeout 5000
2021-03-04 06:35:55 – 5895 – Set RetryTime 5000
2021-03-04 06:35:55 – 5895 – Connect -1
2021-03-04 06:35:58 – 5895 – Connect exception: Tamir.SharpSsh.jsch.JSchException: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: port
at System.Net.IPEndPoint..ctor(IPAddress address, Int32 port)
at Tamir.SharpSsh.java.net.Socket..ctor(String host, Int32 port)
at Tamir.SharpSsh.jsch.Util.CreateSocketRun.run()
at Tamir.SharpSsh.jsch.Util.CreateSocket(String host, Int32 port, Int32 timeout)
at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)
at Tamir.SharpSsh.jsch.Session.connect()
at Tamir.SharpSsh.SshBase.ConnectSession(Int32 tcpPort)
at Tamir.SharpSsh.SshBase.Connect(Int32 tcpPort)
at Skyline.SSH.SshConnection.Connect()
2021-03-04 06:35:58 – 5895 – Connect complete (2281.2668ms)
2021-03-04 06:35:58 – 5895 – Close
2021-03-04 06:35:58 – 5895 – Close Shell
2021-03-04 06:35:58 – 5895 – Close complete