gpt4 book ai didi

Java8 + Jcraft = 该算法的 key 太长

转载 作者:行者123 更新时间:2023-11-30 09:03:59 30 4
gpt4 key购买 nike

我们正在使用 JCraft/Jsch 进行 sftp 文件传输。 http://www.jcraft.com/jsch

多年来,这在 Java6 和 Java 7 中运行良好。但后来我们升级到 Java 8,它在我们的测试环境中运行良好,但在我们的 QA 环境中却失败了。然后它对远程 SFTP 服务器失败。此 SFTP 服务器使用“SSH-2.0-4.2.0.21 SSH Secure Shell Windows NT Server”我们无法控制此服务器。

我在谷歌上搜索了一下,发现有人暗示问题的根源是我们没有安装“Java Cryptography Extension (JCE) Unlimited Strength”。我知道这是需要的,它安装在 Java6/7 上。在 Java 8 上安装它,结果是一样的。

我已经在 Windows 和 Linux 上使用 Java 8 更新 5 和更新 11 进行了测试。

我们使用Jcraft 0.1.51版本(最新)当我切换到 Java7 运行时时,一切正常。

我得到的错误是这个:

com.jcraft.jsch.JSchException: Session.connect: java.security.InvalidKeyException: Key is too long for this algorithm
at com.jcraft.jsch.Session.connect(Session.java:558)
at com.jcraft.jsch.Session.connect(Session.java:183)
at sb1.fip.backend.ssh2.sftp.SFTPClientImpl.connect(SFTPClientImpl.java:241)

我怀疑 JCraft 有问题。

我已经执行了这个程序: http://sourceforge.net/p/jsch/mailman/message/32660306/它确认我已经安装了 Java Cryptography Extension。

这是失败的代码:

private void connect() {
try {
JSch.setLogger(new JschLogger());
JSch jsch = new JSch();
session = jsch.getSession(sftpConfig.getUsername(), sftpConfig.getHost(), sftpConfig.getPort());
session.setUserInfo(new SFTPUserInfo(sftpConfig.getPassword()));
session.setTimeout(150000);
session.connect();
channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
} catch (Exception e) {
throw new SystemException(Ssh2ErrorCode.SFTP_CONNECT_ERROR, sftpConfig.getLoggableConfigInfo(), e);
}
}

多一点日志:

