com.jcraft.jsch.agentproxy.AgentProxyException Java Examples

The following examples show how to use com.jcraft.jsch.agentproxy.AgentProxyException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSchExecutor.java    From vividus with Apache License 2.0 11 votes vote down vote up
private JSch createJSchInstance(ServerConfiguration server) throws AgentProxyException, JSchException
{
    JSch jSch = new JSch();
    if (server.isAgentForwarding())
    {
        Connector connector = ConnectorFactory.getDefault().createConnector();
        jSch.setIdentityRepository(new RemoteIdentityRepository(connector));
    }
    else if (server.getPrivateKey() != null && server.getPublicKey() != null)
    {
        String passphrase = server.getPassphrase();
        jSch.addIdentity("default", getBytes(server.getPrivateKey()), getBytes(server.getPublicKey()),
                passphrase != null ? getBytes(passphrase) : null);
    }
    return jSch;
}
 
Example #2
Source File: JSchExecutor.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Override
public R execute(ServerConfiguration serverConfiguration, Commands commands) throws CommandExecutionException
{
    try
    {
        JSch jSch = createJSchInstance(serverConfiguration);
        return execute(jSch, serverConfiguration, commands);
    }
    catch (JSchException | AgentProxyException e)
    {
        throw new CommandExecutionException(e);
    }
}
 
Example #3
Source File: OpenSSHAgentAuthenticator.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
public OpenSSHAgentAuthenticator() {
    try {
        proxy = new AgentProxy(new SSHAgentConnector(new JNAUSocketFactory()));
    }
    catch(AgentProxyException e) {
        log.warn(String.format("Agent proxy %s failed with %s", this, e));
    }
}
 
Example #4
Source File: PageantAuthenticator.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
public PageantAuthenticator() {
    try {
        this.proxy = new AgentProxy(new PageantConnector());
    }
    catch(AgentProxyException e) {
        log.warn(String.format("Agent proxy %s failed with %s", this, e));
    }
}
 
Example #5
Source File: AgentProxyAwareJschConfigSessionFactory.java    From gitflow-incremental-builder with MIT License 5 votes vote down vote up
private Collection<Identity> getIdentitiesFromAgentProxy() {

        Connector con = null;
        try {
            con = ConnectorFactory.getDefault().createConnector();
        } catch(AgentProxyException e) {
            logger.warn("AgentProxy setup failed, cannot read identities from agent", e);
        }
        return con != null ? new RemoteIdentityRepository(con).getIdentities() : new ArrayList<>();
    }
 
Example #6
Source File: SSHSessionProvider.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
private Session initSessionSshAgent(String username, String socketPath, JSch jsch) throws JSchException {
  final Session session = jsch.getSession(username, myHost, myPort);
  session.setConfig("PreferredAuthentications", "publickey");

  try {
    ConnectorFactory cf = ConnectorFactory.getDefault();
    cf.setUSocketPath(socketPath);
    Connector con = cf.createConnector();
    IdentityRepository irepo = new RemoteIdentityRepository(con);
    jsch.setIdentityRepository(irepo);
    return session;
  } catch (AgentProxyException e) {
    throw new JSchException("Failed to connect to ssh agent.", e);
  }
}
 
Example #7
Source File: DefaultSessionFactory.java    From jsch-extension with MIT License 4 votes vote down vote up
private void setDefaultIdentities() throws JSchException {
    boolean identitiesSet = false;
    try {
        Connector connector = ConnectorFactory.getDefault()
                .createConnector();
        if ( connector != null ) {
            logger.info( "An AgentProxy Connector was found, check for identities" );
            RemoteIdentityRepository repository = new RemoteIdentityRepository( connector );
            Vector<Identity> identities = repository.getIdentities();
            if ( identities.size() > 0 ) {
                logger.info( "Using AgentProxy identities: {}", identities );
                setIdentityRepository( repository );
                identitiesSet = true;
            }
        }
    }
    catch ( AgentProxyException e ) {
        logger.debug( "Failed to load any keys from AgentProxy:", e );
    }
    if ( !identitiesSet ) {
        String privateKeyFilesString = System.getProperty( PROPERTY_JSCH_PRIVATE_KEY_FILES );
        if ( privateKeyFilesString != null && !privateKeyFilesString.isEmpty() ) {
            logger.info( "Using local identities from {}: {}",
                    PROPERTY_JSCH_PRIVATE_KEY_FILES, privateKeyFilesString );
            setIdentitiesFromPrivateKeys( Arrays.asList( privateKeyFilesString.split( "," ) ) );
            identitiesSet = true;
        }
    }
    if ( !identitiesSet ) {
        List<String> privateKeyFiles = new ArrayList<String>();
        for ( File file : new File[] {
                new File( dotSshDir(), "id_rsa" ),
                new File( dotSshDir(), "id_dsa" ),
                new File( dotSshDir(), "id_ecdsa" ) } ) {
            if ( file.exists() ) {
                privateKeyFiles.add( file.getAbsolutePath() );
            }
        }
        logger.info( "Using local identities: {}", privateKeyFiles );
        setIdentitiesFromPrivateKeys( privateKeyFiles );
    }
}