JSchException:算法协商失败diffie-hellman-group14-sha1

时间:2015-05-06 12:51:41

标签: java algorithm jsch

我知道这已被问过几次,但我已尝试过许多已经接受的解决方案。

我正在使用JSch创建一个简单的SSH隧道。并且我在日志中不断收到此错误:

INFO: diffie-hellman-group14-sha1 is not available.

我已经将Java无限制策略文件添加到正确的文件夹中,并且已将此算法添加到sshd_config文件中的KexAlgorithms部分。以下是完整的日志细分。

INFO: Connecting to xx.xx.xxx.xxx port 22
INFO: Connection established
INFO: Remote version string: SSH-2.0-OpenSSH_6.8
INFO: Local version string: SSH-2.0-JSCH-0.1.50
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-     cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: CheckKexes: diffie-hellman-group14-sha1
INFO: diffie-hellman-group14-sha1 is not available.
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
INFO: kex: server: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
INFO: kex: server: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
INFO: kex: server: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
INFO: kex: server: none,zlib@openssh.com
INFO: kex: server: none,zlib@openssh.com
INFO: kex: server: 
INFO: kex: server: 
INFO: kex: client: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
INFO: kex: client: ssh-rsa,ssh-dss
INFO: kex: client: aes256-cbc
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc
INFO: kex: client: hmac-sha2-256
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
INFO: kex: client: none
INFO: kex: client: none
INFO: kex: client: 
INFO: kex: client: 
INFO: Disconnecting from xx.xx.xxx.xxx port 22
com.jcraft.jsch.JSchException: Algorithm negotiation fail

3 个答案:

答案 0 :(得分:3)

您的客户端和服务器不共享通用的KEX算法:

  

INFO:kex:server:curve25519-sha256 @ libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14 -sha1

     

INFO:kex:client:diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1

正如您所看到的,两者都不支持任何算法都可以在其他列表中找到。您可以通过以下两种方式之一向客户端添加对其他KEX算法的支持:

  1. 将JSch升级到最新版本(0.1.52)以自动启用对sha256的支持。
  2. 如果您坚持使用0.1.51,则可以以编程方式启用sha256:

    JSch shell = new JSch();
    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");
    

    然后创建会话并使用以下命令设置配置:

    Session session = ...
    session.setConfig(config);
    

答案 1 :(得分:1)

要使此密钥交换算法可用,您必须添加支持它的安全提供程序。您提到的不受限制的政策文件也是必需的。

Bouncycastle的供应商安装:

boolean succeeded = false;
do {
  int old = value;
  if ( compareAndSet(old, old+1) ) {
    // It worked!
    succeeded = true;
  } else {
    // Some other thread incremented it before I got there. Just try again.
  }
} while (!succeeded);

确保Java import org.bouncycastle.jce.provider.BouncyCastleProvider; ... Security.addProvider(new BouncyCastleProvider()); 中包含必要的jar文件。

答案 2 :(得分:0)

我们也面临同样的问题,但是我找到了此问题的根本原因。

当我从普通的Java程序执行时,它工作正常

当我从应用程序(在weblogic中部署)执行时,它失败了。

原因:Weblogic应用程序使用JDK 1.6.0.41之外的默认Jrockit API 1.6.0.29。

更改了Weblogic JAVA版本,然后可以正常工作。