Esempio n. 1
0
 /**
  * Get Public Key
  *
  * Wrapper for $this->key->getPublicKey()
  *
  * @access public
  * @param  Integer $format optional
  * @return Mixed
  */
 public function getPublicKey($format = null)
 {
     return !isset($format) ? $this->key->getPublicKey() : $this->key->getPublicKey($format);
 }
Esempio n. 2
0
 /**
  * Request Identities
  *
  * See "2.5.2 Requesting a list of protocol 2 keys"
  * Returns an array containing zero or more \Topxia\Service\Util\Phpsec\System\SSH\Agent\Identity objects
  *
  * @access public
  * @return Array
  */
 public function requestIdentities()
 {
     if (!$this->fsock) {
         return array();
     }
     $packet = pack('NC', 1, self::SSH_AGENTC_REQUEST_IDENTITIES);
     if (strlen($packet) != fputs($this->fsock, $packet)) {
         user_error('Connection closed while requesting identities');
     }
     $length = current(unpack('N', fread($this->fsock, 4)));
     $type = ord(fread($this->fsock, 1));
     if ($type != self::SSH_AGENT_IDENTITIES_ANSWER) {
         user_error('Unable to request identities');
     }
     $identities = array();
     $keyCount = current(unpack('N', fread($this->fsock, 4)));
     for ($i = 0; $i < $keyCount; $i++) {
         $length = current(unpack('N', fread($this->fsock, 4)));
         $key_blob = fread($this->fsock, $length);
         $length = current(unpack('N', fread($this->fsock, 4)));
         $key_comment = fread($this->fsock, $length);
         $length = current(unpack('N', substr($key_blob, 0, 4)));
         $key_type = substr($key_blob, 4, $length);
         switch ($key_type) {
             case 'ssh-rsa':
                 $key = new RSA();
                 $key->loadKey('ssh-rsa ' . base64_encode($key_blob) . ' ' . $key_comment);
                 break;
             case 'ssh-dss':
                 // not currently supported
                 break;
         }
         // resources are passed by reference by default
         if (isset($key)) {
             $identity = new Identity($this->fsock);
             $identity->setPublicKey($key);
             $identity->setPublicKeyBlob($key_blob);
             $identities[] = $identity;
             unset($key);
         }
     }
     return $identities;
 }