Your IP : 216.73.216.213
B
��q^>� � @ s$ d Z ddlmZmZ ddlZddlZddlmZmZ ddl Z ddl
Z
ddlZddlZddl
mZ ddlmZ ddlmZmZ ddlmZmZmZmZ dd lmZmZ dd
lmZ yddlmZm Z W n$ e!k
r� ddlm"Zm#Z Y nX dd
l$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z. ddl,m/Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@ZAmBZCmDZE ddlFmGZGmHZH ddlImJZJ e�K� e�L� e�M� d�ZNdddd�ZOG dd� deP�ZQG dd � d eP�ZRG d!d"� d"eP�ZSG d#d$� d$eH�ZTG d%d&� d&eU�ZVd*d(d)�ZWdS )+z$
Handling of RSA, DSA, and EC keys.
� )�absolute_import�divisionN)�md5�sha256)�InvalidSignature)�default_backend)�hashes�
serialization)�dsa�rsa�padding�ec)�load_pem_private_key�load_ssh_public_key)�utils)�encode_dss_signature�decode_dss_signature)�encode_rfc6979_signature�decode_rfc6979_signature)�Cipher�
algorithms�modes)�PyAsn1Error)�univ)�decoder)�encoder)�common�sexpy)�int_from_bytes�int_to_bytes)� randbytes) � iterbytes�long�izip�nativeString�unicode�_PY3�_b64decodebytes�_b64encodebytes� _bytesChr)�
NamedConstant�Names)�_mutuallyExclusiveArguments)s ecdsa-sha2-nistp256s ecdsa-sha2-nistp384s ecdsa-sha2-nistp521s nistp256s nistp384s nistp521)s secp256r1s secp384r1s secp521r1c @ s e Zd ZdZdS )�BadKeyErrorzj
Raised when a key isn't what we expected from it.
XXX: we really need to check for bad keys
N)�__name__�
__module__�__qualname__�__doc__� r2 r2 �I/opt/alt/python37/lib64/python3.7/site-packages/twisted/conch/ssh/keys.pyr- F s r- c @ s e Zd ZdZdS )�EncryptedKeyErrorzb
Raised when an encrypted key is presented to fromString/fromFile without
a password.
N)r. r/ r0 r1 r2 r2 r2 r3 r4 O s r4 c @ s e Zd ZdZdS )�BadFingerPrintFormatzS
Raises when unsupported fingerprint formats are presented to fingerprint.
N)r. r/ r0 r1 r2 r2 r2 r3 r5 W s r5 c @ s e Zd ZdZe� Ze� ZdS )�FingerprintFormatsa�
Constants representing the supported formats of key fingerprints.
@cvar MD5_HEX: Named constant representing fingerprint format generated
using md5[RFC1321] algorithm in hexadecimal encoding.
@type MD5_HEX: L{twisted.python.constants.NamedConstant}
@cvar SHA256_BASE64: Named constant representing fingerprint format
generated using sha256[RFC4634] algorithm in base64 encoding
@type SHA256_BASE64: L{twisted.python.constants.NamedConstant}
N)r. r/ r0 r1 r* �MD5_HEX�
SHA256_BASE64r2 r2 r2 r3 r6 ^ s r6 c @ s� e Zd ZdZedRdd��ZedSdd��Zedd� �Zed d
� �Zedd� �Z ed
d� �Z
edd� �Zedd� �Zedd� �Z
edd� �Zedd� �Zedd� �ZedTdd��ZedUdd��ZedVdd ��ZedWd!d"��Zd#d$� Zd%d&� Zd'd(� Zd)d*� Zd+d,� Zd-d.� Zejfd/d0�Zd1d2� Zd3d4� Zd5d6� Z d7d8� Z!d9d:� Z"d;d<� Z#e$d=d>gd=d?gg�dXd@dA��Z%dYdBdC�Z&dZdDdE�Z'd[dFdG�Z(d\dHdI�Z)dJdK� Z*dLdM� Z+dNdO� Z,dPdQ� Z-dS )]�Keyau
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().
Nc C s( t |d��}| �|�� ||�S Q R X dS )a�
Load a key from a file.
@param filename: The path to load key data from.
@type type: L{str} or L{None}
@param type: A string describing the format the key data is in, or
L{None} to attempt detection of the type.
@type passphrase: L{bytes} or L{None}
@param passphrase: The passphrase the key is encrypted with, or L{None}
if there is no encryption.
@rtype: L{Key}
@return: The loaded key.
�rbN)�open�
fromString�read)�cls�filename�type�
passphrase�fr2 r2 r3 �fromFilex s zKey.fromFilec C s� t |t�r|�d�}t |t�r(|�d�}|dkr:| �|�}|dkrPtd|f ��t| d|�� f d�}|dkr|td|f ��|jjdkr�|r�td��||�S |||�S dS )a
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.
@type data: L{bytes}
@param data: The key data.
@type type: L{str} or L{None}
@param type: A string describing the format the key data is in, or
L{None} to attempt detection of the type.
@type passphrase: L{bytes} or L{None}
@param passphrase: The passphrase the key is encrypted with, or L{None}
if there is no encryption.
@rtype: L{Key}
@return: The loaded key.
zutf-8Nzcannot guess the type of %rz_fromString_%szno _fromString method for %s� zkey not encrypted) �
isinstancer% �encode�_guessStringTyper- �getattr�upper�__code__�co_argcount)r>