AlkantarClanX12

Your IP : 3.145.39.176


Current Path : /opt/imunify360/venv/lib/python3.11/site-packages/Crypto/PublicKey/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib/python3.11/site-packages/Crypto/PublicKey/__pycache__/RSA.cpython-311.pyc

�

f��fu����gd�ZddlZddlZddlmZddlmZmZmZddl	m
Z
mZddlm
Z
ddlmZmZmZddlmZmZmZGd	�d
e��Zdd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z dd�Z!e!Z"dZ#dS))�generate�	construct�
import_key�RsaKey�oid�N)�Random)�tobytes�bord�tostr)�DerSequence�DerNull)�Integer)�test_probable_prime�generate_probable_prime�	COMPOSITE)�_expand_subject_public_key_info�_create_subject_public_key_info� _extract_subject_public_key_infoc��eZdZdZd�Zed���Zed���Zed���Zed���Z	ed���Z
ed���Zed	���Zed
���Z
ed���Zed���Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z		d%d�ZeZeZd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&dS)&ra�Class defining an actual RSA key.
    Do not instantiate directly.
    Use :func:`generate`, :func:`construct` or :func:`import_key` instead.

    :ivar n: RSA modulus
    :vartype n: integer

    :ivar e: RSA public exponent
    :vartype e: integer

    :ivar d: RSA private exponent
    :vartype d: integer

    :ivar p: First factor of the RSA modulus
    :vartype p: integer

    :ivar q: Second factor of the RSA modulus
    :vartype q: integer

    :ivar invp: Chinese remainder component (:math:`p^{-1} \text{mod } q`)
    :vartype invp: integer

    :ivar invq: Chinese remainder component (:math:`q^{-1} \text{mod } p`)
    :vartype invq: integer

    :ivar u: Same as ``invp``
    :vartype u: integer

    :undocumented: exportKey, publickey
    c��t|�����}td��}|td��z}|||fvrtd���|���D]\}}t	|d|z|���||kr7|j|jdz
z|_|j|jdz
z|_	d|_
dSdS)a.Build an RSA key.

        :Keywords:
          n : integer
            The modulus.
          e : integer
            The public exponent.
          d : integer
            The private exponent. Only required for private keys.
          p : integer
            The first factor of the modulus. Only required for private keys.
          q : integer
            The second factor of the modulus. Only required for private keys.
          u : integer
            The CRT coefficient (inverse of p modulo q). Only required for
            private keys.
        ��n�e)�p�q�d�uzSome RSA components are missing�_�N)�set�keys�
