
    Mh_                        d Z ddlZddlmZ ddlmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ  edd	      \  ZZZZZ ed
d      \  ZZ edd	      D  cg c]
  }  e|        c} \  ZZZZZ ed
d      D  cg c]
  }  e|        c} \  ZZ G d d      Z  G d de       Z! G d d      Z" G d d      Z#yc c} w c c} w )a  
This module provides GSS-API / SSPI Key Exchange as defined in :rfc:`4462`.

.. note:: Credential delegation is not supported in server mode.

.. note::
    `RFC 4462 Section 2.2
    <https://tools.ietf.org/html/rfc4462.html#section-2.2>`_ says we are not
    required to implement GSS-API error messages. Thus, in many methods within
    this module, if an error occurs an exception will be thrown and the
    connection will be terminated.

.. seealso:: :doc:`/api/ssh_gss`

.. versionadded:: 1.15
    N)sha1)DEBUGmax_byte	zero_bytebyte_chr	byte_maskbyte_ord)util)Message)SSHException   #   (   *   c                   x    e Zd ZdZdZdZ ed      edz  z   Ze	dz  Z
dZd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zy)KexGSSGroup1z
    GSS-API / SSPI Authenticated Diffie-Hellman Key Exchange as defined in `RFC
    4462 Section 2 <https://tools.ietf.org/html/rfc4462.html#section-2>`_
    lE   8{3If?E yZ3V58noPe?a-tBLy3W[<p6m5P&aF!33*w& ARM;L}.c|&A@h\&&#-Dvd             z(gss-group1-sha1-toWM5Slw5Ew8Mqkay+al2g==c                     || _         | j                   j                  | _        d | _        d| _        d| _        d| _        y )Nr   )	transportkexgss_ctxtkexgssgss_hostxefselfr   s     h/var/www/pru.catia.catastroantioquia-mas.com/valormasv2/lib/python3.12/site-packages/paramiko/kex_gss.py__init__zKexGSSGroup1.__init__Y   s6    "nn00    c                    | j                          | j                  j                  rPt        | j                  | j
                  | j                        | _        | j                  j                  t               yt        | j                  | j
                  | j                        | _
        | j                  j                  | _        t               }|j                  t               |j                  | j                   j#                  | j                               |j%                  | j                         | j                  j'                  |       | j                  j                  t(        t*        t,        t.               y)zU
        Start the GSS-API / SSPI Authenticated Diffie-Hellman Key Exchange.
        Ntarget)_generate_xr   server_modepowGr   Pr   _expect_packetMSG_KEXGSS_INITr   r   r   add_bytec_MSG_KEXGSS_INIT
add_stringr   ssh_init_sec_context	add_mpint_send_messageMSG_KEXGSS_HOSTKEYMSG_KEXGSS_CONTINUEMSG_KEXGSS_COMPLETEMSG_KEXGSS_ERRORr    ms     r!   	start_kexzKexGSSGroup1.start_kexa   s     	>>%%0DFNN))/:TVVTVVTVV,//I	

$%	T[[55T]]5KL	DFF$$Q'%%		
r#   c                    | j                   j                  r|t        k(  r| j                  |      S | j                   j                  s|t        k(  r| j                  |      S | j                   j                  r|t        k(  r| j                  |      S | j                   j                  s|t        k(  r| j                  |      S |t        k(  r| j                  |      S d}t        |j                  |            )
        Parse the next packet.

        :param ptype: The (string) type of the incoming packet
        :param `.Message` m: The packet content
        z.GSS KexGroup1 asked to handle packet type {:d})r   r(   r-   _parse_kexgss_initr4   _parse_kexgss_hostkeyr5   _parse_kexgss_continuer6   _parse_kexgss_completer7   _parse_kexgss_errorr   formatr    ptyper9   msgs       r!   
parse_nextzKexGSSGroup1.parse_next{   s     >>%%5O+C**1--++:L1L--a00^^''U6I-I..q11++:M1M..q11&&++A..>3::e,--r#   c                     	 t        j                  d      }t        |d   d      |dd z   }|dd }|| j                  | j                  fvrnKt        j                  |      | _        y)ap  
        generate an "x" (1 < x < q), where q is (p-1)/2.
        p is a 128-byte (1024-bit) number, where the first 64 bits are 1.
        therefore q can be approximated as a 2^1023.  we drop the subset of
        potential x where the first 63 bits are 1, because some of those will
        be larger than q (but this is a tiny tiny subset of potential x).
              r   r   Nr   )osurandomr   b7fffffffffffffffb0000000000000000r
   inflate_longr   )r    x_bytesfirsts      r!   r'   zKexGSSGroup1._generate_x   so     jjoG
