我正在使用 sshj (0.19.1) 使用带有 SSH2 连接的 scala 应用程序。我可以从 Eclipse 中正常连接,但是从一个胖 jar 运行应用程序,我遇到了一些错误。我最初的错误是:
Line 3: TransportException: null
at net.schmizz.sshj.transport.TransportException$1.chain(33)
at net.schmizz.sshj.transport.TransportException$1.chain(27)
at net.schmizz.concurrent.Promise.deliverError(96)
at net.schmizz.concurrent.Event.deliverError(74)
at net.schmizz.concurrent.ErrorDeliveryUtil.alertEvents(34)
at net.schmizz.sshj.transport.KeyExchanger.notifyError(386)
at net.schmizz.sshj.transport.TransportImpl.die(596)
at net.schmizz.sshj.transport.Reader.run(68)
我已将 US_export_policy.jar 和 local_policy.jar 添加到 $JAVA_HOME/lib/security。我添加了以下内容以尝试将 bouncycastle 注册为提供者,
import org.bouncycastle.jce.provider.BouncyCastleProvider
val bouncyCastle = new BouncyCastleProvider()
java.security.Security.addProvider(bouncyCastle)
net.schmizz.sshj.common.SecurityUtils.registerSecurityProvider("org.bouncycastle.jce.provider.BouncyCastleProvider")
但我仍然收到以下错误:
INFO n.schmizz.sshj.common.SecurityUtils - Registration of Security Provider 'org.bouncycastle.jce.provider.BouncyCastleProvider' unexpectedly failed
INFO n.schmizz.sshj.common.SecurityUtils - BouncyCastle not registered, using the default JCE provider
INFO n.s.sshj.transport.random.JCERandom - Creating new SecureRandom.
WARN net.schmizz.sshj.DefaultConfig - Illegal key size
WARN net.schmizz.sshj.DefaultConfig - Cannot find any provider supporting Twofish/CBC/NoPadding
...
WARN net.schmizz.sshj.DefaultConfig - Illegal key size or default parameters
WARN net.schmizz.sshj.DefaultConfig - Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
INFO n.s.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0.19.1
INFO n.s.sshj.transport.TransportImpl - Server identity string: SSH-2.0-OpenSSH_6.6.1
ERROR n.s.sshj.transport.TransportImpl - Dying because - {}
net.schmizz.sshj.common.SSHRuntimeException: BouncyCastle is required to read a key of type ecdsa-sha2-nistp256
at net.schmizz.sshj.common.Buffer.readPublicKey(Buffer.java:431)
at net.schmizz.sshj.transport.kex.AbstractDHG.next(AbstractDHG.java:66)
at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:358)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:493)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:104)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:172)
at net.schmizz.sshj.transport.Reader.run(Reader.java:60)
Caused by: java.security.GeneralSecurityException: BouncyCastle is required to read a key of type ecdsa-sha2-nistp256
at net.schmizz.sshj.common.KeyType$3.readPubKeyFromBuffer(KeyType.java:120)
at net.schmizz.sshj.common.Buffer.readPublicKey(Buffer.java:429)
... 6 common frames omitted
INFO n.s.sshj.transport.TransportImpl - Disconnected - UNKNOWN
ERROR net.schmizz.concurrent.Promise - <<kex done>> woke to: net.schmizz.sshj.transport.TransportException: BouncyCastle is required to read a key of type ecdsa-sha2-nistp256
我将 jar 运行为java -cp ../lib/bcprov-jdk15on-1.51.jar -jar <my jar>
,因为据我了解,您不能将 bouncycastle 作为提供程序的 fat jar 的一部分包含在内。但我不确定我错过了什么,我无法将其注册为提供者。任何帮助,将不胜感激。