use of org.apache.sshd.agent.SshAgent in project karaf by apache.
the class Main method startAgent.
private static SshAgent startAgent(String user, URL privateKeyUrl, String keyFile, FilePasswordProvider passwordProvider) {
InputStream is = null;
try {
SshAgent agent = new AgentImpl();
is = privateKeyUrl.openStream();
ObjectInputStream r = new ObjectInputStream(is);
KeyPair keyPair = (KeyPair) r.readObject();
is.close();
agent.addIdentity(keyPair, user);
if (keyFile != null) {
FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(Paths.get(keyFile));
fileKeyPairProvider.setPasswordFinder(passwordProvider);
for (KeyPair key : fileKeyPairProvider.loadKeys()) {
agent.addIdentity(key, user);
}
}
return agent;
} catch (Throwable e) {
close(is);
System.err.println("Error starting ssh agent for: " + e.getMessage());
return null;
}
}
use of org.apache.sshd.agent.SshAgent in project karaf by apache.
the class DeployMojo method setupAgent.
private void setupAgent(String user, File keyFile, SshClient client) {
URL builtInPrivateKey = ClientMojo.class.getClassLoader().getResource("karaf.key");
SshAgent agent = startAgent(user, builtInPrivateKey, keyFile);
client.setAgentFactory(new LocalAgentFactory(agent));
client.getProperties().put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, "local");
}
use of org.apache.sshd.agent.SshAgent in project karaf by apache.
the class ClientMojo method setupAgent.
private void setupAgent(String user, File keyFile, SshClient client) {
URL builtInPrivateKey = ClientMojo.class.getClassLoader().getResource("karaf.key");
SshAgent agent = startAgent(user, builtInPrivateKey, keyFile);
client.setAgentFactory(new LocalAgentFactory(agent));
client.getProperties().put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, "local");
}
use of org.apache.sshd.agent.SshAgent in project karaf by apache.
the class KarafAgentFactory method createClient.
public SshAgent createClient(FactoryManager manager) throws IOException {
String proxyId = (String) manager.getProperties().get(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
if (proxyId == null) {
throw new IllegalStateException("No " + SshAgent.SSH_AUTHSOCKET_ENV_NAME + " environment variable set");
}
AgentServerProxy proxy = proxies.get(proxyId);
if (proxy != null) {
return proxy.createClient();
}
SshAgent agent = locals.get(proxyId);
if (agent != null) {
return new AgentDelegate(agent);
}
throw new IllegalStateException("No ssh agent found");
}
use of org.apache.sshd.agent.SshAgent in project karaf by apache.
the class KarafAgentFactory method registerSession.
public void registerSession(org.apache.karaf.shell.api.console.Session session) {
try {
String user = (String) session.get("USER");
SshAgent agent = new AgentImpl();
URL url = getClass().getClassLoader().getResource("karaf.key");
InputStream is = url.openStream();
ObjectInputStream r = new ObjectInputStream(is);
KeyPair keyPair = (KeyPair) r.readObject();
agent.addIdentity(keyPair, "karaf");
String agentId = "local:" + user;
session.put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, agentId);
locals.put(agentId, agent);
} catch (Throwable e) {
LOGGER.warn("Error starting ssh agent for local console", e);
}
}
Aggregations