requestIdentities() method pumps out \phpseclib\System\SSH\Agent\Identity objects
Author: Jim Wigginton (terrafrost@php.net)
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function connect()
 {
     $serverConfig = $this->getConfiguration();
     $this->sftp = new SFTP($serverConfig->getHost(), $serverConfig->getPort(), 3600);
     switch ($serverConfig->getAuthenticationMethod()) {
         case Configuration::AUTH_BY_PASSWORD:
             $result = $this->sftp->login($serverConfig->getUser(), $serverConfig->getPassword());
             break;
         case Configuration::AUTH_BY_IDENTITY_FILE:
             $key = new RSA();
             $key->setPassword($serverConfig->getPassPhrase());
             $key->loadKey(file_get_contents($serverConfig->getPrivateKey()));
             $result = $this->sftp->login($serverConfig->getUser(), $key);
             break;
         case Configuration::AUTH_BY_PEM_FILE:
             $key = new RSA();
             $key->loadKey(file_get_contents($serverConfig->getPemFile()));
             $result = $this->sftp->login($serverConfig->getUser(), $key);
             break;
         case Configuration::AUTH_BY_AGENT:
             $key = new Agent();
             $key->startSSHForwarding(null);
             $result = $this->sftp->login($serverConfig->getUser(), $key);
             break;
         default:
             throw new RuntimeException('You need to specify authentication method.');
     }
     if (!$result) {
         throw new RuntimeException('Unable to login with the provided credentials.');
     }
 }
Example #2
0
 /**
  * Login with an ssh-agent provided key
  *
  * @param String $username
  * @param \phpseclib\System\SSH\Agent $agent
  * @return Boolean
  * @access private
  */
 function _ssh_agent_login($username, $agent)
 {
     $this->agent = $agent;
     $keys = $agent->requestIdentities();
     foreach ($keys as $key) {
         if ($this->_privatekey_login($username, $key)) {
             return true;
         }
     }
     return false;
 }