ValueError�items�setattr�_d�_p�_dp�_q�_dq�_invq)�self�kwargs�	input_set�
public_set�private_set�	component�values       �v/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/PublicKey/RSA.py�__init__zRsaKey.__init__Ss���&����
�
�&�&�	���_�_�
� �3�';�#<�#<�<���[�*�5�5�5��>�?�?�?� &�����	2�	2��I�u��D�#�	�/�5�1�1�1�1���#�#��w�$�'�A�+�.�D�H��w�$�'�A�+�.�D�H��D�J�J�J�$�#�c�*�t|j��S�N)�int�_n�r+s r2rzRsaKey.nr����4�7�|�|�r4c�*�t|j��Sr6)r7�_er9s r2rzRsaKey.evr:r4c�p�|���std���t|j��S)Nz-No private exponent available for public keys)�has_private�AttributeErrorr7r%r9s r2rzRsaKey.dzs4�����!�!�	R� �!P�Q�Q�Q��4�7�|�|�r4c�p�|���std���t|j��S)Nz.No CRT component 'p' available for public keys)r>r?r7r&r9s r2rzRsaKey.p��4�����!�!�	S� �!Q�R�R�R��4�7�|�|�r4c�p�|���std���t|j��S)Nz.No CRT component 'q' available for public keys)r>r?r7r(r9s r2rzRsaKey.q�rAr4c�p�|���std���t|j��S)Nz/No CRT component 'dp' available for public keys)r>r?r7r'r9s r2�dpz	RsaKey.dp��4�����!�!�	T� �!R�S�S�S��4�8�}�}�r4c�p�|���std���t|j��S)Nz/No CRT component 'dq' available for public keys)r>r?r7r)r9s r2�dqz	RsaKey.dq�rEr4c���|���std���|j�$|j�|j��|_t
|j��S)Nz1No CRT component 'invq' available for public keys)r>r?r*r(�inverser&r7r9s r2�invqzRsaKey.invq�sS�����!�!�	V� �!T�U�U�U��:��������1�1�D�J��4�:���r4c��|jSr6)rr9s r2�invpzRsaKey.invp�s	���v�
r4c�p�|���std���t|j��S)Nz.No CRT component 'u' available for public keys)r>r?r7�_ur9s r2rzRsaKey.u�rAr4c�4�|j���S)zSize of the RSA modulus in bits�r8�size_in_bitsr9s r2rQzRsaKey.size_in_bits�s���w�#�#�%�%�%r4c�F�|j���dz
dzdzS)z9The minimal amount of bytes that can hold the RSA modulusr�rPr9s r2�
size_in_byteszRsaKey.size_in_bytes�s%����$�$�&�&��*�q�0�1�4�4r4c��d|cxkr|jksntd���ttt	|��|j|j����S)NrzPlaintext too large)r8r"r7�powrr<)r+�	plaintexts  r2�_encryptzRsaKey._encrypt�sX���I�'�'�'�'���'�'�'�'��2�3�3�3��3�w�y�)�)�4�7�D�G�<�<�=�=�=r4c��d|cxkr|jksntd���|���std���t	jd|j���}t	|��t
||j|j��z|jz}t
||j|j	��}t
||j
|j��}||z
|jz|jz}||j	z|z}|�
|j��|z|jz}|t
||j|j��krtd���|S)NrzCiphertext too largezThis is not a private keyr)�
min_inclusive�
max_exclusivez Fault detected in RSA decryption)r8r"r>�	TypeErrorr�random_rangerVr<r'r&r)r(rNrI)	r+�
ciphertext�r�cp�m1�m2�h�mp�results	         r2�_decryptzRsaKey._decrypt�s6���J�(�(�(�(���(�(�(�(��3�4�4�4����!�!�	9��7�8�8�8�

� �q���H�H�H��
�Z�
 �
 �3�q�$�'�4�7�#;�#;�
;�d�g�
E��
��T�X�t�w�
'�
'��
��T�X�t�w�
'�
'���2�g���
 �D�G�+��
���[�2�
���)�)�D�G�$�$�r�)�T�W�4����V�T�W�d�g�6�6�6�6��?�@�@�@��
r4c�"�t|d��S)z"Whether this is an RSA private keyr%)�hasattrr9s r2r>zRsaKey.has_private�s���t�T�"�"�"r4c��dS�NT�r9s r2�can_encryptzRsaKey.can_encrypt�����tr4c��dSrjrkr9s r2�can_signzRsaKey.can_sign�rmr4c�8�t|j|j���S)z^A matching RSA public key.

        Returns:
            a new :class:`RsaKey` object
        r)rr8r<r9s r2�
public_keyzRsaKey.public_key�s�����4�7�+�+�+�+r4c���|���|���krdS|j|jks|j|jkrdS|���sdS|j|jkS)NFT)r>rrr�r+�others  r2�__eq__z
RsaKey.__eq__�st��������!2�!2�!4�!4�4�4��5��6�U�W�����%�'� 1� 1��5����!�!�	��4���%�'�!�"r4c��||kSr6rkrss  r2�__ne__z
RsaKey.__ne__�s���E�M�"�"r4c��ddlm}|�)Nr)�
PicklingError)�picklery)r+rys  r2�__getstate__zRsaKey.__getstate__�s��(�(�(�(�(�(��r4c�*�|���rRdt|j��t|j��t|j��t|j��fz}nd}dt|j��t|j��|fzS)Nz, d=%d, p=%d, q=%d, u=%d�zRsaKey(n=%d, e=%d%s))r>r7r%r&r(rNr8r<)r+�extras  r2�__repr__zRsaKey.__repr__�s{�������	�.�#�d�g�,�,��D�G���25�d�g�,�,��D�G���2N�N�E�E��E�%��T�W���s�4�7�|�|�U�(K�K�Kr4c�\�|���rd}nd}d|t|��fzS)N�Private�Publicz%s RSA key at 0x%X)r>�id)r+�key_types  r2�__str__zRsaKey.__str__�s8�������	 � �H�H��H�#�x��D���&:�:�:r4�PEMNrc
���|�t|��}|�tj}|dkr�d�|j|jfD��\}}t|d��dzrd|z}t|d��dzrd|z}d||g}d�d	�|D����}	d
tj|	��dd�zS|�	���rtd|j|j|j
|j|j|j
|jdz
z|j
|jdz
zt!|j���|j��g	�����}
|dkrd
}|dkr|rt'd���n�ddlm}|dkr/|�-d}|�|
t.dt1�����}
nqd}|sd}|�|
t.||t1�����}
d}n=d}t3t.t|j|jg��t1����}
|dkr|
S|dkr-ddlm}
|
�|
|||��}t|��St'd|z���)a%Export this RSA key.

        Args:
          format (string):
            The format to use for wrapping the key:

            - *'PEM'*. (*Default*) Text encoding, done according to `RFC1421`_/`RFC1423`_.
            - *'DER'*. Binary encoding.
            - *'OpenSSH'*. Textual encoding, done according to OpenSSH specification.
              Only suitable for public keys (not private keys).

          passphrase (string):
            (*For private keys only*) The pass phrase used for protecting the output.

          pkcs (integer):
            (*For private keys only*) The ASN.1 structure to use for
            serializing the key. Note that even in case of PEM
            encoding, there is an inner ASN.1 DER structure.

            With ``pkcs=1`` (*default*), the private key is encoded in a
            simple `PKCS#1`_ structure (``RSAPrivateKey``).

            With ``pkcs=8``, the private key is encoded in a `PKCS#8`_ structure
            (``PrivateKeyInfo``).

            .. note::
                This parameter is ignored for a public key.
                For DER and PEM, an ASN.1 DER ``SubjectPublicKeyInfo``
                structure is always used.

          protection (string):
            (*For private keys only*)
            The encryption scheme to use for protecting the private key.

            If ``None`` (default), the behavior depends on :attr:`format`:

            - For *'DER'*, the *PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC*
              scheme is used. The following operations are performed:

                1. A 16 byte Triple DES key is derived from the passphrase
                   using :func:`Crypto.Protocol.KDF.PBKDF2` with 8 bytes salt,
                   and 1 000 iterations of :mod:`Crypto.Hash.HMAC`.
                2. The private key is encrypted using CBC.
                3. The encrypted key is encoded according to PKCS#8.

            - For *'PEM'*, the obsolete PEM encryption scheme is used.
              It is based on MD5 for key derivation, and Triple DES for encryption.

            Specifying a value for :attr:`protection` is only meaningful for PKCS#8
            (that is, ``pkcs=8``) and only if a pass phrase is present too.

            The supported schemes for PKCS#8 are listed in the
            :mod:`Crypto.IO.PKCS8` module (see :attr:`wrap_algo` parameter).

          randfunc (callable):
            A function that provides random bytes. Only used for PEM encoding.
            The default is :func:`Crypto.Random.get_random_bytes`.

        Returns:
          byte string: the encoded key

        Raises:
          ValueError:when the format is unknown or when you try to encrypt a private
            key with *DER* format and PKCS#1.

        .. warning::
            If you don't provide a pass phrase, the private key will be
            exported in the clear!

        .. _RFC1421:    http://www.ietf.org/rfc/rfc1421.txt
        .. _RFC1423:    http://www.ietf.org/rfc/rfc1423.txt
        .. _`PKCS#1`:   http://www.ietf.org/rfc/rfc3447.txt
        .. _`PKCS#8`:   http://www.ietf.org/rfc/rfc5208.txt
        N�OpenSSHc�6�g|]}|�����Srk)�to_bytes��.0�xs  r2�
