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

Module util

source code

Useful functions used by the rest of ssh.

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=DEBUG)
send ssh logs to a logfile, if they're not already going somewhere
source code
 
get_logger(name) source code
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