Rev 846 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 846 | Rev 874 | ||
---|---|---|---|
Line 22... | Line 22... | ||
22 | * echo $ssh->exec('pwd'); |
22 | * echo $ssh->exec('pwd'); |
23 | * echo $ssh->exec('ls -la'); |
23 | * echo $ssh->exec('ls -la'); |
24 | * ?> |
24 | * ?> |
25 | * </code> |
25 | * </code> |
26 | * |
26 | * |
- | 27 | * @category System |
|
- | 28 | * @package SSH\Agent |
|
27 | * @author Jim Wigginton <terrafrost@php.net> |
29 | * @author Jim Wigginton <terrafrost@php.net> |
28 | * @copyright 2014 Jim Wigginton |
30 | * @copyright 2014 Jim Wigginton |
29 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
31 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
30 | * @link http://phpseclib.sourceforge.net |
32 | * @link http://phpseclib.sourceforge.net |
31 | */ |
33 | */ |
Line 41... | Line 43... | ||
41 | /** |
43 | /** |
42 | * Pure-PHP ssh-agent client identity factory |
44 | * Pure-PHP ssh-agent client identity factory |
43 | * |
45 | * |
44 | * requestIdentities() method pumps out \phpseclib3\System\SSH\Agent\Identity objects |
46 | * requestIdentities() method pumps out \phpseclib3\System\SSH\Agent\Identity objects |
45 | * |
47 | * |
- | 48 | * @package SSH\Agent |
|
46 | * @author Jim Wigginton <terrafrost@php.net> |
49 | * @author Jim Wigginton <terrafrost@php.net> |
- | 50 | * @access public |
|
47 | */ |
51 | */ |
48 | class Agent |
52 | class Agent |
49 | { |
53 | { |
50 | use Common\Traits\ReadBytes; |
54 | use Common\Traits\ReadBytes; |
51 | 55 | ||
Line 76... | Line 80... | ||
76 | 80 | ||
77 | /** |
81 | /** |
78 | * Socket Resource |
82 | * Socket Resource |
79 | * |
83 | * |
80 | * @var resource |
84 | * @var resource |
- | 85 | * @access private |
|
81 | */ |
86 | */ |
82 | private $fsock; |
87 | private $fsock; |
83 | 88 | ||
84 | /** |
89 | /** |
85 | * Agent forwarding status |
90 | * Agent forwarding status |
86 | * |
91 | * |
87 | * @var int |
92 | * @var int |
- | 93 | * @access private |
|
88 | */ |
94 | */ |
89 | private $forward_status = self::FORWARD_NONE; |
95 | private $forward_status = self::FORWARD_NONE; |
90 | 96 | ||
91 | /** |
97 | /** |
92 | * Buffer for accumulating forwarded authentication |
98 | * Buffer for accumulating forwarded authentication |
93 | * agent data arriving on SSH data channel destined |
99 | * agent data arriving on SSH data channel destined |
94 | * for agent unix socket |
100 | * for agent unix socket |
95 | * |
101 | * |
96 | * @var string |
102 | * @var string |
- | 103 | * @access private |
|
97 | */ |
104 | */ |
98 | private $socket_buffer = ''; |
105 | private $socket_buffer = ''; |
99 | 106 | ||
100 | /** |
107 | /** |
101 | * Tracking the number of bytes we are expecting |
108 | * Tracking the number of bytes we are expecting |
102 | * to arrive for the agent socket on the SSH data |
109 | * to arrive for the agent socket on the SSH data |
103 | * channel |
110 | * channel |
104 | * |
111 | * |
105 | * @var int |
112 | * @var int |
- | 113 | * @access private |
|
106 | */ |
114 | */ |
107 | private $expected_bytes = 0; |
115 | private $expected_bytes = 0; |
108 | 116 | ||
109 | /** |
117 | /** |
110 | * The current request channel |
118 | * The current request channel |
111 | * |
119 | * |
112 | * @var int |
120 | * @var int |
- | 121 | * @access private |
|
113 | */ |
122 | */ |
114 | private $request_channel; |
123 | private $request_channel; |
115 | 124 | ||
116 | /** |
125 | /** |
117 | * Default Constructor |
126 | * Default Constructor |
118 | * |
127 | * |
119 | * @return \phpseclib3\System\SSH\Agent |
128 | * @return \phpseclib3\System\SSH\Agent |
120 | * @throws \phpseclib3\Exception\BadConfigurationException if SSH_AUTH_SOCK cannot be found |
129 | * @throws \phpseclib3\Exception\BadConfigurationException if SSH_AUTH_SOCK cannot be found |
121 | * @throws \RuntimeException on connection errors |
130 | * @throws \RuntimeException on connection errors |
- | 131 | * @access public |
|
122 | */ |
132 | */ |
123 | public function __construct($address = null) |
133 | public function __construct($address = null) |
124 | { |
134 | { |
125 | if (!$address) { |
135 | if (!$address) { |
126 | switch (true) { |
136 | switch (true) { |
Line 147... | Line 157... | ||
147 | * See "2.5.2 Requesting a list of protocol 2 keys" |
157 | * See "2.5.2 Requesting a list of protocol 2 keys" |
148 | * Returns an array containing zero or more \phpseclib3\System\SSH\Agent\Identity objects |
158 | * Returns an array containing zero or more \phpseclib3\System\SSH\Agent\Identity objects |
149 | * |
159 | * |
150 | * @return array |
160 | * @return array |
151 | * @throws \RuntimeException on receipt of unexpected packets |
161 | * @throws \RuntimeException on receipt of unexpected packets |
- | 162 | * @access public |
|
152 | */ |
163 | */ |
153 | public function requestIdentities() |
164 | public function requestIdentities() |
154 | { |
165 | { |
155 | if (!$this->fsock) { |
166 | if (!$this->fsock) { |
156 | return []; |
167 | return []; |
Line 199... | Line 210... | ||
199 | /** |
210 | /** |
200 | * Signal that agent forwarding should |
211 | * Signal that agent forwarding should |
201 | * be requested when a channel is opened |
212 | * be requested when a channel is opened |
202 | * |
213 | * |
203 | * @return void |
214 | * @return void |
- | 215 | * @access public |
|
204 | */ |
216 | */ |
205 | public function startSSHForwarding() |
217 | public function startSSHForwarding() |
206 | { |
218 | { |
207 | if ($this->forward_status == self::FORWARD_NONE) { |
219 | if ($this->forward_status == self::FORWARD_NONE) { |
208 | $this->forward_status = self::FORWARD_REQUEST; |
220 | $this->forward_status = self::FORWARD_REQUEST; |
Line 212... | Line 224... | ||
212 | /** |
224 | /** |
213 | * Request agent forwarding of remote server |
225 | * Request agent forwarding of remote server |
214 | * |
226 | * |
215 | * @param \phpseclib3\Net\SSH2 $ssh |
227 | * @param \phpseclib3\Net\SSH2 $ssh |
216 | * @return bool |
228 | * @return bool |
- | 229 | * @access private |
|
217 | */ |
230 | */ |
218 | private function request_forwarding($ssh) |
231 | private function request_forwarding($ssh) |
219 | { |
232 | { |
220 | if (!$ssh->requestAgentForwarding()) { |
233 | if (!$ssh->requestAgentForwarding()) { |
221 | return false; |
234 | return false; |
Line 232... | Line 245... | ||
232 | * This method is called upon successful channel |
245 | * This method is called upon successful channel |
233 | * open to give the SSH Agent an opportunity |
246 | * open to give the SSH Agent an opportunity |
234 | * to take further action. i.e. request agent forwarding |
247 | * to take further action. i.e. request agent forwarding |
235 | * |
248 | * |
236 | * @param \phpseclib3\Net\SSH2 $ssh |
249 | * @param \phpseclib3\Net\SSH2 $ssh |
- | 250 | * @access private |
|
237 | */ |
251 | */ |
238 | public function registerChannelOpen($ssh) |
252 | public function registerChannelOpen($ssh) |
239 | { |
253 | { |
240 | if ($this->forward_status == self::FORWARD_REQUEST) { |
254 | if ($this->forward_status == self::FORWARD_REQUEST) { |
241 | $this->request_forwarding($ssh); |
255 | $this->request_forwarding($ssh); |
Line 246... | Line 260... | ||
246 | * Forward data to SSH Agent and return data reply |
260 | * Forward data to SSH Agent and return data reply |
247 | * |
261 | * |
248 | * @param string $data |
262 | * @param string $data |
249 | * @return string Data from SSH Agent |
263 | * @return string Data from SSH Agent |
250 | * @throws \RuntimeException on connection errors |
264 | * @throws \RuntimeException on connection errors |
- | 265 | * @access public |
|
251 | */ |
266 | */ |
252 | public function forwardData($data) |
267 | public function forwardData($data) |
253 | { |
268 | { |
254 | if ($this->expected_bytes > 0) { |
269 | if ($this->expected_bytes > 0) { |
255 | $this->socket_buffer .= $data; |
270 | $this->socket_buffer .= $data; |