在创建与sftp服务器的jsch连接时,算法协商失败

时间:2016-09-12 10:21:58

标签: java encryption ssh jsch diffie-hellman

我正在尝试使用Jsch连接到sftp服务器。出于某种原因,我收到以下错误。

com.jcraft.jsch.JSchException: Algorithm negotiation fail
at com.jcraft.jsch.Session.receive_kexinit(Session.java:590)
at com.jcraft.jsch.Session.connect(Session.java:320)
at com.jcraft.jsch.Session.connect(Session.java:183)
at Test.main(test.java:65)

会话连接日志的详细输出如下所示:

Connecting to xx.xx.xx.xx port 22
Connection established
Remote version string: SSH-2.0-6.4.5.90 SSH Tectia Server
Local version string: SSH-2.0-JSCH-0.1.54
CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
diffie-hellman-group14-sha1 is not available.
CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
SSH_MSG_KEXINIT sent
SSH_MSG_KEXINIT received
kex: server: diffie-hellman-group14-sha1,diffie-hellman-group14-sha256@ssh.com,diffie-hellman-group15-sha256@ssh.com,diffie-hellman-group15-sha384@ssh.com,diffie-hellman=group16-sha384@ssh.com,diffie-hellman-group16-sha512@ssh.com,diffie-hellman-group18-sha512@ssh.com
kex: server: ssh-rsa,ssh-rsa-sha256@ssh.com
kex: server: crypticore128@ssh.com,aes128-cbc,aes128-ctr,aes192-cbc,aes192-ctr,aes256-cbc,aes256-ctr,3des-cbc
kex: server: crypticore128@ssh.com,aes128-cbc,aes128-ctr,aes192-cbc,aes192-ctr,aes256-cbc,aes256-ctr,3des-cbc
kex: server: hmac-sha1,hmac-sha256-2@ssh.com,hmac-sha224@ssh.com,hmac-sha256@ssh.com,hmac-sha384@ssh.com
kex: server: hmac-sha1,hmac-sha256-2@ssh.com,hmac-sha224@ssh.com,hmac-sha256@ssh.com,hmac-sha384@ssh.com
kex: server: none,zlib
kex: server: none,zlib
kex: server: 
kex: server: 
kex: client: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256
kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc
kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc
kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
kex: client: none
kex: client: none
kex: client: 
kex: client: 
Disconnecting from xx.xx.xx.xx port 22

从这个论坛的其他答案来看,似乎通常的原因是以下之一:

  • 未安装Java加密扩展(JCE)
  • 旧版Jsch

以下是我用于生成此错误的测试代码,并且我已启用加密扩展。

import javax.crypto.Cipher;
import java.security.*;
import java.security.Provider.Service;
import com.jcraft.jsch.*;
import java.util.Properties;


class Test {
  public static void main(String[] args) {

    Logger jschLogger = new Logger() {

            @Override
            public boolean isEnabled(int arg0) {
                return true;
             }

            @Override
            public void log(int arg0, String arg1) {
                   System.out.println(Integer.toString(arg0)+" - "+arg1);
            }
        };


  JSch jsch = new JSch();
  Session session = null;

    try {
    Properties config = new Properties();
    config.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");
    config.put("StrictHostKeyChecking", "no");

        jsch.setLogger(jschLogger);
    session = jsch.getSession("*****", "******", 22);
    session.setConfig("StrictHostKeyChecking", "no");
    session.setPassword("******");
        session.setConfig(config);
        System.out.println(session.getConfig("kex"));
    session.connect();

    Channel channel = session.openChannel("sftp");
    channel.connect();
    ChannelSftp sftpChannel = (ChannelSftp) channel;
    sftpChannel.get("remotefile.txt", "localfile.txt");
    sftpChannel.exit();
    session.disconnect();
        } catch (JSchException e) {
            e.printStackTrace();
                System.out.println(e.getMessage());
                System.out.println(e.getCause().toString());
        } catch (Exception  e) {
                e.printStackTrace();
                System.out.println(e.getMessage());
                System.out.println(e.getCause().toString());
        }
 }

}

有人能指出我正确的方向吗?我无法控制服务器。

0 个答案:

没有答案