summaryrefslogtreecommitdiff
path: root/docs/public/paramiko.util-module.html
blob: a7ad4cdd21e286d264c8d7492bae40e431389245 (plain)
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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>paramiko.util</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css"></link>
</head>
<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">

<!-- =========== START OF NAVBAR =========== -->
<table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="center">
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="paramiko-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="trees.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="indices.html">Index</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar" width="100%"></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <font size="-1"><b class="breadcrumbs">
        <a href="paramiko-module.html">Package&nbsp;paramiko</a> ::
        Module&nbsp;util
      </b></font></br>
    </td>
    <td><table cellpadding="0" cellspacing="0">
      <tr><td align="right"><font size="-2">[<a href="../private/paramiko.util-module.html">show&nbsp;private</a>&nbsp;|&nbsp;hide&nbsp;private]</font></td></tr>
      <tr><td align="right"><font size="-2">[<a href="frames.html"target="_top">frames</a>&nbsp;|&nbsp;<a href="paramiko.util-module.html" target="_top">no&nbsp;frames</a>]</font></td></tr>
    </table></td>
</tr></table>

<!-- =========== START OF MODULE DESCRIPTION =========== -->
<h2 class="module">Module paramiko.util</h2>

Useful functions used by the rest of paramiko.
<hr/>

<!-- =========== START OF CLASSES =========== -->
<table class="summary" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="summary">
  <th colspan="2">Classes</th></tr>
<tr><td width="15%">
  <b><a href="paramiko.util.PFilter-class.html"><code>PFilter</code></a></b></td>
  <td>&nbsp;</td></tr>
</table><br />


<!-- =========== START OF FUNCTION SUMMARY =========== -->
<table class="summary" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="summary">
  <th colspan="2">Function Summary</th></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><a name="bit_length"></a><span class="summary-sig"><span class="summary-sig-name">bit_length</span>(<span class=summary-sig-arg>n</span>)</span></code>
</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><span class="summary-sig"><a href="paramiko.util-module.html#deflate_long" class="summary-sig-name"><code>deflate_long</code></a>(<span class=summary-sig-arg>n</span>,
          <span class=summary-sig-arg>add_sign_padding</span>)</span></code>
<br />
turns a long-int into a normalized byte string (adapted from 
Crypto.Util.number)</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><a name="format_binary"></a><span class="summary-sig"><span class="summary-sig-name">format_binary</span>(<span class=summary-sig-arg>data</span>,
          <span class=summary-sig-arg>prefix</span>)</span></code>
</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><a name="format_binary_line"></a><span class="summary-sig"><span class="summary-sig-name">format_binary_line</span>(<span class=summary-sig-arg>data</span>)</span></code>
</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><a name="format_binary_weird"></a><span class="summary-sig"><span class="summary-sig-name">format_binary_weird</span>(<span class=summary-sig-arg>data</span>)</span></code>
</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">        string
</font></td>
  <td><code><span class="summary-sig"><a href="paramiko.util-module.html#generate_key_bytes" class="summary-sig-name"><code>generate_key_bytes</code></a>(<span class=summary-sig-arg>hashclass</span>,
          <span class=summary-sig-arg>salt</span>,
          <span class=summary-sig-arg>key</span>,
          <span class=summary-sig-arg>nbytes</span>)</span></code>
<br />
Given a password, passphrase, or other human-source key, scramble it 
through a secure hash into some keyworthy bytes.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><a name="get_logger"></a><span class="summary-sig"><span class="summary-sig-name">get_logger</span>(<span class=summary-sig-arg>name</span>)</span></code>
</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><a name="get_thread_id"></a><span class="summary-sig"><span class="summary-sig-name">get_thread_id</span>()</span></code>
</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><span class="summary-sig"><a href="paramiko.util-module.html#hexify" class="summary-sig-name"><code>hexify</code></a>(<span class=summary-sig-arg>s</span>)</span></code>
<br />
turn a string into a hex sequence</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><span class="summary-sig"><a href="paramiko.util-module.html#inflate_long" class="summary-sig-name"><code>inflate_long</code></a>(<span class=summary-sig-arg>s</span>,
          <span class=summary-sig-arg>always_positive</span>)</span></code>
<br />
turns a normalized byte string into a long-int (adapted from 
Crypto.Util.number)</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">        dict(hostname, dict(keytype, <a 
        href="../private/paramiko.PKey-class.html" 
        class="link"><code>PKey</code></a>))
</font></td>
  <td><code><span class="summary-sig"><a href="paramiko.util-module.html#load_host_keys" class="summary-sig-name"><code>load_host_keys</code></a>(<span class=summary-sig-arg>filename</span>)</span></code>
