o
    >h                     @   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   
ConchError	getPrimesr   self r   y/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/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)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   isFixedGroupisEllipticCurve)r    kexAlgorithmr   r   r   
<listcomp>H   s    z,SSHFactory.buildProtocol.<locals>.<listcomp>)r   FactorybuildProtocollistr   from_iterabler   valuessupportedPublicKeysr   _loginfo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 unimplementedNotImplementedErrorr   r   r   r   r   O      zSSHFactory.getPublicKeysc                 C   r2   )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 unimplementedr3   r   r   r   r   r   Y   r5   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)r7   r6   r   r   keyfuncp   s   z&SSHFactory.getDHPrime.<locals>.keyfuncNz(Factory should have been started by now.)r!   r   )intr   sortedkeysrandomchoice)r   r6   r:   
primesKeysrealBitsr   r9   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   avatarN)r   services)r   r
   servicer   r   r   
getServicex   s   
zSSHFactory.getService)r   N)__name__
__module____qualname____doc__r   r   r;   r   r   __annotations__r   r-   r
   SSHServerTransportr   r   SSHUserAuthServerr	   SSHConnectionrD   r   r(   r   r   r   rB   rF   r   r   r   r   r      s   
  

&
r   )rJ   r>   	itertoolsr   typingr   r   r   r   twisted.conchr   twisted.conch.sshr   r	   r
   r   twisted.internetr   twisted.loggerr   r'   r   r   r   r   r   <module>   s   	