【问题标题】:SFTP using JSch and GlobalScape使用 JSch 和 GlobalScape 的 SFTP
【发布时间】:2011-07-30 16:32:06
【问题描述】:

我正在尝试使用 Java 安全通道 (JSCh) 建立 SFTP 连接。 我的软件堆栈是 Red Hat Enterprise Server 5.0、JRE 6.0 和 JSch v0.1.44。 主要的服务器软件堆栈(我正在尝试连接)是 Windows Server 2008 和最新版本的 GlobalScape。 尝试连接时,我得到一个

com.jcraft.jsch.JSchException: Algorithm negotiation fail 
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:529) 
    at com.jcraft.jsch.Session.connect(Session.java:291) 

启用 JSch 日志记录我得到以下相同的连接:

0000001d SystemErr     R INFO: Connecting to xxx.xxx.xxx.157 port 22
0000001d SystemErr     R INFO: Connection established
0000001d SystemErr     R INFO: Remote version string: SSH-2.0-1.36_sshlib GlobalSCAPE
0000001d SystemErr     R INFO: Local version string: SSH-2.0-JSCH-0.1.44
0000001d SystemErr     R INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-    cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
0000001d SystemErr     R INFO: aes256-ctr is not available.
0000001d SystemErr     R INFO: aes192-ctr is not available.
0000001d SystemErr     R INFO: aes256-cbc is not available.
0000001d SystemErr     R INFO: aes192-cbc is not available.
0000001d SystemErr     R INFO: arcfour256 is not available.
0000001d SystemErr     R INFO: SSH_MSG_KEXINIT sent
0000001d SystemErr     R INFO: SSH_MSG_KEXINIT received
0000001d SystemErr     R INFO: Disconnecting from xxx.xxx.xxx.157 port 22

所以从外观上看,我正在连接到服务器,实际上我可以发送和接收一条 msg,但是当客户端尝试匹配服务器 msg 提议和客户端 msg 提议时,它会引发异常。

现在将其与使用以前的 GlobalScape 软件和 Windows Server 2003 成功连接到服务器的 JSch 日志进行比较:

0000001e SystemErr     R INFO: Connecting to xxx.xxx.xxx.156 port 22
0000001e SystemErr     R INFO: Connection established
0000001e SystemErr     R INFO: Remote version string: SSH-2.0-1.36 sshlib: GlobalScape
0000001e SystemErr     R INFO: Local version string: SSH-2.0-JSCH-0.1.44
0000001e SystemErr     R INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
0000001e SystemErr     R INFO: aes256-ctr is not available.
0000001e SystemErr     R INFO: aes192-ctr is not available.
0000001e SystemErr     R INFO: aes256-cbc is not available.
0000001e SystemErr     R INFO: aes192-cbc is not available.
0000001e SystemErr     R INFO: arcfour256 is not available.
0000001e SystemErr     R INFO: SSH_MSG_KEXINIT sent
0000001e SystemErr     R INFO: SSH_MSG_KEXINIT received
0000001e SystemErr     R INFO: kex: server->client aes128-cbc hmac-md5 none
0000001e SystemErr     R INFO: kex: client->server aes128-cbc hmac-md5 none
0000001e SystemErr     R INFO: SSH_MSG_KEXDH_INIT sent
0000001e SystemErr     R INFO: expecting SSH_MSG_KEXDH_REPLY
0000001e SystemErr     R INFO: ssh_dss_verify: signature true
0000001e SystemErr     R WARN: Permanently added 'xxx.xxx.xxx.156' (DSA) to the list of known hosts.
0000001e SystemErr     R INFO: SSH_MSG_NEWKEYS sent
0000001e SystemErr     R INFO: SSH_MSG_NEWKEYS received
0000001e SystemErr     R INFO: SSH_MSG_SERVICE_REQUEST sent
0000001e SystemErr     R INFO: SSH_MSG_SERVICE_ACCEPT received
0000001e SystemErr     R INFO: Authentications that can continue: publickey,keyboard-inteactive,password
0000001e SystemErr     R INFO: Next authentication method: publickey
0000001e SystemErr     R INFO: Authentications that can continue: password
0000001e SystemErr     R INFO: Next authentication method: password
0000001e SystemErr     R INFO: Authentication succeeded (password).

所以它再次能够连接并能够交换 SSH_MSG_KEXINIT,但是这里客户端和服务器建议匹配并且没有抛出异常

sftp 安全性使用公钥/私钥和用户名/密码。

我可以使用 WinSCP、Filezilla 和 linux 命令行(从运行 java 应用程序的同一台服务器)连接到它。

我与 SFTP 服务器的一位系统管理员交谈,我们尝试使用用户名/密码,但我得到了相同的异常和日志。

系统管理员告诉我,两台服务器的区别在于 GlobalScape 版本,现在是 Microsoft 2008 Server。

那么有人对如何解决这个问题有任何想法吗?

提前非常感谢!

【问题讨论】:

  • 我认为设置的主要区别在于您的 GlobalScape 版本是否正确?看看配置,最新版本是否允许 aes128-cbc 和 hmac-md5 ?
  • 如果你可以在调试器中运行你的程序,你可以尝试在Session.send_keyinit()中间放置一个断点来查看ciphersc2scipherss2c的值。或在此处添加.log(...)
  • 是的,到目前为止,JSch 日志的主要区别在于 GlobalScape 版本。我已经与该服务器的系统管理员进行了交谈,他正在检查它。感谢您的帖子。

标签: java encryption ssh sftp jsch


【解决方案1】:

您遇到的问题与 globalscape 无关,它与所有启用的密码算法 SFTP 服务器有关。 每个 sftp 服务器都有一些他们同意的密码算法,所以如果你没有这些编码和密码算法,它就不起作用 密码算法 所有其他 SFTP 软件都有内置的密码算法,它们根据 sftp 服务器配置使用最新的 256 位密码算法,你都设置好了

https://enterprisedt.com/products/edtftpjssl/doc/manual/html/howtousesftpchoosingalgorithms.html

公钥算法

可以为服务器身份验证的首选公钥算法设置 DSA 或 RSA 或两者。例如,如果设置了 RSA,服务器将向客户端提供一个 RSA 公钥(如果服务器当然支持 RSA 密钥 - 有些服务器不支持)。下面的代码说明了如何仅设置 RSA。它首先禁用所有密钥对算法,然后启用 RSA:

ftp.disableAllAlgorithms(SSHFTPAlgorithm.KEY_PAIR); ftp.setAlgorithmEnabled(SSHFTPAlgorithm.KEY_RSA, true);

默认启用 DSA 和 RSA。

密码算法

密码算法是用于对 SFTP 数据和命令进行加密的对称算法。下面的代码说明了如何将三重 DES 设置为密码算法(禁用所有其他算法):

ftp.disableAllAlgorithms(SSHFTPAlgorithm.CIPHER); ftp.setAlgorithmEnabled(SSHFTPAlgorithm.CIPHER_3DES_CBC, true);

默认启用所有密码算法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多