<br />
Read a file of known SSH host keys, in the format used by openssh, and 
return a compound dict of <code>hostname -&gt; keytype -&gt;</code> <a 
href="../private/paramiko.PKey-class.html" 
class="link"><code>PKey</code></a>.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><span class="summary-sig"><a href="paramiko.util-module.html#log_to_file" class="summary-sig-name"><code>log_to_file</code></a>(<span class=summary-sig-arg>filename</span>,
          <span class=summary-sig-arg>level</span>)</span></code>
<br />
send paramiko logs to a logfile, if they're not already going 
somewhere</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><span class="summary-sig"><a href="paramiko.util-module.html#lookup_ssh_host_config" class="summary-sig-name"><code>lookup_ssh_host_config</code></a>(<span class=summary-sig-arg>hostname</span>,
          <span class=summary-sig-arg>config</span>)</span></code>
<br />
Return a dict of config options for a given hostname.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><a name="mod_inverse"></a><span class="summary-sig"><span class="summary-sig-name">mod_inverse</span>(<span class=summary-sig-arg>x</span>,
          <span class=summary-sig-arg>m</span>)</span></code>
</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">        object
</font></td>
  <td><code><span class="summary-sig"><a href="paramiko.util-module.html#parse_ssh_config" class="summary-sig-name"><code>parse_ssh_config</code></a>(<span class=summary-sig-arg>file_obj</span>)</span></code>
<br />
Parse a config file of the format used by OpenSSH, and return an 
object that can be used to make queries to <a 
href="paramiko.util-module.html#lookup_ssh_host_config" 
class="link"><code>lookup_ssh_host_config</code></a>.</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><a name="safe_string"></a><span class="summary-sig"><span class="summary-sig-name">safe_string</span>(<span class=summary-sig-arg>s</span>)</span></code>
</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><a name="tb_strings"></a><span class="summary-sig"><span class="summary-sig-name">tb_strings</span>()</span></code>
</td></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><span class="summary-sig"><a href="paramiko.util-module.html#unhexify" class="summary-sig-name"><code>unhexify</code></a>(<span class=summary-sig-arg>s</span>)</span></code>
<br />
turn a hex sequence back into a string</td></tr>
</table><br />


<!-- =========== START OF FUNCTION DETAILS =========== -->
<table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="details">
  <th colspan="2">Function Details</th></tr>
</table>

<a name="deflate_long"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">deflate_long</span>(<span class=sig-arg>n</span>,
          <span class=sig-arg>add_sign_padding</span>=<span class=sig-default>True</span>)</span>
  </h3>
  turns a long-int into a normalized byte string (adapted from 
  Crypto.Util.number)
  <dl><dt></dt><dd>
  </dd></dl>
</td></tr></table>

<a name="generate_key_bytes"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">generate_key_bytes</span>(<span class=sig-arg>hashclass</span>,
          <span class=sig-arg>salt</span>,
          <span class=sig-arg>key</span>,
          <span class=sig-arg>nbytes</span>)</span>
  </h3>
  Given a password, passphrase, or other human-source key, scramble it 
  through a secure hash into some keyworthy bytes. This specific 
  algorithm is used for encrypting/decrypting private key files.
  <dl><dt></dt><dd>
    <dl><dt><b>Parameters:</b></dt>
      <dd><code><b>hashclass</b></code> -
         class from <code>Crypto.Hash</code> that can be used as a 
        secure hashing function (like <code>MD5</code> or 
        <code>SHA</code>).
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=<code>Crypto.Hash</code>)</i>
      <dd><code><b>salt</b></code> -
         data to salt the hash with.
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=string)</i>
      <dd><code><b>key</b></code> -
         human-entered password or passphrase.
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=string)</i>
      <dd><code><b>nbytes</b></code> -
         number of bytes to generate.
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=int)</i>
      </dd>
    </dl>
    <dl><dt><b>Returns:</b></dt>
      <dd>
        key data
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=string)</i>
      </dd>
    </dl>
  </dd></dl>
</td></tr></table>

<a name="hexify"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">hexify</span>(<span class=sig-arg>s</span>)</span>
  </h3>
  turn a string into a hex sequence
  <dl><dt></dt><dd>
  </dd></dl>
</td></tr></table>

<a name="inflate_long"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">inflate_long</span>(<span class=sig-arg>s</span>,
          <span class=sig-arg>always_positive</span>=<span class=sig-default>False</span>)</span>
  </h3>
  turns a normalized byte string into a long-int (adapted from 
  Crypto.Util.number)
  <dl><dt></dt><dd>
  </dd></dl>
</td></tr></table>

