
    tf                         d Z ddlZddlmZ ddlmZmZmZmZ ddl	m
Z
 ddlmZmZmZmZ ddlmZ ddlmZ  G d	 d
ej                  ZdS )z
A Factory for SSH servers.

See also L{twisted.conch.openssh_compat.factory} for OpenSSH compatibility.

Maintainer: Paul Swartz
    N)chain)DictListOptionalTuple)error)_kex
connection	transportuserauth)protocol)Loggerc                      e Zd ZU dZeeeeeeef                  f                  e	d<    e
            Zej        Zej        ej        dZddZd Zd Zd	 Zdeeeeeeef                  f                  fd
Zdedeeef         fdZd ZdS )
SSHFactoryz$
    A Factory for SSH servers.
    primes)   ssh-userauths   ssh-connectionreturnNc                 D   t          | d          s|                                 | _        t          | d          s|                                 | _        | j        r| j        st          j        d          t          | d          s|                                 | _        dS dS )z4
        Check for public and private keys.
        
publicKeysprivateKeyszno host keys, failingr   N)	hasattrgetPublicKeysr   getPrivateKeysr   r   
ConchError	getPrimesr   selfs    X/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/conch/ssh/factory.pystartFactoryzSSHFactory.startFactory&   s     t\** 	3"0022DOt]++ 	5#2244D 	<d&6 	<"#:;;;tX&& 	+..**DKKK	+ 	+    c                 B   t           j                            | |          }t          t	          j        d | j                                        D                                 |_        | j	        s0| j
                            d           d |j        D             |_        |S )a=  
        Create an instance of the server side of the SSH protocol.

        @type addr: L{twisted.internet.interfaces.IAddress} provider
        @param addr: The address at which the server will listen.

        @rtype: L{twisted.conch.ssh.transport.SSHServerTransport}
        @return: The built transport.
        c              3   >   K   | ]}|                                 V  d S N)supportedSignatureAlgorithms).0keys     r   	<genexpr>z+SSHFactory.buildProtocol.<locals>.<genexpr>?   s?          7:0022           r    zTdisabling non-fixed-group key exchange algorithms because we cannot find moduli filec                 b    g | ],}t          j        |          st          j        |          *|-S  )r	   isFixedGroupisEllipticCurve)r%   kexAlgorithms     r   
<listcomp>z,SSHFactory.buildProtocol.<locals>.<listcomp>H   sN     ' ' ' $\22' 7;6J<6X6X'' ' 'r    )r   FactorybuildProtocollistr   from_iterabler   valuessupportedPublicKeysr   _loginfosupportedKeyExchanges)r   addrts      r   r/   zSSHFactory.buildProtocol3   s     **466 $    >B>N>U>U>W>W       !
 !

 { 		INN5  ' '$%$;' ' 'A#
 r    c                      t          d          )z
        Called when the factory is started to get the public portions of the
        servers host keys.  Returns a dictionary mapping SSH key types to
        public key strings.

        @rtype: L{dict}
        zgetPublicKeys unimplementedNotImplementedErrorr   s    r   r   zSSHFactory.getPublicKeysO   s     ""?@@@r    c                      t          d          )z
        Called when the factory is started to get the  private portions of the
        servers host keys.  Returns a dictionary mapping SSH key types to
        L{twisted.conch.ssh.keys.Key} objects.

        @rtype: L{dict}
        zgetPrivateKeys unimplementedr:   r   s    r   r   zSSHFactory.getPrivateKeysY   s     ""@AAAr    c                     dS )z
        Called when the factory is started to get Diffie-Hellman generators and
        primes to use.  Returns a dictionary mapping number of bits to lists of
        tuple of (generator, prime).
        Nr)   r   s    r   r   zSSHFactory.getPrimesc   s      r    bitsc                     dt           dt           ffd}| j        
J d            t          | j                                        |          }|d         }t	          j        | j        |                   S )z
        Return a tuple of (g, p) for a Diffe-Hellman process, with p being as
        close to C{bits} bits as possible.
        ir   c                 (    t          | z
            S r#   )abs)r@   r>   s    r   keyfuncz&SSHFactory.getDHPrime.<locals>.keyfuncp   s    q4x== r    Nz(Factory should have been started by now.)r&   r   )intr   sortedkeysrandomchoice)r   r>   rC   
primesKeysrealBitss    `   r   
getDHPrimezSSHFactory.getDHPrimej   s    	!s 	!s 	! 	! 	! 	! 	! 	! {&&(R&&&DK,,..G<<<
a=}T[2333r    c                 L    |dk    st          |d          r| j        |         S dS )z
        Return a class to use as a service for the given transport.

        @type transport:    L{transport.SSHServerTransport}
        @type service:      L{bytes}
        @rtype:             subclass of L{service.SSHService}
        r   avatarN)r   services)r   r   services      r   
getServicezSSHFactory.getServicex   s3     o%%H)E)E%=)) &%r    )r   N)__name__
__module____qualname____doc__r   r   rD   r   r   __annotations__r   r4   r   SSHServerTransportr   r   SSHUserAuthServerr
   SSHConnectionrN   r   r/   r   r   r   rK   rP   r)   r    r   r   r      s.          T#tE#s(O4456666688D+H "3%3 H
+ + + +  8A A AB B B8Dd5c?.C)C$DE    4s 4uS#X 4 4 4 4	* 	* 	* 	* 	*r    r   )rT   rG   	itertoolsr   typingr   r   r   r   twisted.conchr   twisted.conch.sshr	   r
   r   r   twisted.internetr   twisted.loggerr   r.   r   r)   r    r   <module>r_      s            . . . . . . . . . . . .       C C C C C C C C C C C C % % % % % % ! ! ! ! ! !j* j* j* j* j*! j* j* j* j* j*r    