ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
phpseclib\System\SSH\Agent Class Reference
+ Collaboration diagram for phpseclib\System\SSH\Agent:

Public Member Functions

 __construct ()
 Default Constructor. More...
 
 requestIdentities ()
 Request Identities. More...
 
 startSSHForwarding ($ssh)
 Signal that agent forwarding should be requested when a channel is opened. More...
 
 _request_forwarding ($ssh)
 Request agent forwarding of remote server. More...
 
 _on_channel_open ($ssh)
 On successful channel open. More...
 
 _forward_data ($data)
 Forward data to SSH Agent and return data reply. More...
 

Data Fields

const SSH_AGENTC_REQUEST_IDENTITIES = 11
 #+ Message numbers More...
 
const SSH_AGENT_IDENTITIES_ANSWER = 12
 
const SSH_AGENTC_SIGN_REQUEST = 13
 
const SSH_AGENT_SIGN_RESPONSE = 14
 
const FORWARD_NONE = 0
 #- More...
 
const FORWARD_REQUEST = 1
 
const FORWARD_ACTIVE = 2
 
const SSH_AGENT_FAILURE = 5
 #- More...
 
 $fsock
 
 $forward_status = self::FORWARD_NONE
 Agent forwarding status. More...
 
 $socket_buffer = ''
 Buffer for accumulating forwarded authentication agent data arriving on SSH data channel destined for agent unix socket. More...
 
 $expected_bytes = 0
 Tracking the number of bytes we are expecting to arrive for the agent socket on the SSH data channel. More...
 

Detailed Description

Definition at line 48 of file Agent.php.

Constructor & Destructor Documentation

◆ __construct()

phpseclib\System\SSH\Agent::__construct ( )

Default Constructor.

Returns
public

Definition at line 120 of file Agent.php.

References $_SERVER.