D1GABK?GBQKET33T5K5KLL  ""7+r#   c                     |j                         }|| j                  _        |j                         }| j                  j                  ||       | j                  j	                  t
        t               y)z
        Parse the SSH2_MSG_KEXGSS_HOSTKEY message (client mode).

        :param `.Message` m: The content of the SSH2_MSG_KEXGSS_HOSTKEY message
        N
get_stringr   host_key_verify_keyr,   r5   r6   r    r9   rT   sigs       r!   r>   z"KexGSSGroup1._parse_kexgss_hostkey   P     <<>"*lln""8S1%%&9;NOr#   c                    | j                   j                  s|j                         }t               }|j	                  t
               |j                  | j                  j                  | j                  |             | j                   j                  |       | j                   j                  t        t        t               yy)z
        Parse the SSH2_MSG_KEXGSS_CONTINUE message.

        :param `.Message` m: The content of the SSH2_MSG_KEXGSS_CONTINUE
            message
        r&   
recv_tokenNr   r(   rS   r   r.   c_MSG_KEXGSS_CONTINUEr0   r   r1   r   send_messager,   r5   r6   r7   r    r9   	srv_tokens      r!   r?   z#KexGSSGroup1._parse_kexgss_continue   s     ~~))I	AJJ,-LL00==Y 1 
 NN''*NN))#%8:J r#   c                    | j                   j                  t               | j                   _        |j                         | _        | j                  dk  s| j                  | j
                  dz
  kD  rt        d      |j                         }|j                         }d}|r|j                         }t        | j                  | j                  | j
                        }t               }|j                  | j                   j                  | j                   j                  | j                   j                  | j                   j                          |j#                  | j                   j                  j%                                |j'                  | j(                         |j'                  | j                         |j'                  |       t+        t-        |            j/                         }| j                   j1                  ||       |D| j2                  j5                  | j6                  |       | j2                  j9                  ||       n| j2                  j9                  ||       d| j                   _        | j                   j=                          y)z
        Parse the SSH2_MSG_KEXGSS_COMPLETE message (client mode).

        :param `.Message` m: The content of the
            SSH2_MSG_KEXGSS_COMPLETE message
        NrH   Server kex "f" is out of rangerZ   T)r   rT   NullHostKey	get_mpintr   r+   r   rS   get_booleanr)   r   r   addlocal_versionremote_versionlocal_kex_initremote_kex_initr0   __str__r2   r   r   strdigest_set_K_Hr   r1   r   ssh_check_micgss_kex_used_activate_outboundr    r9   	mic_tokenboolr`   KhmHs           r!   r@   z#KexGSSGroup1._parse_kexgss_complete   s    >>""*&1mDNN#FFQJDFFTVVaZ/?@@LLN	}}	I' Y
NN((NN))NN))NN**		
 	dnn--5578
TVV
TVV
QRM  "1% KK,,}} -  KK%%i3KK%%i3&*#))+r#   c                    |j                         }|j                         | _        | j                  dk  s| j                  | j                  dz
  kD  rt	        d      t        | j                  | j                  | j                        }t               | j                  _	        | j                  j                  j                         }t               }|j                  | j                  j                  | j                  j                  | j                  j                  | j                  j                          |j#                  |       |j%                  | j                         |j%                  | j&                         |j%                  |       t)        |j+                               j-                         }| j                  j/                  ||       | j0                  j3                  | j4                  |      }t               }| j0                  j6                  r| j0                  j9                  | j                  j:                  d      }|j=                  t>               |j%                  | j&                         |j#                  |       |#|jA                  d       |j#                  |       n|jA                  d       | j                  jC                  |       d| j                  _"        | j                  jG                          y|j=                  tH               |j#                  |       | j                  jC                  |       | j                  jK                  tL        tN        tP               y)z
        Parse the SSH2_MSG_KEXGSS_INIT message (server mode).

        :param `.Message` m: The content of the SSH2_MSG_KEXGSS_INIT message
        rH   Client kex "e" is out of rangeTgss_kexNF))rS   rd   r   r+   r   r)   r   rc   r   rT   rk   r   rf   rh   rg   rj   ri   r0   r2   r   r   asbytesrm   rn   r   ssh_accept_sec_contextr   _gss_srv_ctxt_statusssh_get_mic
session_idr.   c_MSG_KEXGSS_COMPLETEadd_booleanr3   rp   rq   r]   r,   r5   r6   r7   	r    r9   client_tokenru   keyrv   rw   r`   rs   s	            r!   r=   zKexGSSGroup1._parse_kexgss_init   sY    ||~FFQJDFFTVVaZ/?@@'"--nn%%--/ Y
NN))NN((NN**NN))		
 	c