2014-08-20 14:01:52,801 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger     ]: Connecting to sftp.il.stralfors.com port 22
2014-08-20 14:01:52,824 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: Connection established
2014-08-20 14:01:53,181 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: Remote version string: SSH-2.0-4.2.0.21 SSH Secure Shell Windows NT Server
2014-08-20 14:01:53,181 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: Local version string: SSH-2.0-JSCH-0.1.51
2014-08-20 14:01:53,181 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
2014-08-20 14:01:53,313 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: CheckKexes: diffie-hellman-group14-sha1
2014-08-20 14:01:53,345 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: SSH_MSG_KEXINIT sent
2014-08-20 14:01:53,345 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: SSH_MSG_KEXINIT received
2014-08-20 14:01:53,345 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server: diffie-hellman-group1-sha1
2014-08-20 14:01:53,346 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server: ssh-dss
2014-08-20 14:01:53,346 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server: aes128-cbc,3des-cbc,twofish128-cbc,cast128-cbc,twofish-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,twofish192-cbc,twofish256-cbc,arcfour
2014-08-20 14:01:53,346 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server: aes128-cbc,3des-cbc,twofish128-cbc,cast128-cbc,twofish-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,twofish192-cbc,twofish256-cbc,arcfour
2014-08-20 14:01:53,346 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server: hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96
2014-08-20 14:01:53,347 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server: hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96
2014-08-20 14:01:53,347 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server: none,zlib
2014-08-20 14:01:53,347 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server: none,zlib
2014-08-20 14:01:53,347 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server:
2014-08-20 14:01:53,348 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server:
2014-08-20 14:01:53,348 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
2014-08-20 14:01:53,348 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client: ssh-rsa,ssh-dss
2014-08-20 14:01:53,348 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc
2014-08-20 14:01:53,348 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc
2014-08-20 14:01:53,349 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
2014-08-20 14:01:53,349 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
2014-08-20 14:01:53,349 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client: none
2014-08-20 14:01:53,349 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client: none
2014-08-20 14:01:53,349 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client:
2014-08-20 14:01:53,350 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client:
2014-08-20 14:01:53,353 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: server->client aes128-cbc hmac-md5 none
2014-08-20 14:01:53,354 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: kex: client->server aes128-cbc hmac-md5 none
2014-08-20 14:01:53,360 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: SSH_MSG_KEXDH_INIT sent
2014-08-20 14:01:53,360 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: expecting SSH_MSG_KEXDH_REPLY
2014-08-20 14:01:53,419 [INFO ] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [JschLogger ]: Disconnecting from sftp.il.stralfors.com port 22
2014-08-20 14:01:53,450 [ERROR] [HTY50006] [main ] [9.13.0] [666349519712388] [JUNIT-TEST] [] [StraalforsBackendNoStubTest]: SSH error!
sb1.fip.infra.core.error.SystemException: ErrorCode:FIP-3802 ErrorId:AHWK-9LKI ErrorMsg:Feil i ssh2-backend. Connect failed. SFTPConfig[STRAALFORS, Sb1Ltest@sftp.il.stralfors.com:22, remoteDownloadDir:/tmp, remoteUploadDir:/tmp, localDownloadDir:C:\Users\a11632u\AppData\Local\Temp\/, localUploadDir:C:\Users\a11632u\AppData\Local\Temp\/, uploadPattern:.*, downloadPattern:.*] RootCause:com.jcraft.jsch.JSchException:Session.connect: java.security.InvalidKeyException: Key is too long for this algorithm
at sb1.fip.backend.ssh2.sftp.SFTPClientImpl.connect(SFTPClientImpl.java:243) ~[classes/:na]
at sb1.fip.backend.ssh2.sftp.SFTPClientImpl.listDirs(SFTPClientImpl.java:100) ~[classes/:na]
at sb1.fip.backend.straalfors.StraalforsBackend.listDirs(StraalforsBackend.java:42) ~[classes/:na]
at sb1.fip.backend.straalfors.StraalforsBackendNoStubTest.testListDirs(StraalforsBackendNoStubTest.java:22) ~[test-classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11]
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) [junit-4.11.jar:na]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.11.jar:na]
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) [junit-4.11.jar:na]
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.11.jar:na]
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) [junit-4.11.jar:na]
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) [spring-test-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) [junit-4.11.jar:na]
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) [spring-test-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) [spring-test-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233) [spring-test-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87) [spring-test-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) [junit-4.11.jar:na]
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) [spring-test-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) [junit-4.11.jar:na]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176) [spring-test-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.junit.runner.JUnitCore.run(JUnitCore.java:160) [junit-4.11.jar:na]
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) [junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) [junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) [junit-rt.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11]
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) [idea_rt.jar:na]
Caused by: com.jcraft.jsch.JSchException: Session.connect: java.security.InvalidKeyException: Key is too long for this algorithm
at com.jcraft.jsch.Session.connect(Session.java:558) ~[jsch-0.1.51.jar:na]
at com.jcraft.jsch.Session.connect(Session.java:183) ~[jsch-0.1.51.jar:na]
at sb1.fip.backend.ssh2.sftp.SFTPClientImpl.connect(SFTPClientImpl.java:239) ~[classes/:na]
... 36 common frames omitted

最佳答案

遇到了类似的问题。一些带有 SSH 的遗留系统(开放式 VMS)实现了带有 2048 位 key 的 SHA-1。还不确定这是一个 jsch 错误,还是一个错误的 ssh 实现。我还必须使用 java 8,因为我使用 javafx 8 功能。无论如何,为了解决这个问题,我得到了 openjdk 代码并像这样滥用代码:

sun.security.provider.DSA.java ...
@Override
protected void checkKey(DSAParams params) throws InvalidKeyException {
int valueL = params.getP().bitLength();
// comment out this check since it only
// enforces the protocol and doesn't break the functionality
// if (valueL > 1024) {
// throw new InvalidKeyException("Key is too long for this algorithm");
// }
}

编译它并使用 -Xbootclasspath/p 选项激活它。我知道这是不好的做法,但修复服务器不是一种选择,修复 jsch 可能是一项艰巨的任务。欢迎你为此谴责我。

关于Java8 + Jcraft = 该算法的 key 太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25404371/

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