]> source.dussan.org Git - jgit.git/commitdiff
sshd: simplify ServerKeyLookup interface 70/144570/4
authorThomas Wolf <thomas.wolf@paranor.ch>
Thu, 20 Jun 2019 17:40:45 +0000 (19:40 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Fri, 30 Aug 2019 11:32:11 +0000 (13:32 +0200)
We're actually interested only in the known public keys, we don't need
the corresponding host entry from the config.

Change-Id: Ibde6dffe9e3f87bfbb7c70d1f733b2b0e28cad71
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/ServerKeyLookup.java

index 4ce4f6aadef02351c6173e2c3e41dc00a6d17879..1954abc75b457b64063d844e630dfd6088a8ea3e 100644 (file)
@@ -57,7 +57,6 @@ import java.util.Set;
 
 import org.apache.sshd.client.ClientFactoryManager;
 import org.apache.sshd.client.config.hosts.HostConfigEntry;
-import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier.HostEntryPair;
 import org.apache.sshd.client.keyverifier.ServerKeyVerifier;
 import org.apache.sshd.client.session.ClientSessionImpl;
 import org.apache.sshd.common.FactoryManager;
@@ -293,11 +292,10 @@ public class JGitClientSession extends ClientSessionImpl {
                if (verifier instanceof ServerKeyLookup) {
                        SocketAddress remoteAddress = resolvePeerAddress(
                                        resolveAttribute(JGitSshClient.ORIGINAL_REMOTE_ADDRESS));
-                       List<HostEntryPair> allKnownKeys = ((ServerKeyLookup) verifier)
+                       List<PublicKey> allKnownKeys = ((ServerKeyLookup) verifier)
                                        .lookup(this, remoteAddress);
                        Set<String> reordered = new LinkedHashSet<>();
-                       for (HostEntryPair h : allKnownKeys) {
-                               PublicKey key = h.getServerKey();
+                       for (PublicKey key : allKnownKeys) {
                                if (key != null) {
                                        String keyType = KeyUtils.getKeyType(key);
                                        if (keyType != null) {
index 381f7cfc22c918326d9f4b4170b7a1ed882dad39..3d9fe2a9b348c190a7ba03324cc2a8e682b06333 100644 (file)
@@ -212,11 +212,11 @@ public class OpenSshServerKeyVerifier
        }
 
        @Override
-       public List<HostEntryPair> lookup(ClientSession session,
+       public List<PublicKey> lookup(ClientSession session,
                        SocketAddress remote) {
                List<HostKeyFile> filesToUse = getFilesToUse(session);
                HostKeyHelper helper = new HostKeyHelper();
-               List<HostEntryPair> result = new ArrayList<>();
+               List<PublicKey> result = new ArrayList<>();
                Collection<SshdSocketAddress> candidates = helper
                                .resolveHostNetworkIdentities(session, remote);
                for (HostKeyFile file : filesToUse) {
@@ -224,7 +224,7 @@ public class OpenSshServerKeyVerifier
                                KnownHostEntry entry = current.getHostEntry();
                                for (SshdSocketAddress host : candidates) {
                                        if (entry.isHostMatch(host.getHostName(), host.getPort())) {
-                                               result.add(current);
+                                               result.add(current.getServerKey());
                                                break;
                                        }
                                }
index 4f5f497f7f5a8c4fc0ac9673a03ab72161f0fdf4..2baeb288716afa608c75c132cae821ef5d23f0e9 100644 (file)
@@ -43,9 +43,9 @@
 package org.eclipse.jgit.internal.transport.sshd;
 
 import java.net.SocketAddress;
+import java.security.PublicKey;
 import java.util.List;
 
-import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier.HostEntryPair;
 import org.apache.sshd.client.session.ClientSession;
 import org.eclipse.jgit.annotations.NonNull;
 
@@ -55,7 +55,7 @@ import org.eclipse.jgit.annotations.NonNull;
 public interface ServerKeyLookup {
 
        /**
-        * Retrieves all entries for a given remote address.
+        * Retrieves all public keys known for a given remote.
         *
         * @param session
         *            needed to determine the config files if specified in the ssh
@@ -65,5 +65,5 @@ public interface ServerKeyLookup {
         * @return a possibly empty list of entries found, including revoked ones
         */
        @NonNull
-       List<HostEntryPair> lookup(ClientSession session, SocketAddress remote);
+       List<PublicKey> lookup(ClientSession session, SocketAddress remote);
 }