123            case isset(
$_SERVER[
'SSH_AUTH_SOCK']):
 
  124                $address = 
$_SERVER[
'SSH_AUTH_SOCK'];
 
  126            case isset($_ENV[
'SSH_AUTH_SOCK']):
 
  127                $address = $_ENV[
'SSH_AUTH_SOCK'];
 
  130                user_error(
'SSH_AUTH_SOCK not found');
 
  134        $this->fsock = fsockopen(
'unix://' . $address, 0, $errno, $errstr);
 
  136            user_error(
"Unable to connect to ssh-agent (Error $errno: $errstr)");
 
  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');
 
  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');
 
  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)));
 
  173                $key_comment = fread($this->fsock, $length);
 
  175            $length = current(unpack(
'N', substr($key_blob, 0, 4)));
 
  176            $key_type = substr($key_blob, 4, $length);
 
  180                    $key->loadKey(
'ssh-rsa ' . base64_encode($key_blob) . 
' ' . $key_comment);
 
  188                $identity = 
new Identity($this->fsock);
 
  189                $identity->setPublicKey(
$key);
 
  190                $identity->setPublicKeyBlob($key_blob);
 
  191                $identities[] = $identity;
 
  209        if ($this->forward_status == self::FORWARD_NONE) {
 
  223        $request_channel = $ssh->_get_open_channel();
 
  224        if ($request_channel === 
false) {
 
  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',
 
  237        $ssh->channel_status[$request_channel] = NET_SSH2_MSG_CHANNEL_REQUEST;
 
  239        if (!$ssh->_send_binary_packet($packet)) {
 
  243        $response = $ssh->_get_channel_packet($request_channel);
 
  248        $ssh->channel_status[$request_channel] = NET_SSH2_MSG_CHANNEL_OPEN;
 
  266        if ($this->forward_status == self::FORWARD_REQUEST) {
 
  280        if ($this->expected_bytes > 0) {
 
  281            $this->socket_buffer.= 
$data;
 
  282            $this->expected_bytes -= strlen(
$data);
 
  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;
 
  293        if (strlen($this->socket_buffer) != fwrite($this->fsock, $this->socket_buffer)) {
 
  294            user_error(
'Connection closed attempting to forward data to SSH agent');
 
  297        $this->socket_buffer = 
'';
 
  298        $this->expected_bytes = 0;
 
  300        $agent_reply_bytes = current(unpack(
'N', fread($this->fsock, 4)));
 
  302        $agent_reply_data = fread($this->fsock, $agent_reply_bytes);
 
  303        $agent_reply_data = current(unpack(
'a*', $agent_reply_data));
 
  305        return pack(
'Na*', $agent_reply_bytes, $agent_reply_data);
 
An exception for terminatinating execution or to throw for unit testing.
$socket_buffer
Buffer for accumulating forwarded authentication agent data arriving on SSH data channel destined for...
$expected_bytes
Tracking the number of bytes we are expecting to arrive for the agent socket on the SSH data channel.
_request_forwarding($ssh)
Request agent forwarding of remote server.
requestIdentities()
Request Identities.
_forward_data($data)
Forward data to SSH Agent and return data reply.
const SSH_AGENTC_SIGN_REQUEST
__construct()
Default Constructor.
startSSHForwarding($ssh)
Signal that agent forwarding should be requested when a channel is opened.
const SSH_AGENT_FAILURE
#-
$forward_status
Agent forwarding status.
const SSH_AGENT_SIGN_RESPONSE
const SSH_AGENT_IDENTITIES_ANSWER
const SSH_AGENTC_REQUEST_IDENTITIES
#+ Message numbers
_on_channel_open($ssh)
On successful channel open.
Pure-PHP PKCS#1 compliant implementation of RSA.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']