Skip to content

Commit

Permalink
Merge pull request #215 from bcgov/feature/upgradeToSftp6
Browse files Browse the repository at this point in the history
Unable to negotiate key exchange for kex algorithms
  • Loading branch information
jianmingtu authored Jan 30, 2024
2 parents f547106 + cc61f13 commit d0d4d9b
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import ca.bc.gov.open.jrccaccess.autoconfigure.config.exceptions.KnownHostFileNotDefinedException;
import ca.bc.gov.open.jrccaccess.autoconfigure.config.exceptions.KnownHostFileNotFoundException;
import org.apache.commons.lang3.StringUtils;
import org.apache.sshd.client.ClientBuilder;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.kex.BuiltinDHFactories;
import org.apache.sshd.common.signature.BuiltinSignatures;
import org.apache.sshd.sftp.client.SftpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -34,6 +39,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;

@Configuration
@ComponentScan
Expand Down Expand Up @@ -65,7 +71,17 @@ public AutoConfiguration(SftpInputProperties sftpInputProperties) {
@Bean
public SessionFactory<SftpClient.DirEntry> sftpSessionFactory() throws InvalidConfigException, IOException {

DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);

SshClient client = SshClient.setUpDefaultClient();
client.setKeyExchangeFactories(NamedFactory.setUpTransformedFactories(
false,
BuiltinDHFactories.VALUES,
ClientBuilder.DH2KEX
));
client.setSignatureFactories(new ArrayList<>(BuiltinSignatures.VALUES));

DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(client, true);

factory.setHost(properties.getHost());
factory.setPort(properties.getPort());
factory.setUser(properties.getUsername());
Expand Down

0 comments on commit d0d4d9b

Please sign in to comment.