Ë
    oj…  ã                   óš   — 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    ú;/usr/lib/python3/dist-packages/twisted/conch/ssh/factory.pyÚstartFactoryzSSHFactory.startFactory&   sw   € ô �t˜\Ô*Ø"×0Ñ0Ó2ˆDŒOÜ�t˜]Ô+Ø#×2Ñ2Ó4ˆDÔØ�Š d×&6Ò&6Ü×"Ñ"Ð#:Ó;Ð;Ü�t˜XÔ&ØŸ.™.Ó*ˆD�Kð 'ó    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ô ó ó!
ˆÔð
 �{Š{Ø�I‰I�N‰Nð5ôð %&×$;Ñ$;ö'à Ü×$Ñ$ \Ô2´d×6JÑ6JÈ<Ô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   ø€ Ü�q˜4‘x“=Ð 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Ð&Ü˜DŸK™K×,Ñ,Ó.°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˜#˜t E¨#¨s¨(¡OÑ4Ð4Ñ5Ñ6Ó6á‹8€DØ×+Ñ+€Hð "×3Ñ3Ø%×3Ñ3ñ€Hó
+òò8AòBð˜8 D¨¨d°5¸¸c¸±?Ñ.CÐ)CÑ$DÑEó ð4˜sð 4 u¨S°#¨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    