sshd: support IdentityAgent config
Handle the 'none' value, and change the value to select Pageant to something that looks like an absolute UNC path name to avoid it's handled as an relative path name. Bug: 577053 Change-Id: I4ccf047abbc1def50e2782319e4fa7c744069401 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
parent
ad098b3b85
commit
4efc6a396a
|
@ -26,7 +26,10 @@ public class PageantConnector extends AbstractConnector {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentityAgent() {
|
public String getIdentityAgent() {
|
||||||
return "pageant"; //$NON-NLS-1$
|
// This must be an absolute Windows path name to avoid that
|
||||||
|
// OpenSshConfigFile treats it as a relative path name. Use an UNC
|
||||||
|
// name on localhost, like for pipes.
|
||||||
|
return "\\\\.\\pageant"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,11 +17,14 @@
|
||||||
import org.apache.sshd.agent.SshAgent;
|
import org.apache.sshd.agent.SshAgent;
|
||||||
import org.apache.sshd.agent.SshAgentFactory;
|
import org.apache.sshd.agent.SshAgentFactory;
|
||||||
import org.apache.sshd.agent.SshAgentServer;
|
import org.apache.sshd.agent.SshAgentServer;
|
||||||
|
import org.apache.sshd.client.config.hosts.HostConfigEntry;
|
||||||
import org.apache.sshd.common.FactoryManager;
|
import org.apache.sshd.common.FactoryManager;
|
||||||
import org.apache.sshd.common.channel.ChannelFactory;
|
import org.apache.sshd.common.channel.ChannelFactory;
|
||||||
import org.apache.sshd.common.session.ConnectionService;
|
import org.apache.sshd.common.session.ConnectionService;
|
||||||
import org.apache.sshd.common.session.Session;
|
import org.apache.sshd.common.session.Session;
|
||||||
import org.eclipse.jgit.annotations.NonNull;
|
import org.eclipse.jgit.annotations.NonNull;
|
||||||
|
import org.eclipse.jgit.internal.transport.sshd.JGitClientSession;
|
||||||
|
import org.eclipse.jgit.transport.SshConstants;
|
||||||
import org.eclipse.jgit.transport.sshd.agent.ConnectorFactory;
|
import org.eclipse.jgit.transport.sshd.agent.ConnectorFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,19 +53,24 @@ public JGitSshAgentFactory(@NonNull ConnectorFactory factory,
|
||||||
@Override
|
@Override
|
||||||
public List<ChannelFactory> getChannelForwardingFactories(
|
public List<ChannelFactory> getChannelForwardingFactories(
|
||||||
FactoryManager manager) {
|
FactoryManager manager) {
|
||||||
// No agent forwarding supported yet.
|
// No agent forwarding supported.
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SshAgent createClient(Session session, FactoryManager manager)
|
public SshAgent createClient(Session session, FactoryManager manager)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// sshd 2.8.0 will pass us the session here. At that point, we can get
|
String identityAgent = null;
|
||||||
// the HostConfigEntry and extract and handle the IdentityAgent setting.
|
if (session instanceof JGitClientSession) {
|
||||||
// For now, pass null to let the ConnectorFactory do its default
|
HostConfigEntry hostConfig = ((JGitClientSession) session)
|
||||||
// behavior (Pageant on Windows, SSH_AUTH_SOCK on Unixes with the
|
.getHostConfigEntry();
|
||||||
// jgit-builtin factory).
|
identityAgent = hostConfig.getProperty(SshConstants.IDENTITY_AGENT,
|
||||||
return new SshAgentClient(factory.create(null, homeDir));
|
null);
|
||||||
|
}
|
||||||
|
if (SshConstants.NONE.equals(identityAgent)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new SshAgentClient(factory.create(identityAgent, homeDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -562,6 +562,14 @@ public void testEnVarSubstitution() throws Exception {
|
||||||
h.getValue(SshConstants.IDENTITY_AGENT));
|
h.getValue(SshConstants.IDENTITY_AGENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIdentityAgentNone() throws Exception {
|
||||||
|
config("Host orcz\nIdentityAgent none\n");
|
||||||
|
HostConfig h = lookup("orcz");
|
||||||
|
assertEquals(SshConstants.NONE,
|
||||||
|
h.getValue(SshConstants.IDENTITY_AGENT));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNegativeMatch() throws Exception {
|
public void testNegativeMatch() throws Exception {
|
||||||
config("Host foo.bar !foobar.baz *.baz\n" + "Port 29418\n");
|
config("Host foo.bar !foobar.baz *.baz\n" + "Port 29418\n");
|
||||||
|
|
|
@ -871,7 +871,7 @@ void substitute(String originalHostName, int port, String userName,
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
// HOSTNAME already done above
|
// HOSTNAME already done above
|
||||||
String value = options.get(SshConstants.IDENTITY_AGENT);
|
String value = options.get(SshConstants.IDENTITY_AGENT);
|
||||||
if (value != null) {
|
if (value != null && !SshConstants.NONE.equals(value)) {
|
||||||
value = r.substitute(value, Replacer.DEFAULT_TOKENS, true);
|
value = r.substitute(value, Replacer.DEFAULT_TOKENS, true);
|
||||||
value = toFile(value, home).getPath();
|
value = toFile(value, home).getPath();
|
||||||
options.put(SshConstants.IDENTITY_AGENT, value);
|
options.put(SshConstants.IDENTITY_AGENT, value);
|
||||||
|
|
Loading…
Reference in New Issue