/** * Constructor. * * @param listener the listener. * @throws Exception if the agent could not start. */ public MinaRemoteAgent(TaskListener listener) throws Exception { this.listener = listener; agent = new AgentServer(); socket = agent.start(); }
/** * {@inheritDoc} */ public void stop() { agent.close(); } }
public String start() throws Exception { authSocket = AprLibrary.createLocalSocketAddress(); pool = Pool.create(AprLibrary.getInstance().getRootPool()); handle = Local.create(authSocket, pool); int result = Local.bind(handle, 0); if (result != Status.APR_SUCCESS) { throwException(result); } AprLibrary.secureLocalSocket(authSocket, handle); result = Local.listen(handle, 0); if (result != Status.APR_SUCCESS) { throwException(result); } CloseableExecutorService executor = getExecutorService(); agentThread = executor.submit(() -> { try { while (true) { long clientSock = Local.accept(handle); Socket.timeoutSet(clientSock, 10000000); // TODO make this configurable new SshAgentSession(clientSock, agent).run(); } } catch (Exception e) { log.error("Failed to run session", e); } }); return authSocket; }
@Override public void close() throws IOException { IOException err = null; try { agent.close(); } catch (IOException e) { err = e; } Socket.close(handle); try { if ((agentThread != null) && (!agentThread.isDone())) { agentThread.cancel(true); } } finally { agentThread = null; } CloseableExecutorService executor = getExecutorService(); if ((executor != null) && (!executor.isShutdown())) { Collection<?> runners = executor.shutdownNow(); if (log.isDebugEnabled()) { log.debug("Shut down runners count=" + GenericUtils.size(runners)); } } if (err != null) { throw err; } }
/** * {@inheritDoc} */ public void addIdentity(String privateKey, final String passphrase, String comment) throws IOException { if (!SecurityUtils.isBouncyCastleRegistered()) { SecurityUtils.setRegisterBouncyCastle(true); if (!SecurityUtils.isBouncyCastleRegistered()) { throw new IllegalStateException("BouncyCastle must be registered as a JCE provider"); } } try { PEMReader r = new PEMReader(new StringReader(privateKey), passphrase == null ? null : new PasswordFinder() { public char[] getPassword() { return passphrase.toCharArray(); } }); try { Object o = r.readObject(); if (o instanceof KeyPair) { agent.getAgent().addIdentity((KeyPair) o, comment); } } finally { r.close(); } } catch (Exception e) { e.printStackTrace(listener.error(Messages.SSHAgentBuildWrapper_UnableToReadKey(e.getMessage()))); } }
public String start() throws Exception { authSocket = AprLibrary.createLocalSocketAddress(); pool = Pool.create(AprLibrary.getInstance().getRootPool()); handle = Local.create(authSocket, pool); int result = Local.bind(handle, 0); if (result != Status.APR_SUCCESS) { throwException(result); } AprLibrary.secureLocalSocket(authSocket, handle); result = Local.listen(handle, 0); if (result != Status.APR_SUCCESS) { throwException(result); } CloseableExecutorService executor = getExecutorService(); agentThread = executor.submit(() -> { try { while (true) { long clientSock = Local.accept(handle); Socket.timeoutSet(clientSock, 10000000); // TODO make this configurable new SshAgentSession(clientSock, agent).run(); } } catch (Exception e) { log.error("Failed to run session", e); } }); return authSocket; }
@Override public void close() throws IOException { IOException err = null; try { agent.close(); } catch (IOException e) { err = e; } Socket.close(handle); try { if ((agentThread != null) && (!agentThread.isDone())) { agentThread.cancel(true); } } finally { agentThread = null; } CloseableExecutorService executor = getExecutorService(); if ((executor != null) && (!executor.isShutdown())) { Collection<?> runners = executor.shutdownNow(); if (log.isDebugEnabled()) { log.debug("Shut down runners count=" + GenericUtils.size(runners)); } } if (err != null) { throw err; } }