Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException when using JSch library (version 0.2.22) for SSH connection #767

Open
huangzhCHN opened this issue Feb 22, 2025 · 2 comments

Comments

@huangzhCHN
Copy link

We are encountering an issue while attempting to establish an SSH connection using version 0.2.22 of the JSch library in our application. Below is the stack trace for the exception encountered:
java.lang.ArrayIndexOutOfBoundsException: null
at java.lang.System.arraycopy(Native Method)
at com.jcraft.jsch.Buffer.putByte(Buffer.java:60)
at com.jcraft.jsch.Buffer.putString(Buffer.java:70)
at com.jcraft.jsch.Buffer.putString(Buffer.java:65)
at com.jcraft.jsch.DHXEC.next(DHXEC.java:172)
at com.jcraft.jsch.Session.connect(Session.java:342)
at com.goldwind.pf.report.infrastructure.util.SFTPUtil.login(SFTPUtil.java:96)
at com.goldwind.pf.report.infrastructure.util.SFTPUtil.login(SFTPUtil.java:78)
at com.goldwind.pf.report.domain.reportupload.service.impl.SftpStrategy.upload(SftpStrategy.java:99)
at com.goldwind.pf.report.domain.process.impl.UploadFileProcess.uploadFile(UploadFileProcess.java:111)
at com.goldwind.pf.report.domain.process.impl.UploadFileProcess.lambda$upload$1(UploadFileProcess.java:99)
at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1640)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

This error appears to occur during the key exchange process (DHXEC.next) when invoking Session.connect. We have verified that all parameters passed to the JSch methods are valid and there are no apparent issues such as insufficient memory in our environment.

Could you please provide insights into what might be causing this ArrayIndexOutOfBoundsException specifically in version 0.2.22 of JSch? Are there any known bugs or recommended workarounds for this scenario?

Thank you for your assistance.

@huangzhCHN
Copy link
Author

Could it be caused by adding the following configurations?

JSch.setConfig("server_host_key", JSch.getConfig("server_host_key") + ",ssh-rsa");
JSch.setConfig("PubkeyAcceptedAlgorithms", JSch.getConfig("PubkeyAcceptedAlgorithms") + ",ssh-rsa");

Here are the SFTP connection details from the server:

OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to 192.168.99.100 [192.168.99.100] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH
debug1: match: OpenSSH pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.99.100:22 as 'jf'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: compression: none
debug1: kex: client->server cipher: [email protected] MAC: compression: none
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:QT6eDQbEutH774Jnrv2Xv5ko/7PsoKweQpLhbJB11zo
debug1: Host '192.168.99.100' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:5
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: password
[email protected]'s password:
debug1: Authentication succeeded (password).
Authenticated to 192.168.99.100 ([192.168.99.100]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = zh_CN.UTF-8
debug1: Sending subsystem: sftp
Connected to 192.168.99.100.

@huangzhCHN
Copy link
Author

The program initially had no issues connecting and uploading. However, after running for two days, it reported this error. Moreover, attempts to reconnect and upload again resulted in the same error. Restarting the service resolved the issue on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant