GH-8674: Fix ServerKeyVerifier impl for key type (#8675)

Fixes https://github.com/spring-projects/spring-integration/issues/8674

The `ResourceKnownHostsServerKeyVerifier` does not take into account that several different
keys can be present in the known hosts resource for the same host/port

* Fix `ResourceKnownHostsServerKeyVerifier` to find a list of knows host for the requested session.
Then iterate of this result to match the key type first and then compare keys and their `revoked` marker

**Cherry-pick to `6.1.x` & `6.0.x`**
This commit is contained in:
Artem Bilan
2023-07-17 14:26:39 -04:00
committed by GitHub
parent f527025256
commit d4535cab7d
2 changed files with 22 additions and 14 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.sftp.session;
import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -121,7 +122,7 @@ public class SftpSessionFactoryTests {
asyncTaskExecutor.execute(() -> concurrentSessions.add(sftpSessionFactory.getSession()));
}
await().until(() -> concurrentSessions.size() == 3);
await().atMost(Duration.ofSeconds(30)).until(() -> concurrentSessions.size() == 3);
assertThat(concurrentSessions.get(0))
.isNotEqualTo(concurrentSessions.get(1))