paramiko.util

Package paramiko :: Module util |
[frames] | no frames]

# Module util

source code

Useful functions used by the rest of paramiko.

Classes
| enumerate
| PFilter
| Counter Stateful counter for CTR mode crypto

Functions
inflate_long(s, always_positive=False) turns a normalized byte string into a long-int (adapted from Crypto.Util.number) | source code
deflate_long(n, add_sign_padding=True) turns a long-int into a normalized byte string (adapted from Crypto.Util.number) | source code
format_binary_weird(data) | source code
format_binary(data, prefix=`'````'`) | source code
format_binary_line(data) | source code
hexify(s) | source code
unhexify(s) | source code
safe_string(s) | source code
bit_length(n) | source code
tb_strings() | source code
string |
generate_key_bytes(hashclass, salt, key, nbytes) Given a password, passphrase, or other human-source key, scramble it through a secure hash into some keyworthy bytes. | source code
dict(hostname, dict(keytype, PKey)) |
load_host_keys(filename) Read a file of known SSH host keys, in the format used by openssh, and return a compound dict of `hostname -> keytype ->` PKey. | source code
parse_ssh_config(file_obj) Provided only as a backward-compatible wrapper around SSHConfig. | source code
lookup_ssh_host_config(hostname, config) Provided only as a backward-compatible wrapper around SSHConfig. | source code
mod_inverse(x, m) | source code
get_thread_id() | source code
log_to_file(filename, level=10) send paramiko logs to a logfile, if they're not already going somewhere | source code
get_logger(name) | source code

Variables
| AUTH_FAILED = `2`
| AUTH_PARTIALLY_SUCCESSFUL = `1`
| AUTH_SUCCESSFUL = `0`
| CONNECTION_FAILED_CODE = ``{`1`:` `'``Administratively prohibited``'``,` 2`:``...``
| CRITICAL = `50`
| DEBUG = `10`
| DISCONNECT_AUTH_CANCELLED_BY_USER = `13`
| DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = `14`
| DISCONNECT_SERVICE_NOT_AVAILABLE = `7`
| ERROR = `40`
| INFO = `20`
| MSG_CHANNEL_CLOSE = `97`
| MSG_CHANNEL_DATA = `94`
| MSG_CHANNEL_EOF = `96`
| MSG_CHANNEL_EXTENDED_DATA = `95`
| MSG_CHANNEL_FAILURE = `100`
| MSG_CHANNEL_OPEN = `90`
| MSG_CHANNEL_OPEN_FAILURE = `92`
| MSG_CHANNEL_OPEN_SUCCESS = `91`
| MSG_CHANNEL_REQUEST = `98`
| MSG_CHANNEL_SUCCESS = `99`
| MSG_CHANNEL_WINDOW_ADJUST = `93`
| MSG_DEBUG = `4`
| MSG_DISCONNECT = `1`
| MSG_GLOBAL_REQUEST = `80`
| MSG_IGNORE = `2`
| MSG_KEXINIT = `20`
| MSG_NAMES = ``{`1`:` `'``disconnect``'``,` 2`:` `'``ignore``'``,` 3`:` `'``unimplemented``'``,``...``
| MSG_NEWKEYS = `21`
| MSG_REQUEST_FAILURE = `82`
| MSG_REQUEST_SUCCESS = `81`
| MSG_SERVICE_ACCEPT = `6`
| MSG_SERVICE_REQUEST = `5`
| MSG_UNIMPLEMENTED = `3`
| MSG_USERAUTH_BANNER = `53`
| MSG_USERAUTH_FAILURE = `51`
| MSG_USERAUTH_INFO_REQUEST = `60`
| MSG_USERAUTH_INFO_RESPONSE = `61`
| MSG_USERAUTH_PK_OK = `60`
| MSG_USERAUTH_REQUEST = `50`
| MSG_USERAUTH_SUCCESS = `52`
| OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED = `1`
| OPEN_FAILED_CONNECT_FAILED = `2`
| OPEN_FAILED_RESOURCE_SHORTAGE = `4`
| OPEN_FAILED_UNKNOWN_CHANNEL_TYPE = `3`
| OPEN_SUCCEEDED = `0`
| PY22 = `False`
| WARNING = `30`
| __package__ = ``'``paramiko``'``
| rng = `Random.new()`

Function Details

### generate_key_bytes(hashclass, salt, key, nbytes) | source code
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. Parameters: `hashclass` (`Crypto.Hash`) - class from `Crypto.Hash` that can be used as a secure hashing function (like `MD5` or `SHA`). `salt` (string) - data to salt the hash with. `key` (string) - human-entered password or passphrase. `nbytes` (int) - number of bytes to generate. Returns: string key data

### load_host_keys(filename) | source code
Read a file of known SSH host keys, in the format used by openssh, and return a compound dict of `hostname -> keytype ->` PKey. The hostname may be an IP address or DNS name. The keytype will be either `"ssh-rsa"` or `"ssh-dss"`. This type of file unfortunately doesn't exist on Windows, but on posix, it will usually be stored in `os.path.expanduser("~/.ssh/known_hosts")`. Since 1.5.3, this is just a wrapper around HostKeys. Parameters: `filename` (str) - name of the file to read host keys from Returns: dict(hostname, dict(keytype, PKey)) dict of host keys, indexed by hostname and then keytype

Variables Details

  ### CONNECTION_FAILED_CODE Value:
      {1: 'Administratively prohibited',
       2: 'Connect failed',
       3: 'Unknown channel type',
       4: 'Resource shortage'}

  ### MSG_NAMES Value:
      {1: 'disconnect',
       2: 'ignore',
       3: 'unimplemented',
       4: 'debug',
       5: 'service-request',
       6: 'service-accept',
       20: 'kexinit',
       21: 'newkeys',
      ...