1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Class: Net::SSH::UserAuth::Agent</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
<script type="text/javascript">
// <![CDATA[
function popupCode( url ) {
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
}
function toggleCode( id ) {
if ( document.getElementById )
elem = document.getElementById( id );
else if ( document.all )
elem = eval( "document.all." + id );
else
return false;
elemStyle = elem.style;
if ( elemStyle.display != "block" ) {
elemStyle.display = "block"
} else {
elemStyle.display = "none"
}
return true;
}
// Make codeblocks hidden by default
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
// ]]>
</script>
</head>
<body>
<div id="classHeader">
<table class="header-table">
<tr class="top-aligned-row">
<td><strong>Class</strong></td>
<td class="class-name-in-header">Net::SSH::UserAuth::Agent</td>
</tr>
<tr class="top-aligned-row">
<td><strong>In:</strong></td>
<td>
<a href="../../../../files/lib/net/ssh/userauth/agent_rb.html">
lib/net/ssh/userauth/agent.rb
</a>
<br />
</td>
</tr>
<tr class="top-aligned-row">
<td><strong>Parent:</strong></td>
<td>
Object
</td>
</tr>
</table>
</div>
<!-- banner header -->
<div id="bodyContent">
<div id="contextContent">
<div id="description">
<p>
This class implements a simple client for the ssh-agent protocol. It does
not implement any specific protocol, but instead copies the behavior of the
ssh-agent functions in the OpenSSH library (3.8).
</p>
<p>
This means that although it behaves like a SSH1 client, it also has some
SSH2 functionality (like signing data).
</p>
</div>
</div>
<div id="method-list">
<h3 class="section-bar">Methods</h3>
<div class="name-list">
<a href="#M000142">close</a>
<a href="#M000140">connect!</a>
<a href="#M000141">identities</a>
<a href="#M000143">sign</a>
</div>
</div>
</div>
<!-- if includes -->
<div id="section">
<div id="constants-list">
<h3 class="section-bar">Constants</h3>
<div class="name-list">
<table summary="Constants">
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH2_AGENT_REQUEST_VERSION</td>
<td>=</td>
<td class="context-item-value">1</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH2_AGENT_REQUEST_IDENTITIES</td>
<td>=</td>
<td class="context-item-value">11</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH2_AGENT_IDENTITIES_ANSWER</td>
<td>=</td>
<td class="context-item-value">12</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH2_AGENT_SIGN_REQUEST</td>
<td>=</td>
<td class="context-item-value">13</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH2_AGENT_SIGN_RESPONSE</td>
<td>=</td>
<td class="context-item-value">14</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH2_AGENT_FAILURE</td>
<td>=</td>
<td class="context-item-value">30</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH2_AGENT_VERSION_RESPONSE</td>
<td>=</td>
<td class="context-item-value">103</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH_COM_AGENT2_FAILURE</td>
<td>=</td>
<td class="context-item-value">102</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH_AGENT_REQUEST_RSA_IDENTITIES</td>
<td>=</td>
<td class="context-item-value">1</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH_AGENT_RSA_IDENTITIES_ANSWER</td>
<td>=</td>
<td class="context-item-value">2</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">SSH_AGENT_FAILURE</td>
<td>=</td>
<td class="context-item-value">5</td>
</tr>
</table>
</div>
</div>
<div id="attribute-list">
<h3 class="section-bar">Attributes</h3>
<div class="name-list">
<table>
<tr class="top-aligned-row context-row">
<td class="context-item-name">buffers</td>
<td class="context-item-value"> [W] </td>
<td class="context-item-desc">
The buffer factory to use to obtain buffer instances.
</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">keys</td>
<td class="context-item-value"> [W] </td>
<td class="context-item-desc">
The key factory to use to obtain key instances.
</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">socket_factory</td>
<td class="context-item-value"> [W] </td>
<td class="context-item-desc">
The socket factory used to connect to the agent process. It must respond to
open, and accept a single parameter (the name of the socket to open).
</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">socket_name</td>
<td class="context-item-value"> [W] </td>
<td class="context-item-desc">
The name of the socket to open.
</td>
</tr>
<tr class="top-aligned-row context-row">
<td class="context-item-name">version</td>
<td class="context-item-value"> [W] </td>
<td class="context-item-desc">
The version of the <a href="../../SSH.html">SSH</a> protocol version to
report.
</td>
</tr>
</table>
</div>
</div>
<!-- if method_list -->
<div id="methods">
<h3 class="section-bar">Public Instance methods</h3>
<div id="method-M000142" class="method-detail">
<a name="M000142"></a>
<div class="method-heading">
<a href="#M000142" class="method-signature">
<span class="method-name">close</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
<p>
Closes this socket. This agent reference is no longer able to query the
agent.
</p>
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000142-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000142-source">
<pre>
<span class="ruby-comment cmt"># File lib/net/ssh/userauth/agent.rb, line 145</span>
145: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close</span>
146: <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span>
147: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<div id="method-M000140" class="method-detail">
<a name="M000140"></a>
<div class="method-heading">
<a href="#M000140" class="method-signature">
<span class="method-name">connect!</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
<p>
Connect to the agent process using the socket factory and socket name given
by the attribute writers. If the agent on the other end of the socket
reports that it is an SSH2-compatible agent, this will fail (it only
supports the ssh-agent distributed by OpenSSH).
</p>
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000140-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000140-source">
<pre>
<span class="ruby-comment cmt"># File lib/net/ssh/userauth/agent.rb, line 69</span>
69: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connect!</span>
70: <span class="ruby-ivar">@socket</span> = <span class="ruby-ivar">@socket_factory</span>.<span class="ruby-identifier">open</span>( <span class="ruby-ivar">@socket_name</span> )
71:
72: <span class="ruby-comment cmt"># determine what type of agent we're communicating with</span>
73: <span class="ruby-identifier">buffer</span> = <span class="ruby-ivar">@buffers</span>.<span class="ruby-identifier">writer</span>
74: <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">write_string</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span><span class="ruby-operator">::</span><span class="ruby-constant">Transport</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span>.<span class="ruby-identifier">version</span>
75: <span class="ruby-identifier">type</span>, <span class="ruby-identifier">body</span> = <span class="ruby-identifier">send_with_reply</span> <span class="ruby-constant">SSH2_AGENT_REQUEST_VERSION</span>, <span class="ruby-identifier">buffer</span>
76:
77: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-constant">SSH2_AGENT_VERSION_RESPONSE</span>
78: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-value str">"SSH2 agents are not yet supported"</span>
79: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">SSH_AGENT_RSA_IDENTITIES_ANSWER</span>
80: <span class="ruby-identifier">raise</span> <span class="ruby-constant">AgentError</span>,
81: <span class="ruby-node">"unknown response from agent: #{type}, #{body.to_s.inspect}"</span>
82: <span class="ruby-keyword kw">end</span>
83: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<div id="method-M000141" class="method-detail">
<a name="M000141"></a>
<div class="method-heading">
<a href="#M000141" class="method-signature">
<span class="method-name">identities</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
<p>
Return an array of all identities (public keys) known to the agent. Each
key returned is augmented with a <tt>comment</tt> property which is set to
the comment returned by the agent for that key.
</p>
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000141-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000141-source">
<pre>
<span class="ruby-comment cmt"># File lib/net/ssh/userauth/agent.rb, line 88</span>
88: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">identities</span>
89: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@version</span>
90: <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>
91: <span class="ruby-identifier">code1</span> = <span class="ruby-constant">SSH_AGENT_REQUEST_RSA_IDENTITIES</span>
92: <span class="ruby-identifier">code2</span> = <span class="ruby-constant">SSH_AGENT_RSA_IDENTITIES_ANSWER</span>
93: <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span>
94: <span class="ruby-identifier">code1</span> = <span class="ruby-constant">SSH2_AGENT_REQUEST_IDENTITIES</span>
95: <span class="ruby-identifier">code2</span> = <span class="ruby-constant">SSH2_AGENT_IDENTITIES_ANSWER</span>
96: <span class="ruby-keyword kw">else</span>
97: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-node">"SSH version #{@version}"</span>
98: <span class="ruby-keyword kw">end</span>
99:
100: <span class="ruby-identifier">type</span>, <span class="ruby-identifier">body</span> = <span class="ruby-identifier">send_with_reply</span> <span class="ruby-identifier">code1</span>
101: <span class="ruby-identifier">raise</span> <span class="ruby-constant">AgentError</span>,
102: <span class="ruby-value str">"could not get identity count"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">agent_failed</span>( <span class="ruby-identifier">type</span> )
103: <span class="ruby-identifier">raise</span> <span class="ruby-constant">AgentError</span>, <span class="ruby-node">"bad authentication reply: #{type}"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">code2</span>
104:
105: <span class="ruby-identifier">identities</span> = []
106: <span class="ruby-identifier">body</span>.<span class="ruby-identifier">read_long</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span>
107: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@version</span>
108: <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>
109: <span class="ruby-identifier">key</span> = <span class="ruby-ivar">@keys</span>.<span class="ruby-identifier">get</span>( <span class="ruby-value str">"rsa"</span> )
110: <span class="ruby-identifier">bits</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">read_long</span>
111: <span class="ruby-identifier">key</span>.<span class="ruby-identifier">e</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">read_bignum</span>
112: <span class="ruby-identifier">key</span>.<span class="ruby-identifier">n</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">read_bignum</span>
113: <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span>
114: <span class="ruby-identifier">blob</span> = <span class="ruby-ivar">@buffers</span>.<span class="ruby-identifier">reader</span>( <span class="ruby-identifier">body</span>.<span class="ruby-identifier">read_string</span> )
115: <span class="ruby-identifier">key</span> = <span class="ruby-identifier">blob</span>.<span class="ruby-identifier">read_key</span>
116: <span class="ruby-keyword kw">end</span>
117:
118: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:comment=</span> )
119: <span class="ruby-identifier">key</span>.<span class="ruby-identifier">instance_eval</span> <span class="ruby-value str">"def comment=(cmt)\n@comment = cmt\nend\n"</span>
120: <span class="ruby-keyword kw">end</span>
121:
122: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:comment</span> )
123: <span class="ruby-identifier">key</span>.<span class="ruby-identifier">instance_eval</span> <span class="ruby-value str">"def comment\n@comment\nend\n"</span>
124: <span class="ruby-keyword kw">end</span>
125:
126: <span class="ruby-identifier">key</span>.<span class="ruby-identifier">comment</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">read_string</span>
127: <span class="ruby-identifier">identities</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">key</span>
128: <span class="ruby-keyword kw">end</span>
129:
130: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">identities</span>
131: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<div id="method-M000143" class="method-detail">
<a name="M000143"></a>
<div class="method-heading">
<a href="#M000143" class="method-signature">
<span class="method-name">sign</span><span class="method-args">( key, data )</span>
</a>
</div>
<div class="method-description">
<p>
Using the agent and the given public key, sign the given data. The
signature is returned in SSH2 format.
</p>
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000143-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000143-source">
<pre>
<span class="ruby-comment cmt"># File lib/net/ssh/userauth/agent.rb, line 151</span>
151: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sign</span>( <span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span> )
152: <span class="ruby-identifier">blob</span> = <span class="ruby-ivar">@buffers</span>.<span class="ruby-identifier">writer</span>
153: <span class="ruby-identifier">blob</span>.<span class="ruby-identifier">write_key</span> <span class="ruby-identifier">key</span>
154:
155: <span class="ruby-identifier">packet_data</span> = <span class="ruby-ivar">@buffers</span>.<span class="ruby-identifier">writer</span>
156: <span class="ruby-identifier">packet_data</span>.<span class="ruby-identifier">write_string</span> <span class="ruby-identifier">blob</span>.<span class="ruby-identifier">to_s</span>
157: <span class="ruby-identifier">packet_data</span>.<span class="ruby-identifier">write_string</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">to_s</span>
158: <span class="ruby-identifier">packet_data</span>.<span class="ruby-identifier">write_long</span> <span class="ruby-value">0</span>
159:
160: <span class="ruby-identifier">type</span>, <span class="ruby-identifier">reply</span> = <span class="ruby-identifier">send_with_reply</span> <span class="ruby-constant">SSH2_AGENT_SIGN_REQUEST</span>, <span class="ruby-identifier">packet_data</span>
161: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">agent_failed</span>( <span class="ruby-identifier">type</span> )
162: <span class="ruby-identifier">raise</span> <span class="ruby-constant">AgentError</span>,
163: <span class="ruby-value str">"agent could not sign data with requested identity"</span>
164: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">SSH2_AGENT_SIGN_RESPONSE</span>
165: <span class="ruby-identifier">raise</span> <span class="ruby-constant">AgentError</span>, <span class="ruby-node">"bad authentication response #{type}"</span>
166: <span class="ruby-keyword kw">end</span>
167:
168: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">reply</span>.<span class="ruby-identifier">read_string</span>
169: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="validator-badges">
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>
</body>
</html>
|