无法使用Mule中的SSH连接器进行连接

时间:2014-05-06 20:19:46

标签: java ssh mule


我在Mule Studio(3.5)中安装了SSH连接器。
这是我的配置:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
      xmlns:ssh="http://www.mulesoft.org/schema/mule/ssh" xmlns:http="http://www.mulesoft.org/schema/mule/http"
      xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/current/mule-stdio.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ssh http://www.mulesoft.org/schema/mule/ssh/1.2.1/mule-ssh.xsd">
      <ssh:config name="SSH" host="${servername}"
            port="22" timeout="6000" callbackFlowName="callbackFlow" doc:name="SSH"
            shellMode="false" receiverBufferSize="1000" password="${password}"
            username="${user}">
            <ssh:connection-pooling-profile
                  initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW" />
      </ssh:config>
      <flow name="sshbiginsights-demoFlow1" doc:name="sshbiginsights-demoFlow1">
            <http:inbound-endpoint exchange-pattern="one-way"
                  host="localhost" port="8081" doc:name="HTTP" />
            <ssh:send config-ref="SSH" content="pwd" doc:name="SSH"
                  breakLine="true" />
      </flow>
      <flow name="callbackFlow" doc:name="callbackFlow">
            <logger message="#[payload]" />
      </flow>
</mule>

当我尝试运行流时,我在日志中得到以下异常:

INFO  2014-05-05 11:57:50,410 [[sshbiginsights-demo].sshbiginsights-demoFlow1.stage1.02] net.schmizz.sshj.common.SecurityUtils: BouncyCastle registration succeeded
WARN  2014-05-05 11:57:50,489 [[sshbiginsights-demo].sshbiginsights-demoFlow1.stage1.02] net.schmizz.sshj.DefaultConfig: Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
INFO  2014-05-05 11:57:50,662 [[sshbiginsights-demo].sshbiginsights-demoFlow1.stage1.02] net.schmizz.sshj.transport.TransportImpl: Client identity string: SSH-2.0-SSHJ_0_8_1_SNAPSHOT
INFO  2014-05-05 11:57:50,775 [[sshbiginsights-demo].sshbiginsights-demoFlow1.stage1.02] net.schmizz.sshj.transport.TransportImpl: Server identity string: SSH-2.0-OpenSSH_5.3
ERROR 2014-05-05 11:57:51,260 [reader] net.schmizz.sshj.transport.TransportImpl: Dying because - {}
net.schmizz.sshj.transport.TransportException: [HOST_KEY_NOT_VERIFIABLE] Could not verify `ssh-rsa` host key with fingerprint `38:a3:94:7c:a9:78:19:2a:39:b2:89:f2:d1:86:2e:6a` for `server_name` on port 22
      at net.schmizz.sshj.transport.KeyExchanger.verifyHost(KeyExchanger.java:195)
      at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:346)
      at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:450)
      at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:100)
      at net.schmizz.sshj.transport.Decoder.received(Decoder.java:168)
      at net.schmizz.sshj.transport.Reader.run(Reader.java:44)
INFO  2014-05-05 11:57:51,262 [reader] net.schmizz.sshj.transport.TransportImpl: Disconnected - HOST_KEY_NOT_VERIFIABLE
ERROR 2014-05-05 11:57:51,264 [[sshbiginsights-demo].sshbiginsights-demoFlow1.stage1.02] net.schmizz.concurrent.Promise: <<kex done>> woke to: net.schmizz.sshj.transport.TransportException: [HOST_KEY_NOT_VERIFIABLE] Could not verify `ssh-rsa` host key with fingerprint `38:a3:94:7c:a9:78:19:2a:39:b2:89:f2:d1:86:2e:6a` for `server_name` on port 22
ERROR 2014-05-05 11:57:51,267 [[sshbiginsights-demo].sshbiginsights-demoFlow1.stage1.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: Could not reach ssh server at server_name:22. Type: class org.mule.api.ConnectionException
ERROR 2014-05-05 11:57:51,271 [[sshbiginsights-demo].sshbiginsights-demoFlow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Failed to invoke send. Message payload is of type: String
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Could not reach ssh server at server_name:22 (org.mule.api.ConnectionException)
  org.mule.modules.ssh.multiplexer.SshConnector:172 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/ConnectionException.html)
2. Failed to invoke send. Message payload is of type: String (org.mule.api.MessagingException)
  org.mule.modules.ssh.multiplexer.processors.SendMessageProcessor:139 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.ConnectionException: Could not reach ssh server at server_name:22
      at org.mule.modules.ssh.multiplexer.SshConnector.connect(SshConnector.java:172)
      at org.mule.modules.ssh.multiplexer.connectivity.SshConnectorConnectionFactory.makeObject(SshConnectorConnectionFactory.java:52)
      at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:1179)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

我看到了连接器的代码,它正在使用net.schmizz.sshj库。我在java main中写了以下内容 -

SSHClient client = new SSHClient();
// client.addHostKeyVerifier("38:a3:94:7c:a9:78:19:2a:39:b2:89:f2:d1:86:2e:6a");
client.connect("server", 22);
client.authPassword("user", "password");
Session session = client.startSession();
Command cmd = null;
cmd = session.exec("pwd");
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
cmd.close();
client.disconnect();
client.close();

当注释掉addHostKeyVerifier时,我得到相同的异常。当我取消注释它时,它可以工作。
但是,我没有在SSH连接器中看到我可以添加此主机密钥验证程序。
为什么我得到这个例外?这与我正在尝试连接的服务器有关吗?
谢谢,
阿迪

1 个答案:

答案 0 :(得分:0)

当前版本的SSH连接器不允许添加单个主机密钥验证程序,但它会加载已知主机列表:

https://github.com/mulesoft/sshmultiplexed-connector/blob/mule-module-SshMultiplexer-1.2.1/src/main/java/org/mule/modules/ssh/multiplexer/SshConnector.java#L158

来自默认位置:

  • ~/.ssh/known_hosts
  • ~/.ssh/known_hosts2

您是否尝试在~/.ssh/known_hosts

中添加此主机签名?