How to Solve Mule SFTP Connector Algorithm Negotiation Fail Exception
This quick tutorial will show you how to resolve issues with the Mule SFTP connector connecting to remote file locations.
Join the DZone community and get the full member experience.
Join For FreeThis article is the resolution of the Mule SFTP connector when connecting to remote file locations.
The configurations details are below:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp" 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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd">
<sftp:connector name="SFTP" validateConnections="true" doc:name="SFTP" />
<flow name="sftpflow">
<sftp:inbound-endpoint connector-ref="SFTP" host="host_ip" port="22" path="File Loactions " user="USERNAME" password="PASSWORD"
responseTimeout="10000" doc:name="SFTP" >
<reconnect count="3"/>
</sftp:inbound-endpoint>
<logger message="Able to read file :- #[payload]" level="INFO" doc:name="Logger" />
</flow>
</mule>
The exception will be:
com.jcraft.jsch.JSchException: Algorithm negotiation fail
at com.jcraft.jsch.Session.receive_kexinit(Session.java:583) ~[jsch-0.1.51.jar:?]
The SFTP connector for Mule has the in-built support jsch-0.1.51.jar
. So, while connecting to secure file locations through the SFTP connector, the com.jcraft.jsch.JSchException: Algorithm negotiation fail
exception is thrown.
In the JSch.class for jsch-0.1.51.jar
, for the KEY -->"kex
," it does not have the value "diffie-hellman-group-exchange-sha256" for connecting to the remote location securely. The sha256
exchange pattern is required, which is there in the jsch-0.1.54.jar
file. But for 3.6.2/3.7.1 and 3.8.1 runtime versions, the in-built third party jsch-0.1.51.jar
has been used.
The Workaround
Override the KEY "kex
" and add the value diffie-hellman-group-exchange-sha256
.
The following block should be added in the Static block:
configuration.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");
JSch.setConfig(configuration);
public class JSchKeyConfig {
static {
Properties configuration = new Properties();
configuration.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");
JSch.setConfig(configuration);
}
Inject the JSchKeyConfig through Spring beans.
Opinions expressed by DZone contributors are their own.
Comments