
    Vh                         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y)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y)
SSHFactoryz$
    A Factory for SSH servers.
    primes)   ssh-userauths   ssh-connectionreturnNc                 &   t        | d      s| j                         | _        t        | d      s| j                         | _        | j                  r| j                  st        j                  d      t        | d      s| j                         | _        yy)z4
        Check for public and private keys.
        
publicKeysprivateKeyszno host keys, failingr   N)	hasattrgetPublicKeysr   getPrivateKeysr   r   
ConchError	getPrimesr   selfs    I/home/dcms/DCMS/lib/python3.12/site-packages/twisted/conch/ssh/factory.pystartFactoryzSSHFactory.startFactory&   sw     t\*"002DOt]+#224Dd&6&6""#:;;tX&..*DK '    c                    t         j                  j                  | |      }t        t	        j
                  d | j                  j                         D                    |_        | j                  sd| j                  j                  d       |j                  D cg c].  }t        j                  |      st        j                  |      r|0 c}|_        |S c c}w )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   | ]  }|j                           y wN)supportedSignatureAlgorithms).0keys     r   	<genexpr>z+SSHFactory.buildProtocol.<locals>.<genexpr>?   s       7:002 s   zTdisabling non-fixed-group key exchange algorithms because we cannot find moduli file)r   FactorybuildProtocollistr   from_iterabler   valuessupportedPublicKeysr   _loginfosupportedKeyExchangesr	   isFixedGroupisEllipticCurve)r   addrtkexAlgorithms       r   r)   zSSHFactory.buildProtocol3   s     **46 $  >B>N>N>U>U>W  !

 {{IINN5 %&$;$;' $$\2d6J6J<6X 'A#
 's   3C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 unimplementedr7   r   s    r   r   zSSHFactory.getPrivateKeysY   s     ""@AAr    c                      y)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).
        N r   s    r   r   zSSHFactory.getPrimesc   s    r    bitsc                     dt         dt         ffd}| j                  J d       t        | j                  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    z(Factory should have been started by now.)r&   r   )intr   sortedkeysrandomchoice)r   r<   rA   
primesKeysrealBitss    `   r   
getDHPrimezSSHFactory.getDHPrimej   sh    	!s 	!s 	! {{&R(RR&DKK,,.G<
a=}}T[[233r    c                 D    |dk(  st        |d      r| j                  |   S y)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   s*     o%H)E==)) *Fr    )r   N)__name__
__module____qualname____doc__r   r   rB   r   r   __annotations__r   r.   r   SSHServerTransportr   r   SSHUserAuthServerr
   SSHConnectionrL   r   r)   r   r   r   rI   rN   r;   r    r   r   r      s     T#tE#s(O445668D++H "33%33H
+8AB8Dd5c?.C)C$DE 4s 4uS#X 4	*r    r   )rR   rE   	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 % !j*!! j*r    