
    7g,                     N   d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d d          Z	 G d	 d
e	          Z
 G d de	          Z G d de	          Z G d de          Z G d de          Z edddg          Z G d de          Z G d de          Z G d d          ZdS )z
Modern, adaptable authentication machinery.

Replaces certain parts of `.SSHClient`. For a concrete implementation, see the
``OpenSSHAuthStrategy`` class in `Fabric <https://fabfile.org>`_.
    )
namedtuple   )AgentKey)
get_logger)AuthenticationExceptionc                   *    e Zd ZdZd Zd Zd Zd ZdS )
AuthSourcez
    Some SSH authentication source, such as a password, private key, or agent.

    See subclasses in this module for concrete implementations.

    All implementations must accept at least a ``username`` (``str``) kwarg.
    c                     || _         d S Nusername)selfr   s     P/var/www/html/syslog/venv/lib/python3.11/site-packages/paramiko/auth_strategy.py__init__zAuthSource.__init__   s         c                     d |                                 D             }d                    |          }| j        j         d| dS )Nc                 "    g | ]\  }}| d |S )= ).0kvs      r   
<listcomp>z$AuthSource._repr.<locals>.<listcomp>   s&    999$!QA999r   z, ())itemsjoin	__class____name__)r   kwargspairsjoineds       r   _reprzAuthSource._repr   sL     :9&,,..9995!!.)55F5555r   c                 *    |                                  S r   )r#   r   s    r   __repr__zAuthSource.__repr__"   s    zz||r   c                     t           )z)
        Perform authentication.
        NotImplementedErrorr   	transports     r   authenticatezAuthSource.authenticate%   s
     "!r   N)r   
__module____qualname____doc__r   r#   r&   r,   r   r   r   r	   r	      sZ         ! ! !6 6 6  " " " " "r   r	   c                       e Zd ZdZd ZdS )NoneAuthzS
    Auth type "none", ie https://www.rfc-editor.org/rfc/rfc4252#section-5.2 .
    c                 6    |                     | j                  S r   )	auth_noner   r*   s     r   r,   zNoneAuth.authenticate1   s    ""4=111r   Nr   r-   r.   r/   r,   r   r   r   r1   r1   ,   s-         2 2 2 2 2r   r1   c                   2     e Zd ZdZ fdZ fdZd Z xZS )Passworda  
    Password authentication.

    :param callable password_getter:
        A lazy callable that should return a `str` password value at
        authentication time, such as a `functools.partial` wrapping
        `getpass.getpass`, an API call to a secrets store, or similar.

        If you already know the password at instantiation time, you should
        simply use something like ``lambda: "my literal"`` (for a literal, but
        also, shame on you!) or ``lambda: variable_name`` (for something stored
        in a variable).
    c                 Z    t                                          |           || _        d S Nr   )superr   password_getter)r   r   r:   r   s      r   r   zPassword.__init__D   s,    (+++.r   c                 R    t                                          | j                  S )N)user)r9   r#   r   )r   r   s    r   r&   zPassword.__repr__H   s     ww}}$-}000r   c                 `    |                                  }|                    | j        |          S r   )r:   auth_passwordr   )r   r+   passwords      r   r,   zPassword.authenticateM   s-     ''))&&t}h???r   )r   r-   r.   r/   r   r&   r,   __classcell__r   s   @r   r6   r6   5   sq         / / / / /1 1 1 1 1
@ @ @ @ @ @ @r   r6   c                       e Zd ZdZd ZdS )
PrivateKeya  
    Essentially a mixin for private keys.

    Knows how to auth, but leaves key material discovery/loading/decryption to
    subclasses.

    Subclasses **must** ensure that they've set ``self.pkey`` to a decrypted
    `.PKey` instance before calling ``super().authenticate``; typically
    either in their ``__init__``, or in an overridden ``authenticate`` prior to
    its `super` call.
    c                 B    |                     | j        | j                  S r   )auth_publickeyr   pkeyr*   s     r   r,   zPrivateKey.authenticatee   s    ''tyAAAr   Nr4   r   r   r   rC   rC   X   s2        
 
B B B B Br   rC   c                   ,     e Zd ZdZ fdZ fdZ xZS )InMemoryPrivateKeyz1
    An in-memory, decrypted `.PKey` object.
    c                 Z    t                                          |           || _        d S r8   )r9   r   rF   )r   r   rF   r   s      r   r   zInMemoryPrivateKey.__init__n   s)    (+++			r   c                     t                                          | j                  }t          | j        t                    r|dz  }|S )N)rF   z [agent])r9   r#   rF   
isinstancer   )r   repr   s     r   r&   zInMemoryPrivateKey.__repr__s   sA     ggmmm++di** 	:C
r   r   r-   r.   r/   r   r&   r@   rA   s   @r   rH   rH   i   s[             
        r   rH   c                   (     e Zd ZdZ fdZd Z xZS )OnDiskPrivateKeya  
    Some on-disk private key that needs opening and possibly decrypting.

    :param str source:
        String tracking where this key's path was specified; should be one of
        ``"ssh-config"``, ``"python-config"``, or ``"implicit-home"``.
    :param Path path:
        The filesystem path this key was loaded from.
    :param PKey pkey:
        The `PKey` object this auth source uses/represents.
    c                     t                                          |           || _        d}||vrt          d|          || _        || _        d S )Nr   )z
