use of org.apache.sshd.agent.local.AgentImpl 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.local.AgentImpl 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);
}
}
use of org.apache.sshd.agent.local.AgentImpl in project karaf by apache.
the class ClientMojo method startAgent.
private SshAgent startAgent(String user, URL privateKeyUrl, File keyFile) {
try (InputStream is = privateKeyUrl.openStream()) {
SshAgent agent = new AgentImpl();
ObjectInputStream r = new ObjectInputStream(is);
KeyPair keyPair = (KeyPair) r.readObject();
is.close();
agent.addIdentity(keyPair, user);
if (keyFile != null) {
FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(keyFile.getAbsoluteFile().toPath());
for (KeyPair key : fileKeyPairProvider.loadKeys()) {
agent.addIdentity(key, user);
}
}
return agent;
} catch (Throwable e) {
getLog().error("Error starting ssh agent for: " + e.getMessage(), e);
return null;
}
}
use of org.apache.sshd.agent.local.AgentImpl in project karaf by apache.
the class DeployMojo method startAgent.
private SshAgent startAgent(String user, URL privateKeyUrl, File keyFile) {
try (InputStream is = privateKeyUrl.openStream()) {
SshAgent agent = new AgentImpl();
ObjectInputStream r = new ObjectInputStream(is);
KeyPair keyPair = (KeyPair) r.readObject();
is.close();
agent.addIdentity(keyPair, user);
if (keyFile != null) {
FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(keyFile.getAbsoluteFile().toPath());
for (KeyPair key : fileKeyPairProvider.loadKeys()) {
agent.addIdentity(key, user);
}
}
return agent;
} catch (Throwable e) {
getLog().error("Error starting ssh agent for: " + e.getMessage(), e);
return null;
}
}
Aggregations