TVV
TVV
Q%%'1%KK66MM<
	 I;;++//))4 0 I JJ,-KKLL#$d#Y'e$NN((+*.DNN'NN--/JJ,-LL#NN((+NN))#%8:Jr#   c                     |j                         }|j                         }|j                         }|j                          t        dj                  |||            )a  
        Parse the SSH2_MSG_KEXGSS_ERROR message (client mode).
        The server may send a GSS-API error message. if it does, we display
        the error by throwing an exception (client mode).

        :param `.Message` m: The content of the SSH2_MSG_KEXGSS_ERROR message
        :raise SSHException: Contains GSS-API major and minor status as well as
                             the error message and the language tag of the
                             message
        CGSS-API Error:
Major Status: {}
Minor Status: {}
Error Message: {}
get_intrS   r   rB   r    r9   
maj_status
min_statuserr_msgs        r!   rA   z KexGSSGroup1._parse_kexgss_error*  S     YY[
YY[
,,.	 FJ
 	
r#   N)__name__
__module____qualname____doc__r+   r*   r   r   rL   r   rM   NAMEr"   r:   rF   r'   r>   r?   r@   r=   rA    r#   r!   r   r   L   sf     	KA	A A5!A5D
4.,, P.+,Z6p
r#   r   c                       e Zd ZdZdZdZdZy)KexGSSGroup14z
    GSS-API / SSPI Authenticated Diffie-Hellman Group14 Key Exchange as defined
    in `RFC 4462 Section 2
    <https://tools.ietf.org/html/rfc4462.html#section-2>`_
    l   &UG9
tcb0]Q\-:$90.`U_b;YS7x]Ek`:xds!,w<G8qbdR_hddY6KpRT{UjK#Gt|L4S8 FYpw,(.> =HG2Cdc_.K?&j_c}z[\V_1M.D^/1v5I	jV&|/mVlR<6#{n4(EY91T:g8	H	Apcb4BBj~H r   z)gss-group14-sha1-toWM5Slw5Ew8Mqkay+al2g==N)r   r   r   r   r+   r*   r   r   r#   r!   r   r   D  s     	KA	A6Dr#   r   c                   b    e Zd ZdZdZdZdZdZd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zy)	KexGSSGexz
    GSS-API / SSPI Authenticated Diffie-Hellman Group Exchange as defined in
    `RFC 4462 Section 2 <https://tools.ietf.org/html/rfc4462.html#section-2>`_
    z%gss-gex-sha1-toWM5Slw5Ew8Mqkay+al2g==       i   c                     || _         | j                   j                  | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _	        d| _
        y )NF)r   r   r   r   pqgr   r   r   	old_styler   s     r!   r"   zKexGSSGex.__init__[  sR    "nn00r#   c                    | j                   j                  r | j                   j                  t               y| j                   j                  | _        t               }|j                  t               |j                  | j                         |j                  | j                         |j                  | j                         | j                   j                  |       | j                   j                  t               y)zV
        Start the GSS-API / SSPI Authenticated Diffie-Hellman Group Exchange
        N)r   r(   r,   MSG_KEXGSS_GROUPREQr   r   r.   c_MSG_KEXGSS_GROUPREQadd_intmin_bitspreferred_bitsmax_bitsr3   MSG_KEXGSS_GROUPr8   s     r!   r:   zKexGSSGex.start_kexg  s     >>%%NN))*=> //I	

()			$-- 			$%%&			$-- $$Q'%%&67r#   c                    |t         k(  r| j                  |      S |t        k(  r| j                  |      S |t        k(  r| j                  |      S |t        k(  r| j                  |      S |t        k(  r| j                  |      S |t        k(  r| j                  |      S |t        k(  r| j                  |      S d}t        |j                  |            )r<   z'KexGex asked to handle packet type {:d})r   _parse_kexgss_groupreqr   _parse_kexgss_groupr-   _parse_kexgss_gex_initr4   r>   r5   r?   r6   r@   r7   rA   r   rB   rC   s       r!   rF   zKexGSSGex.parse_nextz  s     ''..q11&&++A..o%..q11((--a00))..q11))..q11&&++A..73::e,--r#   c                 \   | j                   dz
  dz  }t        j                  |d      }t        |d         }t	        |      }d}|dz  s|dz  }|dz  }|dz  s	 t        j                  |      }t        |d   |      |dd  z   }t        j                  |d      }|dkD  r||k  r		 || _	        y T)NrH   r   r      rI   )