<a name="load_host_keys"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">load_host_keys</span>(<span class=sig-arg>filename</span>)</span>
  </h3>
  <p>Read a file of known SSH host keys, in the format used by openssh, 
  and return a compound dict of <code>hostname -&gt; keytype -&gt;</code> 
  <a href="../private/paramiko.PKey-class.html" 
  class="link"><code>PKey</code></a>. The hostname may be an IP address 
  or DNS name. The keytype will be either 
  <code>&quot;ssh-rsa&quot;</code> or 
  <code>&quot;ssh-dss&quot;</code>.</p>
  This type of file unfortunately doesn't exist on Windows, but on 
  posix, it will usually be stored in 
  <code>os.path.expanduser(&quot;~/.ssh/known_hosts&quot;)</code>.
  <dl><dt></dt><dd>
    <dl><dt><b>Parameters:</b></dt>
      <dd><code><b>filename</b></code> -
         name of the file to read host keys from
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=str)</i>
      </dd>
    </dl>
    <dl><dt><b>Returns:</b></dt>
      <dd>
        dict of host keys, indexed by hostname and then keytype
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=dict(hostname, dict(keytype, <a 
        href="../private/paramiko.PKey-class.html" 
        class="link"><code>PKey</code></a>)))</i>
      </dd>
    </dl>
  </dd></dl>
</td></tr></table>

<a name="log_to_file"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">log_to_file</span>(<span class=sig-arg>filename</span>,
          <span class=sig-arg>level</span>=<span class=sig-default>10</span>)</span>
  </h3>
  send paramiko logs to a logfile, if they're not already going 
  somewhere
  <dl><dt></dt><dd>
  </dd></dl>
</td></tr></table>

<a name="lookup_ssh_host_config"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">lookup_ssh_host_config</span>(<span class=sig-arg>hostname</span>,
          <span class=sig-arg>config</span>)</span>
  </h3>
  <p>Return a dict of config options for a given hostname. The 
  <code>config</code> object must come from <a 
  href="paramiko.util-module.html#parse_ssh_config" 
  class="link"><code>parse_ssh_config</code></a>.</p>
  <p>The host-matching rules of OpenSSH's <code>ssh_config</code> man 
  page are used, which means that all configuration options from matching 
  host specifications are merged, with more specific hostmasks taking 
  precedence. In other words, if <code>&quot;Port&quot;</code> is set 
  under <code>&quot;Host *&quot;</code> and also <code>&quot;Host 
  *.example.com&quot;</code>, and the lookup is for 
  <code>&quot;ssh.example.com&quot;</code>, then the port entry for 
  <code>&quot;Host *.example.com&quot;</code> will win out.</p>
  The keys in the returned dict are all normalized to lowercase (look 
  for <code>&quot;port&quot;</code>, not <code>&quot;Port&quot;</code>. 
  No other processing is done to the keys or values.
  <dl><dt></dt><dd>
    <dl><dt><b>Parameters:</b></dt>
      <dd><code><b>hostname</b></code> -
         the hostname to lookup
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=str)</i>
      <dd><code><b>config</b></code> -
         the config object to search
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=object)</i>
      </dd>
    </dl>
  </dd></dl>
</td></tr></table>

<a name="parse_ssh_config"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">parse_ssh_config</span>(<span class=sig-arg>file_obj</span>)</span>
  </h3>
  <p>Parse a config file of the format used by OpenSSH, and return an 
  object that can be used to make queries to <a 
  href="paramiko.util-module.html#lookup_ssh_host_config" 
  class="link"><code>lookup_ssh_host_config</code></a>. The format is 
  described in OpenSSH's <code>ssh_config</code> man page. This method is 
  provided primarily as a convenience to posix users (since the OpenSSH 
  format is a de-facto standard on posix) but should work fine on Windows 
  too.</p>
  The return value is currently a list of dictionaries, each 
  containing host-specific configuration, but this is considered an 
  implementation detail and may be subject to change in later 
  versions.
  <dl><dt></dt><dd>
    <dl><dt><b>Parameters:</b></dt>
      <dd><code><b>file_obj</b></code> -
         a file-like object to read the config file from
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=file)</i>
      </dd>
    </dl>
    <dl><dt><b>Returns:</b></dt>
      <dd>
        opaque configuration object
        <br /><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (type=object)</i>
      </dd>
    </dl>
  </dd></dl>
</td></tr></table>

<a name="unhexify"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">unhexify</span>(<span class=sig-arg>s</span>)</span>
  </h3>
  turn a hex sequence back into a string
  <dl><dt></dt><dd>
  </dd></dl>
</td></tr></table>
<br />


<!-- =========== START OF NAVBAR =========== -->
<table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="center">
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="paramiko-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="trees.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="indices.html">Index</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar" width="100%"></th>
  </tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td align="left"><font size="-2">Generated by Epydoc 2.1 on Sun Dec  4 11:16:48 2005</font></td>
    <td align="right"><a href="http://epydoc.sourceforge.net"
                      ><font size="-2">http://epydoc.sf.net</font></a></td>
  </tr>
</table>
</body>
</html>