1

在 Eclipse 中测试 SSHJ,一切看起来都不错。但是当我使用 Maven shade 插件打包 SSHJ 时,我得到以下错误:

Exception in thread "main" net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods
at net.schmizz.sshj.SSHClient.auth(SSHClient.java:217)
at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:316)
at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:365)
at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:295)
at no.f12.SshRepository.executeTaskOnHost(SshRepository.java:23)
at no.f12.SshService.serviceCommand(SshService.java:22)
at no.f12.App.main(App.java:29)

添加

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

将错误消息更改为:

Exception in thread "main" net.schmizz.sshj.transport.TransportException: Unable to reach a settlement: [] and [aes128-ctr, aes192-ctr, aes256-ctr, arcfour256, arcfour128, aes128-gcm@openssh.com, aes256-gcm@openssh.com, aes128-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, aes192-cbc, aes256-cbc, arcfour, rijndael-cbc@lysator.liu.se]
at net.schmizz.sshj.transport.Proposal.firstMatch(Proposal.java:165)
at net.schmizz.sshj.transport.Proposal.negotiate(Proposal.java:147)
at net.schmizz.sshj.transport.KeyExchanger.gotKexInit(KeyExchanger.java:239)
at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:364)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:478)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)

知道如何解决这个问题吗?

关于我为什么要使用阴影的一些背景知识......我试图达到一个点,即 Java 的使用和小型实用程序的分发非常简单。所以我使用这个创建了一个真正可执行的 jar:https ://github.com/brianm/really-executable-jars-maven-plugin 。这使我能够创建一个可执行文件来分发并添加到用户的路径中。有点像 Go 有一个包含所有依赖项的二进制文件。

4

3 回答 3

1

另一种可行的方法是将 bouncycastle 添加到 JRE 扩展库中。

例如,将 'bcprov-jdk15on-1.49.jar' 放在主机上的文件夹 '$JAVA_HOME/jre/lib/ext/' 中。

于 2014-08-14T14:43:46.953 回答
1

我有这个确切的问题。我终于放弃了尝试把所有东西都放在一个大的“uberjar”中。

相反,我使用 maven-assembly-plugin 组装了所有 jar,然后将它们提取并添加到类路径中以便执行,例如 'java -cp all-needed-libs/* com.company.MainClass'。

于 2014-04-16T06:36:24.843 回答
0

您必须签署 jar,它是 Javax.security 所要求的。我遇到了类似的问题,并且我的测试中有堆栈跟踪:

Cannot init Cipher factory: blowfish-cbc
java.lang.SecurityException: JCE cannot authenticate the provider BC
    at javax.crypto.Cipher.getInstance(Cipher.java:642)
    at javax.crypto.Cipher.getInstance(Cipher.java:580)
    at net.schmizz.sshj.common.SecurityUtils.getCipher(SecurityUtils.java:96)
    at net.schmizz.sshj.transport.cipher.BaseCipher.init(BaseCipher.java:88)
    ....
Caused by: java.util.jar.JarException: file:/test-jar-with-dependencies.jar has unsigned entries - library.properties
    at javax.crypto.JarVerifier.verifySingleJar(JarVerifier.java:462)
    at javax.crypto.JarVerifier.verifyJars(JarVerifier.java:322)
    at javax.crypto.JarVerifier.verify(JarVerifier.java:250)
    at javax.crypto.JceSecurity.verifyProviderJar(JceSecurity.java:161)
    at javax.crypto.JceSecurity.getVerificationResult(JceSecurity.java:187)
    at javax.crypto.Cipher.getInstance(Cipher.java:638)
    at javax.crypto.Cipher.getInstance(Cipher.java:580)
    at net.schmizz.sshj.common.SecurityUtils.getCipher(SecurityUtils.java:96)
    at net.schmizz.sshj.transport.cipher.BaseCipher.init(BaseCipher.java:88)
    at net.schmizz.sshj.DefaultConfig.initCipherFactories(DefaultConfig.java:152)
    at net.schmizz.sshj.DefaultConfig.<init>(DefaultConfig.java:107)
于 2014-01-03T22:26:41.523 回答