Description
In what version(s) of Spring Integration are you seeing this issue?
- 6.0.5 (Spring Boot 3.0.6)
- Still in the
main
branch
Describe the bug
When using a DefaultSftpSessionFactory
with knownHostsResource
set, the known_hosts
are matched only by hostname, and not by IP.
Even if host
is set to an IP address in the configuration, only its reverse DNS is matched.
Exception from the log (redacted)
o.a.s.client.session.ClientSessionImpl : exceptionCaught(ClientSessionImpl[[email protected]/203.0.113.1:2222])[state=Opened] SshException: Server key did not validate
To Reproduce
Configure a DefaultSftpSessionFactory
, with host
set to an IP address, and knownHostsResource
set to a classpath known_host
file with a public key configured for the IP.
Expected behavior
The known_hosts should be matched with the IP from the host
config param, like it did in Spring Integration SFTP < 6.
Analyzing a bit more
ResourceKnownHostsServerKeyVerifier.resolveHostNetworkIdentities()
calls SshdSocketAddress.toSshdSocketAddress
, which always fetches the hostname from the connect address's IP.
This behavior appears to be copied from Apache Mina's KnownHostsServerKeyVerifier
. It might well be on purpose on their side to only use hostnames, but this is a regression from the behavior in previous versions of Spring Integration SFTP.
Maybe ResourceKnownHostsServerKeyVerifier.resolveHostNetworkIdentities()
should (in addition?) return the raw address from clientSession.getConnectAddress()
?