Search code examples
javasshjschapache-commons-vfs

How to set KEX on JSch Session when using Apache VFS


I am using Apache VFS 2.1 with JSch 0.1.54 (latest versions today) to upload files using SFTP.

The system throws "End of IO Stream Read" when connecting, the complete stack is:

Caused by: com.jcraft.jsch.JSchException: Session.connect: java.io.IOException: End of IO Stream Read
    at com.jcraft.jsch.Session.connect(Session.java:565)
    at com.jcraft.jsch.Session.connect(Session.java:183)
    at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:166)

I've found a possible solution to my problem in this thread but it operates directly with the JSch. Since I am using Apache VFS I can't access the Session directly (at least I think I can't).

But if I could, it would look like this:

session.setConfig("kex", "diffie-hellman-group1-sha1");

Looking into the Apache VFS implementation org.apache.commons.vfs2.provider.sftp.SftpClientFactory it didn't find a way to set this property.

How can I set this configuration using Apache VFS API?

Log data:

22/05/2017 09:27:20 org.apache.commons.vfs2.impl.StandardFileSystemManager info
INFO: Using "D:\Users\TECBMEPI\AppData\Local\Temp\vfs_cache" as temporary files store.
22/05/2017 09:27:20 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Connecting to z1t1brmxpta022 port 22
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Connection established
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Remote version string: SSH-2.0-OpenSSH_6.6.1
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Local version string: SSH-2.0-JSCH-0.1.54
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: aes256-ctr is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: aes192-ctr is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: aes256-cbc is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: aes192-cbc is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: diffie-hellman-group14-sha1 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdh-sha2-nistp256 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdh-sha2-nistp384 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdh-sha2-nistp521 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdsa-sha2-nistp256 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdsa-sha2-nistp384 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: ecdsa-sha2-nistp521 is not available.
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: SSH_MSG_KEXINIT sent
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: SSH_MSG_KEXINIT received
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: none,[email protected]
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: none,[email protected]
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: 
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server: 
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: ssh-rsa,ssh-dss
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: none
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: none
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: 
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client: 
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: server->client aes128-ctr hmac-md5 none
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: kex: client->server aes128-ctr hmac-md5 none
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: SSH_MSG_KEX_DH_GEX_REQUEST(1024<1024<1024) sent
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: expecting SSH_MSG_KEX_DH_GEX_GROUP
22/05/2017 09:27:21 org.apache.commons.vfs2.provider.sftp.SftpClientFactory log
INFO: Disconnecting from z1t1brmxpta022 port 22

Solution

  • The JSch Session inherits settings from its JSch instance. And all JSch instances actually share the same global/static hashtable with settings.

    So just call static JSch.setConfig before SftpClientFactory.createConnection:

    JSch.setConfig("kex", "diffie-hellman-group1-sha1");