use of org.apache.sshd.agent.SshAgent in project karaf by apache.
the class Main method setupAgent.
private static void setupAgent(String user, String keyFile, SshClient client, FilePasswordProvider passwordProvider) {
SshAgent agent;
URL builtInPrivateKey = Main.class.getClassLoader().getResource("karaf.key");
agent = startAgent(user, builtInPrivateKey, keyFile, passwordProvider);
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 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.SshAgent 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;
}
}
use of org.apache.sshd.agent.SshAgent in project platformlayer by platformlayer.
the class MinaSshConnection method buildAgentConnection.
@Override
public SshConnection buildAgentConnection(KeyPair agentKeyPair) throws IOException, SshException {
LocalAgentFactory agentFactory = new LocalAgentFactory();
SshAgent agent = agentFactory.getAgent();
try {
agent.addIdentity(agentKeyPair, "default");
} catch (IOException e) {
throw new IllegalArgumentException("Error adding agent identity", e);
}
MinaSshConnection agentConnection = new MinaSshConnection(new MinaSshContext(agentFactory));
agentConnection.setHost(this.getHost());
agentConnection.setPort(this.getPort());
agentConnection.setUser(this.getUser());
agentConnection.setServerKeyVerifier(this.getServerKeyVerifier());
agentConnection.setKeyPair(this.getKeyPair());
agentConnection.ensureConnected();
return agentConnection;
}
Aggregations