twisted.conch.ssh.keys.Key(object) class documentationtwisted.conch.ssh.keys
View Source
(View In Hierarchy)
An object representing a key. A key can be either a public or private key. A public key can verify a signature; a private key can create or verify a signature. To generate a string that can be stored on disk, use the toString method. If you have a private key, but want the string representation of the public key, use Key.public().toString().
| Instance Variable | keyObject 0 | DEPRECATED. The Crypto.PublicKey object that operations are
performed with. |
| Class Method | fromFile | Load a key from a file. |
| Class Method | fromString | No summary |
| Method | __init__ | Initialize with a private or public
cryptography.hazmat.primitives.asymmetric key. |
| Method | __eq__ | Return True if other represents an object with the same key. |
| Method | __ne__ | Return True if other represents anything other than this key. |
| Method | __repr__ | Return a pretty representation of this object. |
| Method | keyObject 1 | A Crypto.PublicKey object similar to this key. |
| Method | keyObject | Undocumented |
| Method | isPublic | Check if this instance is a public key. |
| Method | public | Returns a version of this key containing only the public key data. If this is a public key, this may or may not be the same object as self. |
| Method | fingerprint | Get the user presentation of the fingerprint of this |
| Method | type | Return the type of the object we wrap. Currently this can only be 'RSA' or 'DSA'. |
| Method | sshType | Get the type of the object we wrap as defined in the SSH protocol, defined in RFC 4253, Section 6.6. Currently this can only be b'ssh-rsa' or b'ssh-dss'. |
| Method | size | Return the size of the object we wrap. |
| Method | data | Return the values of the public key as a dictionary. |
| Method | blob | Return the public key blob for this key. The blob is the over-the-wire format for public keys. |
| Method | privateBlob | Return the private key blob for this key. The blob is the over-the-wire format for private keys: |
| Method | toString | Create a string representation of this key. If the key is a private key
and you want the represenation of its public key, use
key.public().toString(). type maps to a _toString_*
method. |
| Method | sign | Sign some data with this key. |
| Method | verify | Verify a signature using this key. |
| Class Method | _fromString_BLOB | No summary |
| Class Method | _fromString_PRIVATE_BLOB | Return a private key object corresponding to this private key blob. The blob formats are as follows: |
| Class Method | _fromString_PUBLIC_OPENSSH | Return a public key object corresponding to this OpenSSH public key string. The format of an OpenSSH public key string is:: <key type> <base64-encoded public key blob> |
| Class Method | _fromString_PRIVATE_OPENSSH | Return a private key object corresponding to this OpenSSH private key string. If the key is encrypted, passphrase MUST be provided. Providing a passphrase for an unencrypted key is an error. |
| Class Method | _fromString_PUBLIC_LSH | Return a public key corresponding to this LSH public key string. The LSH public key string format is:: <s-expression: ('public-key', (<key type>, (<name, <value>)+))> |
| Class Method | _fromString_PRIVATE_LSH | Return a private key corresponding to this LSH private key string. The LSH private key string format is:: <s-expression: ('private-key', (<key type>, (<name>, <value>)+))> |
| Class Method | _fromString_AGENTV3 | Return a private key object corresponsing to the Secure Shell Key Agent v3 format. |
| Class Method | _guessStringType | Guess the type of key in data. The types map to _fromString_* methods. |
| Class Method | _fromRSAComponents | Build a key from RSA numerical components. |
| Class Method | _fromDSAComponents | Build a key from DSA numerical components. |
| Method | _toString_OPENSSH | No summary |
| Method | _toString_LSH | Return a public or private LSH key. See _fromString_PUBLIC_LSH and _fromString_PRIVATE_LSH for the key formats. |
| Method | _toString_AGENTV3 | Return a private Secure Shell Agent v3 key. See _fromString_AGENTV3 for the key format. |
Load a key from a file.
| Parameters | filename | The path to load key data from. |
| type | A string describing the format the key data is in, or None to
attempt detection of the type. (type: str
or None) | |
| passphrase | The passphrase the key is encrypted with, or None if there is
no encryption. (type: bytes
or None) | |
| Returns | The loaded key. (type: Key) | |
Return a Key object corresponding to the string data. type is optionally the type of string, matching a _fromString_* method. Otherwise, the _guessStringType() classmethod will be used to guess a type. If the key is encrypted, passphrase is used as the decryption key.
| Parameters | data | The key data. (type: bytes) |
| type | A string describing the format the key data is in, or None to
attempt detection of the type. (type: str
or None) | |
| passphrase | The passphrase the key is encrypted with, or None if there is
no encryption. (type: bytes
or None) | |
| Returns | The loaded key. (type: Key) | |
Return a public key object corresponding to this public key blob. The format of a RSA public key blob is:
string 'ssh-rsa' integer e integer n
The format of a DSA public key blob is:
string 'ssh-dss' integer p integer q integer g integer y
| Parameters | blob | The key data. (type: bytes) |
| Returns | A new key. (type: twisted.conch.ssh.keys.Key) | |
| Raises | BadKeyError | if the key type (the first string) is unknown. |
Return a private key object corresponding to this private key blob. The blob formats are as follows:
RSA keys:
string 'ssh-rsa' integer n integer e integer d integer u integer p integer q
DSA keys:
string 'ssh-dss' integer p integer q integer g integer y integer x
| Parameters | blob | The key data. (type: bytes) |
| Returns | A new key. (type: twisted.conch.ssh.keys.Key) | |
| Raises | BadKeyError | if the key type (the first string) is unknown. |
Return a public key object corresponding to this OpenSSH public key string. The format of an OpenSSH public key string is:
<key type> <base64-encoded public key blob>
| Parameters | data | The key data. (type: bytes) |
| Returns | A new key. (type: twisted.conch.ssh.keys.Key) | |
| Raises | BadKeyError | if the blob type is unknown. |
Return a private key object corresponding to this OpenSSH private key string. If the key is encrypted, passphrase MUST be provided. Providing a passphrase for an unencrypted key is an error.
The format of an OpenSSH private key string is:
-----BEGIN <key type> PRIVATE KEY----- [Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,<initialization value>] <base64-encoded ASN.1 structure> ------END <key type> PRIVATE KEY------
The ASN.1 structure of a RSA key is:
(0, n, e, d, p, q)
The ASN.1 structure of a DSA key is:
(0, p, q, g, y, x)
| Parameters | data | The key data. (type: bytes) |
| passphrase | The passphrase the key is encrypted with, or None if it is not
encrypted. (type: bytes
or None) | |
| Returns | A new key. (type: twisted.conch.ssh.keys.Key) | |
| Raises | BadKeyError | if * a passphrase is provided for an unencrypted key * the ASN.1 encoding is incorrect |
| EncryptedKeyError | if * a passphrase is not provided for an encrypted key | |
Return a public key corresponding to this LSH public key string. The LSH public key string format is:
<s-expression: ('public-key', (<key type>, (<name, <value>)+))>
The names for a RSA (key type 'rsa-pkcs1-sha1') key are: n, e. The names for a DSA (key type 'dsa') key are: y, g, p, q.
| Parameters | data | The key data. (type: bytes) |
| Returns | A new key. (type: twisted.conch.ssh.keys.Key) | |
| Raises | BadKeyError | if the key type is unknown |
Return a private key corresponding to this LSH private key string. The LSH private key string format is:
<s-expression: ('private-key', (<key type>, (<name>, <value>)+))>
The names for a RSA (key type 'rsa-pkcs1-sha1') key are: n, e, d, p, q. The names for a DSA (key type 'dsa') key are: y, g, p, q, x.
| Parameters | data | The key data. (type: bytes) |
| Returns | A new key. (type: twisted.conch.ssh.keys.Key) | |
| Raises | BadKeyError | if the key type is unknown |
Return a private key object corresponsing to the Secure Shell Key Agent v3 format.
The SSH Key Agent v3 format for a RSA key is:
string 'ssh-rsa' integer e integer d integer n integer u integer p integer q
The SSH Key Agent v3 format for a DSA key is:
string 'ssh-dss' integer p integer q integer g integer y integer x
| Parameters | data | The key data. (type: bytes) |
| Returns | A new key. (type: twisted.conch.ssh.keys.Key) | |
| Raises | BadKeyError | if the key type (the first string) is unknown |
Guess the type of key in data. The types map to _fromString_* methods.
| Parameters | data | The key data. (type: bytes) |
Build a key from RSA numerical components.
| Parameters | n | The 'n' RSA variable. (type: int) |
| e | The 'e' RSA variable. (type: int) | |
| d | The 'd' RSA variable (optional for a public key). (type: int
or None) | |
| p | The 'p' RSA variable (optional for a public key). (type: int
or None) | |
| q | The 'q' RSA variable (optional for a public key). (type: int
or None) | |
| u | The 'u' RSA variable. Ignored, as its value is determined by p and q. (type: int
or None) | |
| Returns | An RSA key constructed from the values as given. (type: Key) | |
Build a key from DSA numerical components.
| Parameters | y | The 'y' DSA variable. (type: int) |
| p | The 'p' DSA variable. (type: int) | |
| q | The 'q' DSA variable. (type: int) | |
| g | The 'g' DSA variable. (type: int) | |
| x | The 'x' DSA variable (optional for a public key) (type: int
or None) | |
| Returns | A DSA key constructed from the values as given. (type: Key) | |
Initialize with a private or public
cryptography.hazmat.primitives.asymmetric key.
| Parameters | keyObject | Low level key. (type: cryptography.hazmat.primitives.asymmetric key.) |
A Crypto.PublicKey object similar to this key.
As PyCrypto is no longer used for the underlying operations, this property should be avoided.
Check if this instance is a public key.
| Returns | True if this is a public key. | |
Returns a version of this key containing only the public key data. If this is a public key, this may or may not be the same object as self.
| Returns | A public key. (type: Key) | |
Get the user presentation of the fingerprint of this Key. As described
by RFC
4716 section 4:
The fingerprint of a public key consists of the output of the MD5 message-digest algorithm [RFC1321]. The input to the algorithm is the public key data as specified by [RFC4253]. (...) The output of the (MD5) algorithm is presented to the user as a sequence of 16 octets printed as hexadecimal with lowercase letters and separated by colons.
| Returns | the user presentation of this Key's fingerprint,
as a string. (type: str) | |
| Present Since | 8.2 | |
Return the type of the object we wrap. Currently this can only be 'RSA' or 'DSA'.
| Returns | (type: str) | |
Get the type of the object we wrap as defined in the SSH protocol, defined in RFC 4253, Section 6.6. Currently this can only be b'ssh-rsa' or b'ssh-dss'.
| Returns | The key type format. (type: bytes) | |
Return the size of the object we wrap.
| Returns | The size of the key. (type: int) | |
Return the public key blob for this key. The blob is the over-the-wire format for public keys.
SECSH-TRANS RFC 4253 Section 6.6.
RSA keys:
string 'ssh-rsa' integer e integer n
DSA keys:
string 'ssh-dss' integer p integer q integer g integer y
| Returns | (type: bytes) | |
Return the private key blob for this key. The blob is the over-the-wire format for private keys:
Specification in OpenSSH PROTOCOL.agent
RSA keys:
string 'ssh-rsa' integer n integer e integer d integer u integer p integer q
DSA keys:
string 'ssh-dss' integer p integer q integer g integer y integer x
Create a string representation of this key. If the key is a private key
and you want the represenation of its public key, use
key.public().toString(). type maps to a _toString_*
method.
| Parameters | type | The type of string to emit. Currently supported values are
'OPENSSH', 'LSH', and 'AGENTV3'. (type: str) |
| extra | Any extra data supported by the selected format which is not part of the
key itself. For public OpenSSH keys, this is a comment. For private
OpenSSH keys, this is a passphrase to encrypt with. (type: bytes
or NoneType) | |
| Returns | (type: bytes) | |
Return a public or private OpenSSH string. See _fromString_PUBLIC_OPENSSH and _fromString_PRIVATE_OPENSSH for the string formats. If extra is present, it represents a comment for a public key, or a passphrase for a private key.
| Parameters | extra | Comment for a public key or passphrase for a private key (type: bytes) |
| Returns | (type: bytes) | |
Return a public or private LSH key. See _fromString_PUBLIC_LSH and _fromString_PRIVATE_LSH for the key formats.
| Returns | (type: bytes) | |
Return a private Secure Shell Agent v3 key. See _fromString_AGENTV3 for the key format.
| Returns | (type: bytes) | |