<listcomp>z%RsaKey.export_key.<locals>.<listcomp>Vs ��I�I�I���
�
���I�I�Ir4r��sssh-rsar4c�X�g|]'}tjdt|����|z��(S)�>I)�struct�pack�len)r��kps  r2r�z%RsaKey.export_key.<locals>.<listcomp>\s/��!U�!U�!U�b�&�+�d�C��G�G�"<�"<�r�"A�!U�!U�!Ur4�ssh-rsa ���rzRSA PRIVATE KEY�DERz&PKCS#1 private key cannot be encrypted��PKCS8r�zPRIVATE KEY)�
key_paramszENCRYPTED PRIVATE KEYz"PBKDF2WithHMAC-SHA1AndDES-EDE3-CBCz
PUBLIC KEY�r�z3Unknown key format '%s'. Cannot export the RSA key.)r	r�get_random_bytesr<r8r
�join�binascii�
b2a_base64r>rrrrrrrrI�encoder"�	Crypto.IOr��wraprr
rr�)r+�format�
passphrase�pkcs�
protection�randfunc�e_bytes�n_bytes�keyparts�	keystring�
binary_keyr�r�r��pem_strs               r2�
export_keyzRsaKey.export_keys���Z�!� ��,�,�J����.�H��Y���I�I�t�w���6H�I�I�I��G�W��G�A�J���$�&�
,�!�G�+���G�A�J���$�&�
,�!�G�+��"�G�W�5�H����!U�!U�H�!U�!U�!U�V�V�I���!4�Y�!?�!?����!D�D�D������$	;�$�a�&*�f�&*�f�&*�f�&*�f�&*�f�&*�f���q��&9�&*�f���q��&9�&-�d�f�o�o�&=�&=�d�f�&E�&E�	&(�	)�	)�*0����
��q�y�y�,���U�?�?�z�?�$�%M�N�N�N��+�+�+�+�+�+��U�?�?�z�'9�,�H�!&���J��T�7>�y�y�",�"B�"B�J�J� 7�H�%�J�%I�
�!&���J��,6�
�7>�y�y�",�"B�"B�J�"&�J�J�#�H�8��9D�d�f�FJ�f�FN�:O�:O�9@���;�;�J��U�?�?����U�?�?�%�%�%�%�%�%��j�j��X�z�8�L�L�G��7�#�#�#��N�QW�W�X�X�Xr4c� �td����Nz,Use module Crypto.Signature.pkcs1_15 instead��NotImplementedError)r+�M�Ks   r2�signzRsaKey.sign����!�"P�Q�Q�Qr4c� �td���r�r�)r+r��	signatures   r2�verifyz
RsaKey.verify�r�r4c� �td����Nz+Use module Crypto.Cipher.PKCS1_OAEP insteadr�)r+rWr�s   r2�encryptzRsaKey.encrypt����!�"O�P�P�Pr4c� �td���r�r�)r+r^s  r2�decryptzRsaKey.decrypt�r�r4c��t�r6r��r+r��Bs   r2�blindzRsaKey.blind����!�!r4c��t�r6r�r�s   r2�unblindzRsaKey.unblind�r�r4c��t�r6r�r9s r2�sizezRsaKey.size�r�r4)r�NrNN)'�__name__�
__module__�__qualname__�__doc__r3�propertyrrrrrrDrGrJrLrrQrTrXrfr>rlrorqrurwr{rr�r��	exportKey�	publickeyr�r�r�r�r�r�r�rkr4r2rr3s���������>���>����X������X������X��
����X��
����X��
����X��
����X��
����X������X������X��
&�&�&�5�5�5�>�>�>�
���0#�#�#�
������,�,�,�#�#�#�#�#�#����
L�L�L�;�;�;�>?�-1�MY�MY�MY�MY�`�I��I�R�R�R�R�R�R�Q�Q�Q�Q�Q�Q�"�"�"�"�"�"�"�"�"�"�"r4r�c����
���|dkrtd����dzdks�dkrtd���|�tj}td��x}}t����|���|k�r|d|dzzk�r
|dz}||z
}td��d|zdz
z���x�
�||kr*td��d|zdz
z����
��
fd	�}t
|||�
���td��|dzdz
z�����fd�}t
|||�
��}	�|	z}�dz
�|	dz
��}
��|
��}|���|kr
|d|dzzk��
�|	kr|	�c�}	��|	��}t|�|�|	|�
��S)a0Create a new RSA key pair.

    The algorithm closely follows NIST `FIPS 186-4`_ in its
    sections B.3.1 and B.3.3. The modulus is the product of
    two non-strong probable primes.
    Each prime passes a suitable number of Miller-Rabin tests
    with random bases and a single Lucas test.

    Args:
      bits (integer):
        Key length, or size (in bits) of the RSA modulus.
        It must be at least 1024, but **2048 is recommended.**
        The FIPS standard only defines 1024, 2048 and 3072.
      randfunc (callable):
        Function that returns random bytes.
        The default is :func:`Crypto.Random.get_random_bytes`.
      e (integer):
        Public RSA exponent. It must be an odd positive integer.
        It is typically a small number with very few ones in its
        binary representation.
        The FIPS standard requires the public exponent to be
        at least 65537 (the default).

    Returns: an RSA key object (:class:`RsaKey`, with private key).

    .. _FIPS 186-4: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
    iz"RSA modulus length must be >= 1024�r�zBRSA public exponent must be a positive, odd integer larger than 2.Nrc�H��|�ko|dz
����dkS�Nr)�gcd)�	candidater�min_ps ��r2�filter_pzgenerate.<locals>.filter_p�s*����u�$�D�)�a�-�)<�)<�Q�)?�)?�1�)D�Dr4)�
exact_bitsr��prime_filter�dc�t��|�ko1|dz
����dkot|�z
���kSr�)r��abs)r�r�min_distance�min_qrs ����r2�filter_qzgenerate.<locals>.filter_q�sH�����%�6���]�'�'��*�*�a�/�6��	�A�
�&�&��5�
7r4�rrrrrr)
r"rr�rrQ�sqrtr�lcmrIr)�bitsr�rrr�size_q�size_pr�r�rr�rr�r�r�rs  `         @@@@r2rr�sB�������:�d�{�{��=�>�>�>��1�u��z�z�Q��U�U��]�^�^�^����*���A�J�J��A����
�
�A�
�.�.�
�
�d�
"�
"�q�A�$�!�)�,<�'=�'=��������� �����F�
�Q��7�=�=�?�?�?����V����Q�Z�Z�A��J��N�3�9�9�;�;�E�	E�	E�	E�	E�	E�	E�
$�v�-5�19�
;�
;�
;���q�z�z�d�a�i�#�o�6��	7�	7�	7�	7�	7�	7�	7�	7�

$�v�-5�19�
;�
;�
;��
��E���1�u�k�k�!�a�%� � ��
�I�I�c�N�N��?�.�.�
�
�d�
"�
"�q�A�$�!�)�,<�'=�'=�B	�1�u�u��!���1�	�	�	�!���A��A��a�1��Q�/�/�/�/r4Tc�6�Gd�dt��}|��}td|��D]#\}}t||t|�����$|j}|j}t
|d��st||���}�nM|j}	t
|d��r|j	}
|j
}n�|	|zdz
}|}
|
dzd	kr|
dz}
|
dzd	k�d
}td��}|s�|dkr�t|
��}||krht|||��}|dkrF||dz
kr=t|d|��dkr(t|���|dz��}
d}n|dz}||k�h|dz
}|s|dk��|std
���||
zd	ksJ�||
z}t
|d��r|j}n|
�|��}t|||	|
||���}|�r�|dks||krtd���t|���|��dkrtd���|dzstd���|����rM|	dks|	|krtd���t|���|	��dkrtd���|
|z|krtd���t#|
��t$krtd���t#|��t$krtd���|
dz
|dz
z}||
dz
�|dz
��z}||	zt'|��zdkrtd���t
|d��r6|dks||krtd���|
|z|zdkrtd���|S)a!Construct an RSA key from a tuple of valid RSA components.

    The modulus **n** must be the product of two primes.
    The public exponent **e** must be odd and larger than 1.

    In case of a private key, the following equations must apply:

    .. math::

        \begin{align}
        p*q &= n \\
        e*d &\equiv 1 ( \text{mod lcm} [(p-1)(q-1)]) \\
        p*u &\equiv 1 ( \text{mod } q)
        \end{align}

    Args:
        rsa_components (tuple):
            A tuple of integers, with at least 2 and no
            more than 6 items. The items come in the following order:

            1. RSA modulus *n*.
            2. Public exponent *e*.
            3. Private exponent *d*.
               Only required if the key is private.
            4. First factor of *n* (*p*).
               Optional, but the other factor *q* must also be present.
            5. Second factor of *n* (*q*). Optional.
            6. CRT coefficient *q*, that is :math:`p^{-1} \text{mod }q`. Optional.

        consistency_check (boolean):
            If ``True``, the library will verify that the provided components
            fulfil the main RSA properties.

    Raises:
        ValueError: when the key being imported fails the most basic RSA validity checks.

    Returns: An RSA key object (:class:`RsaKey`).
    c��eZdZdS)�construct.<locals>.InputCompsN)r�r�r�rkr4r2�
