Jump to >

reviewboard.ssh.client

class SSHHostKeys(storage)[source]

Bases: paramiko.hostkeys.HostKeys

Manages known lists of host keys.

This is a specialization of paramiko.HostKeys that interfaces with a storage backend to get the list of host keys.

__init__(storage)[source]
load(filename)[source]

Loads all known host keys from the storage backend.

save(filename)[source]
__abstractmethods__ = frozenset([])[source]
class SSHClient(namespace=None, storage=None)[source]

Bases: paramiko.client.SSHClient

A client for communicating with an SSH server.

SSHClient allows for communicating with an SSH server and managing all known host and user keys.

This is a specialization of paramiko.SSHClient, and supports all the same capabilities.

Key access goes through an SSHStorage backend. The storage backend knows how to look up keys and write them.

The default backend works with the site directory’s data/.ssh directory, and supports namespaced directories for LocalSites.

DEFAULT_STORAGE = u’reviewboard.ssh.storage.FileSSHStorage’[source]
SUPPORTED_KEY_TYPES = (<class ‘paramiko.rsakey.RSAKey’>, <class ‘paramiko.dsskey.DSSKey’>)[source]
__init__(namespace=None, storage=None)[source]
get_user_key()[source]

Returns the keypair of the user running Review Board.

This will be an instance of paramiko.PKey, representing a DSS or RSA key, as long as one exists. Otherwise, it may return None.

delete_user_key()[source]

Deletes the user key for this client.

If no key exists, this will do nothing.

get_public_key(key)[source]

Returns the public key portion of an SSH key.

This will be formatted for display.

is_key_authorized(key)[source]

Returns whether or not a public key is currently authorized.

generate_user_key(bits=2048)[source]

Generates a new RSA keypair for the user running Review Board.

This will store the new key in the backend storage and return the resulting key as an instance of paramiko.RSAKey.

If a key already exists, it’s returned instead.

Callers are expected to handle any exceptions. This may raise IOError for any problems in writing the key file, or paramiko.SSHException for any other problems.

import_user_key(keyfile)[source]

Imports an uploaded key file into Review Board.

keyfile is expected to be an UploadedFile or a paramiko KeyFile. If this is a valid key file, it will be saved in the storage backend and the resulting key as an instance of paramiko.PKey will be returned.

If a key of this name already exists, it will be overwritten.

Callers are expected to handle any exceptions. This may raise IOError for any problems in writing the key file, or paramiko.SSHException for any other problems.

This will raise UnsupportedSSHKeyError if the uploaded key is not a supported type.

add_host_key(hostname, key)[source]

Adds a host key to the known hosts file.

replace_host_key(hostname, old_key, new_key)[source]

Replaces a host key in the known hosts file with another.

This is used for replacing host keys that have changed.