ó
j4Vdc           @   sÔ   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 m
 Z
 m Z d d l m Z d d l m Z m Z d d	 l m Z d d
 l m Z d d l m Z d Z d e f d „  ƒ  YZ d S(   s   
RSA keys.
iÿÿÿÿN(   t   sha1(   t   RSA(   t   util(   t   max_bytet	   zero_bytet   one_byte(   t   Message(   t   BERt   BERException(   t   PKey(   t   long(   t   SSHExceptions   0!0	+ t   RSAKeyc           B   sÈ   e  Z d  Z d d d d d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d d „ Z d d „ Z e d d „ ƒ Z d „  Z d „  Z d „  Z d „  Z RS(   sZ   
    Representation of an RSA key which can be used to sign and verify SSH2
    data.
    c         C   s(  d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ | d  k	 rM |  j | | ƒ d  S| d  k	 rm |  j | | ƒ d  S| d  k r” | d  k	 r” t | ƒ } n  | d  k	 rµ | \ |  _ |  _ nZ | d  k rÐ t	 d ƒ ‚ n  | j
 ƒ  d k rñ t	 d ƒ ‚ n  | j ƒ  |  _ | j ƒ  |  _ t j |  j ƒ |  _ d  S(   Ns   Key object may not be emptys   ssh-rsas   Invalid key(   t   Nonet   nt   et   dt   pt   qt   _from_private_keyt   _from_private_key_fileR   R   t   get_textt	   get_mpintR   t
   bit_lengtht   size(   t   selft   msgt   datat   filenamet   passwordt   valst   file_obj(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   __init__-   s,    					c         C   s@   t  ƒ  } | j d ƒ | j |  j ƒ | j |  j ƒ | j ƒ  S(   Ns   ssh-rsa(   R   t
   add_stringt	   add_mpintR   R   t   asbytes(   R   t   m(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyR#   F   s
    	c         C   s
   |  j  ƒ  S(   N(   R#   (   R   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   __str__M   s    c         C   sJ   t  |  j ƒ  ƒ } | d t  |  j ƒ } | d t  |  j ƒ } t  | ƒ S(   Ni%   (   t   hasht   get_nameR   R   (   R   t   h(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   __hash__P   s    c         C   s   d S(   Ns   ssh-rsa(    (   R   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyR'   V   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   get_bitsY   s    c         C   s   |  j  d  k	 S(   N(   R   R   (   R   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   can_sign\   s    c         C   sš   t  | ƒ j ƒ  } t j t |  j ƒ t |  j ƒ t |  j ƒ f ƒ } t j	 | j
 |  j | ƒ t ƒ  ƒ d d ƒ } t ƒ  } | j d ƒ | j | ƒ | S(   Ni    s   ssh-rsa(   R    t   digestR   t	   constructR
   R   R   R   R   t   deflate_longt   signt   _pkcs1imifyt   bytesR   R!   (   R   R   R,   t   rsat   sigR$   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   sign_ssh_data_   s    3.	c         C   s   | j  ƒ  d k r t St j | j ƒ  t ƒ } t j |  j t | ƒ j ƒ  ƒ t ƒ } t	 j
 t |  j ƒ t |  j ƒ f ƒ } | j | | f ƒ S(   Ns   ssh-rsa(   R   t   FalseR   t   inflate_longt
   get_binaryt   TrueR0   R    R,   R   R-   R
   R   R   t   verify(   R   R   R   R3   t   hash_objR2   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   verify_ssh_sigh   s    ''c         C   sÏ   |  j  d  k s |  j d  k r- t d ƒ ‚ n  d |  j |  j |  j |  j  |  j |  j |  j  d |  j |  j d t j |  j |  j  ƒ g	 } y t	 ƒ  } | j
 | ƒ Wn t k
 rÄ t d ƒ ‚ n X| j ƒ  S(   Ns-   Not enough key info to write private key filei    i   s$   Unable to create ber encoding of key(   R   R   R   R   R   R   R   R   t   mod_inverseR   t   encodeR   R#   (   R   t   keylistt   b(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   _encode_keys   s    !"	c         C   s    |  j  d | |  j ƒ  | ƒ d  S(   NR   (   t   _write_private_key_fileR@   (   R   R   R   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   write_private_key_file€   s    c         C   s    |  j  d | |  j ƒ  | ƒ d  S(   NR   (   t   _write_private_keyR@   (   R   R   R   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   write_private_keyƒ   s    c         C   s[   t  j |  t j | ƒ } t d | j | j f ƒ } | j | _ | j | _ | j	 | _	 | S(   s  
        Generate a new private RSA key.  This factory function can be used to
        generate a new host key or authentication key.

        :param int bits: number of bits the generated key should be.
        :param function progress_func:
            an optional function to call at key points in key generation (used
            by ``pyCrypto.PublicKey``).
        :return: new `.RSAKey` private key
        R   (
   R   t   generatet   ost   urandomR   R   R   R   R   R   (   t   bitst   progress_funcR2   t   key(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyRE   †   s    c         C   sU   t  t j |  j d ƒ ƒ } t | t  t ƒ t  | ƒ d } t t | t t | S(   s›   
        turn a 20-byte SHA1 hash into a blob of data as large as the key's N,
        using PKCS1's "emsa-pkcs1-v1_5" encoding.  totally bizarre.
        i    i   (   t   lenR   R.   R   R   t   SHA1_DIGESTINFOR   R   (   R   R   R   t   filler(    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyR0   ›   s    "c         C   s&   |  j  d | | ƒ } |  j | ƒ d  S(   NR   (   t   _read_private_key_filet   _decode_key(   R   R   R   R   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyR   ¤   s    c         C   s&   |  j  d | | ƒ } |  j | ƒ d  S(   NR   (   t   _read_private_keyRO   (   R   R   R   R   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyR   ¨   s    c         C   sÓ   y t  | ƒ j ƒ  } Wn t k
 r5 t d ƒ ‚ n Xt | ƒ t k	 sj t | ƒ d k  sj | d d k ry t d ƒ ‚ n  | d |  _ | d |  _ | d |  _	 | d |  _
 | d |  _ t j |  j ƒ |  _ d  S(	   Ns   Unable to parse key filei   i    s3   Not a valid RSA private key file (bad ber encoding)i   i   i   i   (   R   t   decodeR   R   t   typet   listRK   R   R   R   R   R   R   R   R   (   R   R   R>   (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyRO   ¬   s    4N(   t   __name__t
   __module__t   __doc__R   R    R#   R%   R)   R'   R*   R+   R4   R;   R@   RB   RD   t   staticmethodRE   R0   R   R   RO   (    (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyR   '   s&   														(   RV   RF   t   hashlibR    t   Crypto.PublicKeyR   t   paramikoR   t   paramiko.commonR   R   R   t   paramiko.messageR   t   paramiko.berR   R   t   paramiko.pkeyR	   t   paramiko.py3compatR
   t   paramiko.ssh_exceptionR   RL   R   (    (    (    s]   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/paramiko/rsakey.pyt   <module>   s   