← Back
Editing: keys.cpython-38.pyc
U �`�[ � � @ s� d Z ddlmZmZ ddlZddlZddlmZmZ ddl Z ddl mZ ddlm Z ddlmZmZ ddlmZmZmZmZ dd lmZmZ dd lmZ zddlmZmZ W n$ ek r� ddlmZm Z Y nX dd l!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z+ ddl)m,Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z>m?Z@ ddlAmBZBmCZC e�D� e�E� e�F� d�ZGdddd�ZHG dd� deI�ZJG dd� deI�ZKG d d!� d!eI�ZLG d"d#� d#eC�ZMG d$d%� d%eN�ZOd)d'd(�ZPdS )*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)� NamedConstant�Names)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__� r1 r1 �8/usr/lib/python3/dist-packages/twisted/conch/ssh/keys.pyr+ A s r+ c @ s e Zd ZdZdS )�EncryptedKeyErrorzb Raised when an encrypted key is presented to fromString/fromFile without a password. Nr, r1 r1 r1 r2 r3 J s r3 c @ s e Zd ZdZdS )�BadFingerPrintFormatzS Raises when unsupported fingerprint formats are presented to fingerprint. Nr, r1 r1 r1 r2 r4 R s r4 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. r/ r0 r) �MD5_HEX� SHA256_BASE64r1 r1 r1 r2 r5 Y s r5 c @ sV e Zd ZdZedCdd��ZedDdd��Zedd� �Zed d � �Zedd� �Z ed d� �Z edd� �Zedd� �Zedd� �Z edd� �ZedEdd��ZedFdd��ZedGdd��Zdd� Zdd � Zd!d"� Zd#d$� Zd%d&� Zd'd(� Zejfd)d*�Zd+d,� Zd-d.� Zd/d0� Zd1d2� Zd3d4� Zd5d6� Z dHd7d8�Z!d9d:� Z"d;d<� Z#d=d>� Z$d?d@� Z%dAdB� Z&dS )I�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 s4 t |d�� }| �|�� ||�W 5 Q R � 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�fr1 r1 r2 �fromFiles 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. �utf-8Nzcannot guess the type of %rz_fromString_%szno _fromString method for %s� zkey not encrypted) � isinstancer% �encode�_guessStringTyper+ �getattr�upper�__code__�co_argcount)r= �datar? r@ �methodr1 r1 r2 r; � s zKey.fromStringc C s� t �|�\}}|dkr@t �|d�\}}}| t�||��t� ��S |dkr�t �|d�\}}}} }| tj| tj |||d�d��t� ��S |t kr�| tj� t | t �|d�d ��t� ��S td|f ��d S ) a 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 The format of ECDSA-SHA2-* public key blob is:: string 'ecdsa-sha2-[identifier]' integer x integer y identifier is the standard NIST curve name. @type blob: L{bytes} @param blob: The key data. @return: A new key. @rtype: L{twisted.conch.ssh.keys.Key} @raises BadKeyError: if the key type (the first string) is unknown. � ssh-rsarD � ssh-dss� ��p�q�g��y�parameter_numbers� �unknown blob type: %sN)r �getNS�getMPr �RSAPublicNumbers� public_keyr r �DSAPublicNumbers�DSAParameterNumbers�_curveTabler �EllipticCurvePublicNumbersZfrom_encoded_pointr+ ) r= �blob�keyType�rest�e�nrR rS rT rV r1 r1 r2 �_fromString_BLOB� s<