o
    Òó·i…  ã                   @   s‚   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
„ 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                   @   s¶   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d„Zdd	„ Zd
d„ Zdd„ Zdeeeeeeef  f  fdd„Zdedeeef fdd„Zdd„ ZdS )Ú
SSHFactoryz$
    A Factory for SSH servers.
    Úprimes)ó   ssh-userauths   ssh-connectionÚreturnNc                 C   sZ   t | dƒs
|  ¡ | _t | dƒs|  ¡ | _| jr| jst 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   Z
ConchErrorÚ	getPrimesr   ©Úself© r   ú_C:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/conch/ssh/factory.pyÚstartFactory&   s   





ÿzSSHFactory.startFactoryc                 C   sV   t j | |¡}tt dd„ | j ¡ D ƒ¡ƒ|_| j	s)| j
 d¡ 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                 s   s   � | ]}|  ¡ V  qd S ©N)ZsupportedSignatureAlgorithms)Ú.0Úkeyr   r   r   Ú	<genexpr>?   s   € 
ÿz+SSHFactory.buildProtocol.<locals>.<genexpr>zTdisabling non-fixed-group key exchange algorithms because we cannot find moduli filec                 S   s$   g | ]}t  |¡st  |¡r|‘qS r   )r   ZisFixedGroupZisEllipticCurve)r   ZkexAlgorithmr   r   r   Ú
<listcomp>H   s    ýýÿz,SSHFactory.buildProtocol.<locals>.<listcomp>N)r   ÚFactoryÚbuildProtocolÚlistr   Úfrom_iterabler   ÚvaluesZsupportedPublicKeysr   Ú_logÚinfoZsupportedKeyExchanges)r   ÚaddrÚtr   r   r   r#   3   s   

ÿÿÿþzSSHFactory.buildProtocolc                 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 unimplementedN©ÚNotImplementedErrorr   r   r   r   r   O   ó   zSSHFactory.getPublicKeysc                 C   r+   )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 unimplementedNr,   r   r   r   r   r   Y   r.   zSSHFactory.getPrivateKeysc                 C   s   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   r   r   r   r   c   s    zSSHFactory.getPrimesÚbitsc                    sR   dt dt f‡ fdd„}| jdusJ dƒ‚t| j ¡ |d�}|d }t | 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                    s   t | ˆ  ƒS r   )Úabs)r0   ©r/   r   r   Úkeyfuncp   s   z&SSHFactory.getDHPrime.<locals>.keyfuncNz(Factory should have been started by now.)r   r   )Úintr   ÚsortedÚkeysÚrandomÚchoice)r   r/   r3   Z
primesKeysZrealBitsr   r2   r   Ú
getDHPrimej   s
   zSSHFactory.getDHPrimec                 C   s    |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   ZavatarN)r   Úservices)r   r
   Zservicer   r   r   Ú
getServicex   s   
ÿzSSHFactory.getService)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r4   r   r   Ú__annotations__r   r'   r
   ZSSHServerTransportr   r   ZSSHUserAuthServerr	   ZSSHConnectionr:   r   r#   r   r   r   r9   r;   r   r   r   r   r      s   
  þ

&
r   )r?   r7   Ú	itertoolsr   Útypingr   r   r   r   Ztwisted.conchr   Ztwisted.conch.sshr   r	   r
   r   Ztwisted.internetr   Ztwisted.loggerr   r"   r   r   r   r   r   Ú<module>   s   	