SSHJ和Maven shade插件

时间:2013-11-06 15:14:24

标签: java maven bouncycastle maven-shade-plugin sshj

在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有一个包含所有依赖项的二进制文件。

3 个答案:

答案 0 :(得分:1)

我遇到了这个问题。我终于放弃了试图把所有东西放在一个大的" uberjar"。

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

答案 1 :(得分:1)

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

e.g put' bcprov-jdk15on-1.49.jar'在文件夹' $ JAVA_HOME / jre / lib / ext /'在主持人身上。

答案 2 :(得分: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)