r   r
   deflate_longr	   lenrJ   rK   r   rN   r   )r    r   qnormqhbyte
byte_countqmaskrO   r   s           r!   r'   zKexGSSGex._generate_x  s    VVaZA!!!Q'%(#Z
D=qLFaKE D= jj,G
E2WQR[@G!!'1-AAAE r#   c                 $   |j                         }|j                         }|j                         }|| j                  kD  r| j                  }|| j                  k  r| j                  }||kD  r|}||k  r|}|| _        || _        || _        | j                  j                         }|t        d      | j                  j                  t        dj                  |||             |j                  |||      \  | _        | _        t               }|j                  t               |j!                  | j                         |j!                  | j                         | j                  j#                  |       | j                  j%                  t&               y)z
        Parse the SSH2_MSG_KEXGSS_GROUPREQ message (server mode).

        :param `.Message` m: The content of the
            SSH2_MSG_KEXGSS_GROUPREQ message
        Nz-Can't do server-side gex with no modulus packzPicking p ({} <= {} <= {} bits))r   r   r   r   r   _get_modulus_packr   _logr   rB   get_modulusr   r   r   r.   c_MSG_KEXGSS_GROUPr2   r3   r,   r-   )r    r9   minbitspreferredbitsmaxbitspacks         r!   r   z KexGSSGex._parse_kexgss_groupreq  sD    ))+		))+4==( MMM4==( MMM ]"#G]"#G+~~//1<NOO-44	
 ))'='JI	

%&	DFF	DFF$$Q'%%o6r#   c                 ,   |j                         | _        |j                         | _        t        j                  | j                        }|dk  s|dkD  rt        dj                  |            | j                  j                  t        dj                  |             | j                          t        | j                  | j                  | j                        | _        t               }|j                  t                |j#                  | j$                  j'                  | j(                               |j+                  | j                         | j                  j-                  |       | j                  j/                  t0        t2        t4        t6               y)z
        Parse the SSH2_MSG_KEXGSS_GROUP message (client mode).

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_GROUP message
        r   r   z<Server-generated gex p (don't ask) is out of range ({} bits)zGot server p ({} bits)r%   N)rd   r   r   r
   
bit_lengthr   rB   r   r   r   r'   r)   r   r   r   r.   r/   r0   r   r1   r   r2   r3   r,   r4   r5   r6   r7   )r    r9   bitlens      r!   r   zKexGSSGex._parse_kexgss_group  s    (TMv}"F6N  	+226:	
 	TVVTVVTVV,I	

$%	T[[55T]]5KL	DFF$$Q'%%		
r#   c                 H   |j                         }|j                         | _        | j                  dk  s| j                  | j                  dz
  kD  rt	        d      | j                          t        | j                  | j                  | j                        | _	        t        | j                  | j                  | j                        }t               | j                  _        | j                  j                  j                         }t               }|j                  | j                  j                   | j                  j"                  | j                  j$                  | j                  j&                  |       |j)                  | j*                         |j)                  | j,                         |j)                  | j.                         |j1                  | j                         |j1                  | j                         |j1                  | j                         |j1                  | j                         |j1                  |       t3        |j5                               j7                         }| j                  j9                  ||       | j:                  j=                  | j>                  |      }t               }| j:                  j@                  r| j:                  jC                  | j                  jD                  d      }|jG                  tH               |j1                  | j                         |jK                  |       |#|jM                  d       |jK                  |       n|jM                  d       | j                  jO                  |       d| j                  _(        | j                  jS                          y|jG                  tT               |jK                  |       | j                  jO                  |       | j                  jW                  tX        tZ        t\               y)z
        Parse the SSH2_MSG_KEXGSS_INIT message (server mode).

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_INIT message
        rH   ry   Trz   NF)/rS   rd   r   r   r   r'   r)   r   r   r   rc   r   rT   rk   r   rf   rh   rg   rj   ri   r   r   r   r   r2   r   r|   rm   rn   r   r}   r   r~   r   r   r.   r   r0   r   r3   rp   rq   r]   r,   r5   r6   r7   r   s	            r!   r   z KexGSSGex._parse_kexgss_gex_init  s    ||~FFQJDFFTVVaZ/?@@TVVTVVTVV,'"--nn%%--/ Y
NN))NN((NN**NN))	
 	

4==!


4&&'