121  {
122  switch (true) {
123  case isset($_SERVER['SSH_AUTH_SOCK']):
124  $address = $_SERVER['SSH_AUTH_SOCK'];
125  break;
126  case isset($_ENV['SSH_AUTH_SOCK']):
127  $address = $_ENV['SSH_AUTH_SOCK'];
128  break;
129  default:
130  user_error('SSH_AUTH_SOCK not found');
131  return false;
132  }
133 
134  $this->fsock = fsockopen('unix://' . $address, 0, $errno, $errstr);
135  if (!$this->fsock) {
136  user_error("Unable to connect to ssh-agent (Error $errno: $errstr)");
137  }
138  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

Member Function Documentation

◆ _forward_data()

phpseclib\System\SSH\Agent::_forward_data (   $data)

Forward data to SSH Agent and return data reply.

Parameters
string$data
Returns
data from SSH Agent private

Definition at line 278 of file Agent.php.

References $data.

279  {
280  if ($this->expected_bytes > 0) {
281  $this->socket_buffer.= $data;
282  $this->expected_bytes -= strlen($data);
283  } else {
284  $agent_data_bytes = current(unpack('N', $data));
285  $current_data_bytes = strlen($data);
286  $this->socket_buffer = $data;
287  if ($current_data_bytes != $agent_data_bytes + 4) {
288  $this->expected_bytes = ($agent_data_bytes + 4) - $current_data_bytes;
289  return false;
290  }
291  }
292 
293  if (strlen($this->socket_buffer) != fwrite($this->fsock, $this->socket_buffer)) {
294  user_error('Connection closed attempting to forward data to SSH agent');
295  }
296 
297  $this->socket_buffer = '';
298  $this->expected_bytes = 0;
299 
300  $agent_reply_bytes = current(unpack('N', fread($this->fsock, 4)));
301 
302  $agent_reply_data = fread($this->fsock, $agent_reply_bytes);
303  $agent_reply_data = current(unpack('a*', $agent_reply_data));
304 
305  return pack('Na*', $agent_reply_bytes, $agent_reply_data);
306  }
$data
Definition: bench.php:6

◆ _on_channel_open()

phpseclib\System\SSH\Agent::_on_channel_open (   $ssh)

On successful channel open.

This method is called upon successful channel open to give the SSH Agent an opportunity to take further action. i.e. request agent forwarding

Parameters
Net_SSH2$sshprivate

Definition at line 264 of file Agent.php.

References phpseclib\System\SSH\Agent\_request_forwarding().

265  {
266  if ($this->forward_status == self::FORWARD_REQUEST) {
267  $this->_request_forwarding($ssh);
268  }
269  }
_request_forwarding($ssh)
Request agent forwarding of remote server.
Definition: Agent.php:221
+ Here is the call graph for this function:

◆ _request_forwarding()

phpseclib\System\SSH\Agent::_request_forwarding (   $ssh)

Request agent forwarding of remote server.

Parameters
Net_SSH2$ssh
Returns
bool private

Definition at line 221 of file Agent.php.

References $response.

Referenced by phpseclib\System\SSH\Agent\_on_channel_open().

222  {
223  $request_channel = $ssh->_get_open_channel();
224  if ($request_channel === false) {
225  return false;
226  }
227 
228  $packet = pack(
229  'CNNa*C',
230  NET_SSH2_MSG_CHANNEL_REQUEST,
231  $ssh->server_channels[$request_channel],
232  strlen('auth-agent-req@openssh.com'),
233  'auth-agent-req@openssh.com',
234  1
235  );
236 
237  $ssh->channel_status[$request_channel] = NET_SSH2_MSG_CHANNEL_REQUEST;
238 
239  if (!$ssh->_send_binary_packet($packet)) {
240  return false;
241  }
242 
243  $response = $ssh->_get_channel_packet($request_channel);
244  if ($response === false) {
245  return false;
246  }
247 
248  $ssh->channel_status[$request_channel] = NET_SSH2_MSG_CHANNEL_OPEN;
249  $this->forward_status = self::FORWARD_ACTIVE;
250 
251  return true;
252  }
$response
+ Here is the caller graph for this function:

◆ requestIdentities()

phpseclib\System\SSH\Agent::requestIdentities ( )

Request Identities.

See "2.5.2 Requesting a list of protocol 2 keys" Returns an array containing zero or more objects

Returns
array public

Definition at line 149 of file Agent.php.

References $i, $key, and $type.

150  {
151  if (!$this->fsock) {
152  return array();
153  }
154 
155  $packet = pack('NC', 1, self::SSH_AGENTC_REQUEST_IDENTITIES);
156  if (strlen($packet) != fputs($this->fsock, $packet)) {
157  user_error('Connection closed while requesting identities');
158  }
159 
160  $length = current(unpack('N', fread($this->fsock, 4)));
161  $type = ord(fread($this->fsock, 1));
162  if ($type != self::SSH_AGENT_IDENTITIES_ANSWER) {
163  user_error('Unable to request identities');
164  }
165 
166  $identities = array();
167  $keyCount = current(unpack('N', fread($this->fsock, 4)));
168  for ($i = 0; $i < $keyCount; $i++) {
169  $length = current(unpack('N', fread($this->fsock, 4)));
170  $key_blob = fread($this->fsock, $length);
171  $length = current(unpack('N', fread($this->fsock, 4)));
172  if ($length) {
173  $key_comment = fread($this->fsock, $length);
174  }
175  $length = current(unpack('N', substr($key_blob, 0, 4)));
176  $key_type = substr($key_blob, 4, $length);
177  switch ($key_type) {
178  case 'ssh-rsa':
179  $key = new RSA();
180  $key->loadKey('ssh-rsa ' . base64_encode($key_blob) . ' ' . $key_comment);
181  break;
182  case 'ssh-dss':
183  // not currently supported
184  break;
185  }
186  // resources are passed by reference by default
187  if (isset($key)) {
188  $identity = new Identity($this->fsock);
189  $identity->setPublicKey($key);
190  $identity->setPublicKeyBlob($key_blob);
191  $identities[] = $identity;
192  unset($key);
193  }
194  }
195 
196  return $identities;
197  }
$type
Pure-PHP PKCS#1 compliant implementation of RSA.
$i
Definition: disco.tpl.php:19
$key
Definition: croninfo.php:18

◆ startSSHForwarding()

phpseclib\System\SSH\Agent::startSSHForwarding (   $ssh)

Signal that agent forwarding should be requested when a channel is opened.

Parameters
Net_SSH2$ssh
Returns
bool public

Definition at line 207 of file Agent.php.

208  {
209  if ($this->forward_status == self::FORWARD_NONE) {
210  $this->forward_status = self::FORWARD_REQUEST;
211  }
212  }

Field Documentation

◆ $expected_bytes

phpseclib\System\SSH\Agent::$expected_bytes = 0

Tracking the number of bytes we are expecting to arrive for the agent socket on the SSH data channel.

Definition at line 112 of file Agent.php.

◆ $forward_status

phpseclib\System\SSH\Agent::$forward_status = self::FORWARD_NONE

Agent forwarding status.

private

Definition at line 96 of file Agent.php.

◆ $fsock

phpseclib\System\SSH\Agent::$fsock

Definition at line 89 of file Agent.php.

◆ $socket_buffer

phpseclib\System\SSH\Agent::$socket_buffer = ''

Buffer for accumulating forwarded authentication agent data arriving on SSH data channel destined for agent unix socket.

private

Definition at line 105 of file Agent.php.

◆ FORWARD_ACTIVE

const phpseclib\System\SSH\Agent::FORWARD_ACTIVE = 2

Definition at line 75 of file Agent.php.

◆ FORWARD_NONE

const phpseclib\System\SSH\Agent::FORWARD_NONE = 0

#-

+ Agent forwarding status

private

Definition at line 71 of file Agent.php.

◆ FORWARD_REQUEST

const phpseclib\System\SSH\Agent::FORWARD_REQUEST = 1

Definition at line 73 of file Agent.php.

◆ SSH_AGENT_FAILURE

const phpseclib\System\SSH\Agent::SSH_AGENT_FAILURE = 5

#-

Unused

Definition at line 81 of file Agent.php.

◆ SSH_AGENT_IDENTITIES_ANSWER

const phpseclib\System\SSH\Agent::SSH_AGENT_IDENTITIES_ANSWER = 12

Definition at line 58 of file Agent.php.

◆ SSH_AGENT_SIGN_RESPONSE

const phpseclib\System\SSH\Agent::SSH_AGENT_SIGN_RESPONSE = 14

Definition at line 62 of file Agent.php.

Referenced by phpseclib\System\SSH\Agent\Identity\sign().

◆ SSH_AGENTC_REQUEST_IDENTITIES

const phpseclib\System\SSH\Agent::SSH_AGENTC_REQUEST_IDENTITIES = 11

#+ Message numbers

private

Definition at line 56 of file Agent.php.

◆ SSH_AGENTC_SIGN_REQUEST

const phpseclib\System\SSH\Agent::SSH_AGENTC_SIGN_REQUEST = 13

Definition at line 60 of file Agent.php.

Referenced by phpseclib\System\SSH\Agent\Identity\sign().


The documentation for this class was generated from the following file: