From bbf76b95a06f4394541bc857dd2e9257da353b7c Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Thu, 20 Jun 2019 19:40:45 +0200 Subject: [PATCH] sshd: simplify ServerKeyLookup interface 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 --- .../jgit/internal/transport/sshd/JGitClientSession.java | 6 ++---- .../internal/transport/sshd/OpenSshServerKeyVerifier.java | 6 +++--- .../jgit/internal/transport/sshd/ServerKeyLookup.java | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java index 4ce4f6aad..1954abc75 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java @@ -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 allKnownKeys = ((ServerKeyLookup) verifier) + List allKnownKeys = ((ServerKeyLookup) verifier) .lookup(this, remoteAddress); Set 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) { diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java index 381f7cfc2..3d9fe2a9b 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java @@ -212,11 +212,11 @@ public class OpenSshServerKeyVerifier } @Override - public List lookup(ClientSession session, + public List lookup(ClientSession session, SocketAddress remote) { List filesToUse = getFilesToUse(session); HostKeyHelper helper = new HostKeyHelper(); - List result = new ArrayList<>(); + List result = new ArrayList<>(); Collection 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; } } diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/ServerKeyLookup.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/ServerKeyLookup.java index 4f5f497f7..2baeb2887 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/ServerKeyLookup.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/ServerKeyLookup.java @@ -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 lookup(ClientSession session, SocketAddress remote); + List lookup(ClientSession session, SocketAddress remote); }