jagadeesh
jagadeesh

Reputation: 21

Spring integration sftp new version upgrade issues

Error Log

[sshd-SshClient[thread-4] WARN o.a.s.c.k.AcceptAllServerKeyVerifier - Server at server presented unverified RSA key: SHA256:key

[sshd-SshClient[thread-3] WARN o.a.s.c.s.ClientSessionImpl - exceptionCaught(ClientSessionImpl[server])[state=Opened] IOException: Connection >reset [sshd-SshClient[thread-1] INFO o.a.s.c.s.ClientSessionImpl - Disconnecting(ClientSessionImpl[server]): SSH2_DISCONNECT_PROTOCOL_ERROR - Detected IdleTimeout after 600609/600000 ms.

For first line log known host file was accepted earlier but now it was not able to because of apache-sshd implemenation by spring integration team and for second line, when I checked came to know we can set heatbeat but in spring integration not getting how to pass

Upvotes: 1

Views: 1486

Answers (1)

jagadeesh
jagadeesh

Reputation: 21

@Configuration
public class SftpConfiguration {

    @Value("${sftp.known-hosts}")
    private Resource knownHosts;
    @Value("${sftp.host}")
    private String host;
    @Value("${sftp.port}")
    private int port;
    @Value("${sftp.username}")
    private String user;
    @Value("${sftp.privatekey}")
    private Resource privateKey;
    @Value("${sftp.privateKeyPassphrase}")
    private String privateKeyPassphrase;
   
    @Bean(name = "sftpSessionFactory")
    public DefaultSftpSessionFactory sftpSessionFactory() throws IOException {
        SshClient externalClient = SshClient.setUpDefaultClient();

        // serverKeyverifier will help to set the knowHosts
        ResourceKnownHostsServerKeyVerifier serverKeyVerifier = null;
        if (this.knownHosts != null) {
            serverKeyVerifier = new ResourceKnownHostsServerKeyVerifier(knownHosts);
        }
        externalClient.setServerKeyVerifier(serverKeyVerifier);

        if (this.privateKey != null) {
            IoResource<Resource> privateKeyResource = new AbstractIoResource<>(Resource.class, this.privateKey) {
                public InputStream openInputStream() throws IOException {
                    return (this.getResourceValue()).getInputStream();
                }
            };

            try {
                Collection<KeyPair> keys = SecurityUtils.getKeyPairResourceParser().
                        loadKeyPairs(null, privateKeyResource,FilePasswordProvider.of(this.privateKeyPassphrase));
                externalClient.setKeyIdentityProvider(KeyIdentityProvider.wrapKeyPairs(keys));
            } catch (GeneralSecurityException ex) {
                throw new IOException("Cannot load private key: " + this.privateKey.getFilename(), ex);
            }
        }
        CoreModuleProperties.HEARTBEAT_INTERVAL.set(externalClient, Duration.ofSeconds(10));

        DefaultSftpSessionFactory sftpSessionFactory = new DefaultSftpSessionFactory(externalClient, false);
        sftpSessionFactory.setHost(host);
        sftpSessionFactory.setPort(port);
        sftpSessionFactory.setUser(user);

        return sftpSessionFactory;
    }
}

Upvotes: 1

Related Questions