ssh-configzpython-configzimplicit-homez source argument must be one of: )r9   r   source
ValueErrorpathrF   )r   r   rQ   rS   rF   allowedr   s         r   r   zOnDiskPrivateKey.__init__   s^    (+++B  KKKLLL				r   c                 j    |                      | j        | j        t          | j                            S )N)keyrQ   rS   )r#   rF   rQ   strrS   r%   s    r   r&   zOnDiskPrivateKey.__repr__   s0    zz	$+C	NN  
 
 	
r   rM   rA   s   @r   rO   rO   |   sQ        
 
    
 
 
 
 
 
 
r   rO   SourceResultrQ   resultc                   (     e Zd ZdZ fdZd Z xZS )
AuthResulta  
    Represents a partial or complete SSH authentication attempt.

    This class conceptually extends `AuthStrategy` by pairing the former's
    authentication **sources** with the **results** of trying to authenticate
    with them.

    `AuthResult` is a (subclass of) `list` of `namedtuple`, which are of the
    form ``namedtuple('SourceResult', 'source', 'result')`` (where the
    ``source`` member is an `AuthSource` and the ``result`` member is either a
    return value from the relevant `.Transport` method, or an exception
    object).

    .. note::
        Transport auth method results are always themselves a ``list`` of "next
        allowable authentication methods".

        In the simple case of "you just authenticated successfully", it's an
        empty list; if your auth was rejected but you're allowed to try again,
        it will be a list of string method names like ``pubkey`` or
        ``password``.

        The ``__str__`` of this class represents the empty-list scenario as the
        word ``success``, which should make reading the result of an
        authentication session more obvious to humans.

    Instances also have a `strategy` attribute referencing the `AuthStrategy`
    which was attempted.
    c                 H    || _          t                      j        |i | d S r   )strategyr9   r   )r   r]   argsr    r   s       r   r   zAuthResult.__init__   s,     $)&)))))r   c                 @    d                     d | D                       S )N
c              3   <   K   | ]}|j          d |j        pd V  dS )z -> successN)rQ   rY   )r   xs     r   	<genexpr>z%AuthResult.__str__.<locals>.<genexpr>   sJ       
 
9:qx44QX244
 
 
 
 
 
r   )r   r%   s    r   __str__zAuthResult.__str__   s6    
 yy 
 
>B
 
 
 
 
 	
r   )r   r-   r.   r/   r   re   r@   rA   s   @r   r[   r[      sQ         <* * * * *
 
 
 
 
 
 
r   r[   c                       e Zd ZdZd Zd ZdS )AuthFailurea  
    Basic exception wrapping an `AuthResult` indicating overall auth failure.

    Note that `AuthFailure` descends from `AuthenticationException` but is
    generally "higher level"; the latter is now only raised by individual
    `AuthSource` attempts and should typically only be seen by users when
    encapsulated in this class. It subclasses `AuthenticationException`
    primarily for backwards compatibility reasons.
    c                     || _         d S r   rY   )r   rY   s     r   r   zAuthFailure.__init__   s    r   c                 0    dt          | j                  z   S )Nr`   )rW   rY   r%   s    r   re   zAuthFailure.__str__   s    c$+&&&&r   N)r   r-   r.   r/   r   re   r   r   r   rg   rg      s<           ' ' ' ' 'r   rg   c                   $    e Zd ZdZd Zd Zd ZdS )AuthStrategya   
    This class represents one or more attempts to auth with an SSH server.

    By default, subclasses must at least accept an ``ssh_config``
    (`.SSHConfig`) keyword argument, but may opt to accept more as needed for
    their particular strategy.
    c                 F    || _         t          t                    | _        d S r   )
ssh_configr   r   log)r   rn   s     r   r   zAuthStrategy.__init__   s     %h''r   c                     t           )a[  
        Generator yielding `AuthSource` instances, in the order to try.

        This is the primary override point for subclasses: you figure out what
        sources you need, and ``yield`` them.

        Subclasses _of_ subclasses may find themselves wanting to do things
        like filtering or discarding around a call to `super`.
        r(   r%   s    r   get_sourceszAuthStrategy.get_sources   s
     "!r   c                    d}t          |           }|                                 D ]}| j                            d|            	 |                    |          }d}nE# t
          $ r8}|}|j        j        }| j                            d| d|            Y d}~nd}~ww xY w|	                    t          ||                     |r n|st          |          |S )	z
        Handles attempting `AuthSource` instances yielded from `get_sources`.

        You *normally* won't need to override this, but it's an option for
        advanced users.
        F)r]   zTrying TzAuthentication via z failed with Nri   )r[   rq   ro   debugr,   	Exceptionr   r   infoappendrX   rg   )r   r+   	succeededoverall_resultrQ   rY   esource_classs           r   r,   zAuthStrategy.authenticate  s;    	#T222 &&(( 	 	FHNN-V--...,,Y77 		
      !{3M&MM|MM        !!,vv">">???   	5^4444s   A
B!).BB!N)r   r-   r.   r/   r   rq   r,   r   r   r   rl   rl      sK         ( ( (
" 
" 
"+ + + + +r   rl   N)r/   collectionsr   agentr   utilr   ssh_exceptionr   r	   r1   r6   rC   rH   rO   rX   listr[   rg   rl   r   r   r   <module>r      s    # " " " " "             2 2 2 2 2 2" " " " " " " ":2 2 2 2 2z 2 2 2@ @ @ @ @z @ @ @FB B B B B B B B"       &
 
 
 
 
z 
 
 
B z.8X*>??*
 *
 *
 *
 *
 *
 *
 *
\' ' ' ' ') ' ' '$G G G G G G G G G Gr   