Browse Source

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 <thomas.wolf@paranor.ch>
stable-5.5
Thomas Wolf 6 years ago committed by Matthias Sohn
parent
commit
bbf76b95a0
  1. 6
      org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java
  2. 6
      org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java
  3. 6
      org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/ServerKeyLookup.java

6
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<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) {

6
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java

@ -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;
}
}

6
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<HostEntryPair> lookup(ClientSession session, SocketAddress remote);
List<PublicKey> lookup(ClientSession session, SocketAddress remote);
}

Loading…
Cancel
Save