InputCompsr�%s�������r4r�r�rrrrr�rFr�Tz2Unable to compute factors p and q from exponent d.rzInvalid RSA public exponentz-RSA public exponent is not coprime to moduluszRSA modulus is not oddzInvalid RSA private exponentz.RSA private exponent is not coprime to modulusz RSA factors do not match moduluszRSA factor p is compositezRSA factor q is compositezInvalid RSA conditionzInvalid RSA component uzInvalid RSA component u with p)�object�zipr$rrrrhrrrrrVr�r"rrIr>rrr7)�rsa_components�consistency_checkr��input_comps�compr1rr�keyrrr�ktot�t�spotted�a�k�candr�phir�s                     r2rr�s1��P
�
�
�
�
�V�
�
�
��*�,�,�K��;�^�L�L�3�3�
��u���T�7�5�>�>�2�2�2�2��
�A��
�A��;��$�$�33��q�A�������M���;��$�$�'	��
�A��
�A�A�
�q�5�1�9�D��A��a�%�1�*�*��a����a�%�1�*�*��G���
�
�A��
�!�c�'�'��A�J�J���$�h�h��q�!�Q�<�<�D��q�y�y�T�a�!�e�_�_��T�1�a���A�9M�9M�$�A�J�J�N�N�4�!�8�4�4��"&�����F�A��$�h�h��Q����
�!�c�'�'��
W� �!U�V�V�V���U�q�L�L�L�L��Q��A��;��$�$�	��
�A�A��	�	�!���A��q�A��a�1��2�2�2���#G�
��6�6�Q�!�V�V��:�;�;�;��1�:�:�>�>�!����!�!��L�M�M�M��1�u�	7��5�6�6�6��?�?���	G��A�v�v��a��� �!?�@�@�@��q�z�z�~�~�a� � �A�%�%� �!Q�R�R�R��1�u��z�z� �!C�D�D�D�"�1�%�%��2�2� �!<�=�=�=�"�1�%�%��2�2� �!<�=�=�=��q�5�Q��U�#�C��!�a�%���Q��U�+�+�+�C��A���C��� �Q�&�&� �!8�9�9�9��s�C� � �
G���6�6�Q�!�V�V�$�%>�?�?�?���E�A�I�!�#�#�$�%E�F�F�F��Jr4c��t���|dd���}|ddkrtd���t|dd�t	|d���|d	��gz��S)
N�	T��nr_elements�only_ints_expectedrz(No PKCS#1 encoding of an RSA private keyr���)r�decoder"rrrI��encodedr,�ders   r2�_import_pkcs1_privater�sx���-�-�
�
�w�A�$�
�
O�
O�C�
�1�v��{�{��C�D�D�D��S��1��X���Q����!8�!8��Q��!@�!@� A�A�B�B�Br4c�h�t���|dd���}t|��S)Nr�Tr�)rrrrs   r2�_import_pkcs1_publicr
�s.��
�-�-�
�
�w�A�$�
�
O�
O�C��S�>�>�r4c�~�t|��\}}}|tks|�td���t|��S)NzNo RSA subjectPublicKeyInfo)rrr"r
)rr,�algoid�encoded_key�paramss     r2�_import_subjectPublicKeyInfor�sA��"A�'�"J�"J��F�K��
��}�}��*��6�7�7�7���,�,�,r4c�>�t|��}t|��Sr6)rr)rr,�sp_infos   r2�_import_x509_certr�s��.�w�7�7�G�'��0�0�0r4c��ddlm}|�||��}|dtkrt	d���t|d|��S)Nrr�zNo PKCS#8 encoded RSA keyr)r�r��unwraprr"�_import_keyDER)rr�r�r�s    r2�
_import_pkcs8r�sW��������
���W�j�)�)�A���t�s�{�{��4�5�5�5��!�A�$�
�+�+�+r4c��tttttf}|D] }	|||��cS#t
$rY�wxYwtd���)z@Import an RSA key (public or private half), encoded in DER form.�RSA key format is not supported)rr
rrrr")�
extern_keyr��	decodings�decodings    r2rr�sy��'�%�-�"��	 �I�����	��8�J�
�3�3�3�3�3���	�	�	��D�	�����6�
7�
7�7s�4�
A�Ac�~�ddlm}m}m}m}|||��\}}|dkrtd���||��\}}||��\}	}||��\}
}||��\}}||��\}}||��\}
}||��\}}||��d�||	|
|
||fD��}t
|��S)Nr)�import_openssh_private_generic�
read_bytes�read_string�
check_paddingzssh-rsazThis SSH key is not RSAc�6�g|]}tj|����Srk)r�
from_bytesr�s  r2r�z/_import_openssh_private_rsa.<locals>.<listcomp>�s#��B�B�B�q�W�
��
"�
"�B�B�Br4)�_opensshrrrr r"r)�data�passwordrrrr �ssh_name�	decryptedrrr�iqmprrr�padded�builds                 r2�_import_openssh_private_rsar+�s@��C�C�C�C�C�C�C�C�C�C�C�C�9�8��x�H�H��H�i��9����2�3�3�3��:�i�(�(�L�A�y��:�i�(�(�L�A�y��:�i�(�(�L�A�y� �j��+�+�O�D�)��:�i�(�(�L�A�y��:�i�(�(�L�A�y���I�&�&�I�A�v��M�&����B�B�Q��1�a��D�,A�B�B�B�E��U���r4c�"�ddlm}t|��}|�t|��}|�d��r;t	|��}|�||��\}}}t
||��}|S|�d��r;|�t	|��|��\}}}|rd}t||��S|�d��r�tj	|�
d��d��}	g}
t|	��d	krctj
d
|	dd	���d}|
�|	d	d	|z���|	d	|zd�}	t|	��d	k�ctj|
d��}tj|
d��}
t#|
|g��St|��dkr)t%|d��dkrt||��St'd
���)a�Import an RSA key (public or private).

    Args:
      extern_key (string or byte string):
        The RSA key to import.

        The following formats are supported for an RSA **public key**:

        - X.509 certificate (binary or PEM format)
        - X.509 ``subjectPublicKeyInfo`` DER SEQUENCE (binary or PEM
          encoding)
        - `PKCS#1`_ ``RSAPublicKey`` DER SEQUENCE (binary or PEM encoding)
        - An OpenSSH line (e.g. the content of ``~/.ssh/id_ecdsa``, ASCII)

        The following formats are supported for an RSA **private key**:

        - PKCS#1 ``RSAPrivateKey`` DER SEQUENCE (binary or PEM encoding)
        - `PKCS#8`_ ``PrivateKeyInfo`` or ``EncryptedPrivateKeyInfo``
          DER SEQUENCE (binary or PEM encoding)
        - OpenSSH (text format, introduced in `OpenSSH 6.5`_)

        For details about the PEM encoding, see `RFC1421`_/`RFC1423`_.

      passphrase (string or byte string):
        For private keys only, the pass phrase that encrypts the key.

    Returns: An RSA key object (:class:`RsaKey`).

    Raises:
      ValueError/IndexError/TypeError:
        When the given key cannot be parsed (possibly because the pass
        phrase is wrong).

    .. _RFC1421: http://www.ietf.org/rfc/rfc1421.txt
    .. _RFC1423: http://www.ietf.org/rfc/rfc1423.txt
    .. _`PKCS#1`: http://www.ietf.org/rfc/rfc3447.txt
    .. _`PKCS#8`: http://www.ietf.org/rfc/rfc5208.txt
    .. _`OpenSSH 6.5`: https://flak.tedunangst.com/post/new-openssh-key-format-and-bcrypt-pbkdf
    rr�Ns-----BEGIN OPENSSH PRIVATE KEYs-----r�� rrr�r��0r)r�r�r	�
