gpt4 book ai didi

java - 使用 JSch 和 GlobalScape 的 SFTP

转载 作者:行者123 更新时间:2023-12-01 05:47:29 25 4
gpt4 key购买 nike

我正在尝试使用 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

因此,从外观上看,我正在连接到服务器,并且实际上可以发送和接收消息,但是当客户端尝试匹配服务器消息提案和客户端消息提案时,它会引发异常。

现在将其与使用以前的 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。

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

非常感谢!

最佳答案

您遇到的问题与全局无关,它与所有启用的密码算法 SFTP 服务器有关。每个 sftp 服务器都有一些他们同意的密码算法,因此如果您没有这些密码编码和算法,它就无法工作密码算法所有其他 SFTP 软件都有内置的密码算法,它们根据 sftp 服务器配置更改为最新的 256 位密码算法使用,您已全部设置完毕

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

公钥算法

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

默认启用所有密码算法。

关于java - 使用 JSch 和 GlobalScape 的 SFTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5564533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com