4==!
TVV
TVV
TVV
TVV
Q%%'1%KK66MM<
	 I;;++//))4 0 I JJ,-KKLL#$d#Y'e$NN((+*.DNN'NN--/JJ,-LL#NN((+NN))#%8:Jr#   c                     |j                         }|| j                  _        |j                         }| j                  j                  ||       | j                  j	                  t
        t               y)z
        Parse the SSH2_MSG_KEXGSS_HOSTKEY message (client mode).

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_HOSTKEY message
        NrR   rV   s       r!   r>   zKexGSSGex._parse_kexgss_hostkey1  rX   r#   c                    | j                   j                  s|j                         }t               }|j	                  t
               |j                  | j                  j                  | j                  |             | j                   j                  |       | j                   j                  t        t        t               yy)z
        Parse the SSH2_MSG_KEXGSS_CONTINUE message.

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_CONTINUE message
        rZ   Nr\   r_   s      r!   r?   z KexGSSGex._parse_kexgss_continue>  s     ~~))I	AJJ,-LL00==Y 1 
 NN''*NN))#%8:J r#   c                 D   | j                   j                  t               | j                   _        |j                         | _        |j                         }|j                         }d}|r|j                         }| j                  dk  s| j                  | j                  dz
  kD  rt        d      t        | j                  | j                  | j                        }t               }|j                  | j                   j                  | j                   j                  | j                   j                  | j                   j                   | j                   j                  j#                                | j$                  s|j'                  | j(                         |j'                  | j*                         | j$                  s|j'                  | j,                         |j/                  | j                         |j/                  | j0                         |j/                  | j2                         |j/                  | j                         |j/                  |       t5        |j7                               j9                         }| j                   j;                  ||       |D| j<                  j?                  | j@                  |       | j<                  jC                  ||       n| j<                  jC                  ||       d| j                   _"        | j                   jG                          y)z
        Parse the SSH2_MSG_KEXGSS_COMPLETE message (client mode).

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_COMPLETE message
        NrH   rb   rZ   T)$r   rT   rc   rd   r   rS   re   r   r   r)   r   r   rf   rg   rh   ri   rj   rk   r   r   r   r   r   r2   r   r   r   r|   rm   rn   r   r1   r   ro   rp   rq   rr   s           r!   r@   z KexGSSGex._parse_kexgss_completeT  s!    >>""*&1mDNN#LLN	}}	IFFQJDFFTVVaZ/?@@' Y
NN((NN))NN))NN**NN##++-	
 ~~JJt}}%


4&&'~~JJt}}%
TVV
TVV
TVV
TVV
Q%%'1% KK,,}} -  KK%%i3KK%%i3&*#))+r#   c                     |j                         }|j                         }|j                         }|j                          t        dj                  |||            )a  
        Parse the SSH2_MSG_KEXGSS_ERROR message (client mode).
        The server may send a GSS-API error message. if it does, we display
        the error by throwing an exception (client mode).

        :param `Message` m:  The content of the SSH2_MSG_KEXGSS_ERROR message
        :raise SSHException: Contains GSS-API major and minor status as well as
                             the error message and the language tag of the
                             message
        r   r   r   s        r!   rA   zKexGSSGex._parse_kexgss_error  r   r#   N)r   r   r   r   r   r   r   r   r"   r:   rF   r'   r   r   r   r>   r?   r@   rA   r   r#   r!   r   r   P  sY    
 3DHHN
8&.4$*7X
B<|P,0,d
r#   r   c                   "    e Zd ZdZd Zd Zd Zy)rc   z
    This class represents the Null Host Key for GSS-API Key Exchange as defined
    in `RFC 4462 Section 5
    <https://tools.ietf.org/html/rfc4462.html#section-5>`_
    c                     d| _         y )N r   r    s    r!   r"   zNullHostKey.__init__  s	    r#   c                     | j                   S Nr   r   s    r!   rk   zNullHostKey.__str__      xxr#   c                     | j                   S r   r   r   s    r!   get_namezNullHostKey.get_name  r   r#   N)r   r   r   r   r"   rk   r   r   r#   r!   rc   rc     s    r#   rc   )$r   rJ   hashlibr   paramiko.commonr   r   r   r   r   r	   paramikor
   paramiko.messager   paramiko.ssh_exceptionr   ranger-   r5   r6   r4   r7   r   r   r/   r]   r   c_MSG_KEXGSS_HOSTKEYc_MSG_KEXGSS_ERRORr   r   r   r   r   rc   )cs   0r!   <module>r      s   ." 
    $ / 
"bM*/B- '&  B-(QXa[( r2/HQK/ +*
u
 u
p	7L 	7M
 M
`
 u )/s   B78B<