startswithrrr+rr��
a2b_base64�splitr�r��unpack�appendrr"rr
r")rr�r��text_encoded�openssh_encoded�marker�enc_flagrerr�r��lengthrrs              r2rr�s��R��������$�$�J����Z�(�(�
����>�?�?���Z�(�(��,/�J�J�|�Z�,P�,P�)����,�_�j�I�I���
����X�&�&�/�"%�*�*�U�:�->�->�
�"K�"K���f�h��	��J��c�:�.�.�.����[�)�)�
!��'�
�(8�(8��(>�(>�q�(A�B�B�	����)�n�n�q� � ��]�4��2�A�2��7�7��:�F��O�O�I�a��F�
�l�3�4�4�4�!�!�f�*�+�+�.�I��)�n�n�q� � �
��x��{�+�+����x��{�+�+���!�Q�� � � �
�:������t�J�q�M�2�2�d�:�:��j�*�5�5�5�
�6�
7�
7�7r4z1.2.840.113549.1.1.1)Nr�)Tr6)$�__all__r�r��Cryptor�Crypto.Util.py3compatr	r
r�Crypto.Util.asn1rr
�Crypto.Math.Numbersr�Crypto.Math.Primalityrrr�Crypto.PublicKeyrrrr�rrrrr
rrrrr+r�	importKeyrrkr4r2�<module>rAs���@��������
�
�
�
�������6�6�6�6�6�6�6�6�6�6�1�1�1�1�1�1�1�1�'�'�'�'�'�'�G�G�G�G�G�G�G�G�G�G�@�@�@�@�@�@�@�@�@�@�
v"�v"�v"�v"�v"�V�v"�v"�v"�rN0�N0�N0�N0�bL�L�L�L�^C�C�C�(���-�-�-�1�1�1�,�,�,�8�8�8�$���0L8�L8�L8�L8�`
�	����r4