Examples of SshAgent


Examples of org.apache.sshd.agent.SshAgent

  }

  @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));
View Full Code Here

Examples of org.apache.sshd.agent.SshAgent

            // the native library is not available, so these tests should be skipped
            authSocket = null;
        }
        assumeThat(authSocket, notNullValue());

        SshAgent client = new AgentClient(authSocket);
        List<SshAgent.Pair<PublicKey, String>> keys = client.getIdentities();
        assertNotNull(keys);
        assertEquals(0, keys.size());

        KeyPair[] k = new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem"}).loadKeys();
        client.addIdentity(k[0], "");
        keys = client.getIdentities();
        assertNotNull(keys);
        assertEquals(1, keys.size());

        client.removeIdentity(k[0].getPublic());
        keys = client.getIdentities();
        assertNotNull(keys);
        assertEquals(0, keys.size());

        client.removeAllIdentities();

        client.close();

        agent.close();
    }
View Full Code Here

Examples of org.apache.sshd.agent.SshAgent

            // the native library is not available, so these tests should be skipped
            authSocket = null;
        }
        assumeThat(authSocket, notNullValue());

        SshAgent client = new AgentClient(authSocket);
        List<SshAgent.Pair<PublicKey, String>> keys = client.getIdentities();
        assertNotNull(keys);
        assertEquals(0, keys.size());

        KeyPair k = Utils.createTestHostKeyProvider().loadKey(KeyPairProvider.SSH_RSA);
        client.addIdentity(k, "");
        keys = client.getIdentities();
        assertNotNull(keys);
        assertEquals(1, keys.size());

        client.removeIdentity(k.getPublic());
        keys = client.getIdentities();
        assertNotNull(keys);
        assertEquals(0, keys.size());

        client.removeAllIdentities();

        client.close();

        agent.close();
    }
View Full Code Here

Examples of org.apache.sshd.agent.SshAgent

        return new ChannelAgentForwarding.Factory();
    }

    public SshAgent createClient(FactoryManager manager) throws IOException {
        String authSocket = manager.getProperties().get(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
        SshAgent agent = new AgentClient(authSocket);
        return agent;
    }
View Full Code Here

Examples of org.apache.sshd.agent.SshAgent

        }
        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");
    }
View Full Code Here

Examples of org.apache.sshd.agent.SshAgent

    }

    public void registerCommandSession(CommandSession session) {
        try {
            String user = (String) session.get("USER");
            SshAgent agent = new AgentImpl();
            URL url = bundleContext.getBundle().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);
View Full Code Here

Examples of org.apache.sshd.agent.SshAgent

        }
        System.exit(exitStatus);
    }

    private static void setupAgent(String user, SshClient client) {
        SshAgent agent;
        URL builtInPrivateKey = Main.class.getClassLoader().getResource("karaf.key");
        agent = startAgent(user, builtInPrivateKey);
        client.setAgentFactory(new LocalAgentFactory(agent));
        client.getProperties().put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, "local");
    }
View Full Code Here

Examples of org.apache.sshd.agent.SshAgent

    }

    private static SshAgent startAgent(String user, URL privateKeyUrl) {
        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);
            return agent;
        } catch (Throwable e) {
            close(is);
            System.err.println("Error starting ssh agent for: " + e.getMessage());
            return null;
View Full Code Here

Examples of org.apache.sshd.agent.SshAgent

    }

    static class SshAgentLoader {
        static SshAgent load(BundleContext bundleContext) {
            try {
                SshAgent agent = new AgentImpl();
                URL url = bundleContext.getBundle().getResource("karaf.key");
                InputStream is = url.openStream();
                ObjectInputStream r = new ObjectInputStream(is);
                KeyPair keyPair = (KeyPair) r.readObject();
                agent.addIdentity(keyPair, "karaf");
                return agent;
            } catch (Throwable e) {
                LOGGER.warn("Error starting ssh agent for local console", e);
                return null;
            }
View Full Code Here

Examples of org.apache.sshd.agent.SshAgent

            }
        }

        SshClient client = null;
        Terminal terminal = null;
        SshAgent agent = null;
        int exitStatus = 0;
        try {

            final Console console = System.console();
            client = SshClient.setUpDefaultClient();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.