§
    Ètºfw!  ã            	       óL  — d Z ddlmZmZmZmZ ddlmZmZm	Z	 ddl
mZ  G d„ de¦  «        Z G d„ de¦  «        Z G d	„ d
e¦  «        Z G d„ de¦  «        Z e	e¦  «         G d„ d¦  «        ¦   «         Z e	e¦  «         G d„ d¦  «        ¦   «         Z e	e¦  «         G d„ d¦  «        ¦   «         Z e	e¦  «         G d„ d¦  «        ¦   «         Z e	e¦  «         G d„ d¦  «        ¦   «         Z e	e¦  «         G d„ d¦  «        ¦   «         Z e	e¦  «         G d„ d¦  «        ¦   «         Z e	e¦  «         G d„ d¦  «        ¦   «         Z e¦   «          e¦   «          e¦   «          e¦   «          e¦   «          e¦   «          e¦   «          e¦   «         dœZd„ Zd„ Zd „ Zd!„ Zd"„ Zd#„ Zd$S )%z
SSH key exchange handling.
é    )Úsha1Úsha256Úsha384Úsha512)Ú	AttributeÚ	InterfaceÚimplementer)Úerrorc                   ó>   — e Zd ZdZ ed¦  «        Z ed¦  «        ZdS )Ú_IKexAlgorithmzB
    An L{_IKexAlgorithm} describes a key exchange algorithm.
    z‹An L{int} giving the preference of the algorithm when negotiating key exchange. Algorithms with lower precedence values are more preferred.zqA callable hash algorithm constructor (e.g. C{hashlib.sha256}) suitable for use with this key exchange algorithm.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú
preferenceÚhashProcessor© ó    úU/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/conch/ssh/_kex.pyr   r      sH   € € € € € ðð ð �ð	ñô €Jð �Ið	=ñô €M€M€Mr   r   c                   ó>   — e Zd ZdZ ed¦  «        Z ed¦  «        ZdS )Ú_IFixedGroupKexAlgorithmzu
    An L{_IFixedGroupKexAlgorithm} describes a key exchange algorithm with a
    fixed prime / generator group.
    zdAn L{int} giving the prime number used in Diffie-Hellman key exchange, or L{None} if not applicable.z�An L{int} giving the generator number used in Diffie-Hellman key exchange, or L{None} if not applicable. (This is not related to Python generator functions.)N)r   r   r   r   r   ÚprimeÚ	generatorr   r   r   r   r   "   sH   € € € € € ðð ð
 ˆIð	2ñô €Eð
 �	ð	'ñô €I€I€Ir   r   c                   ó   — e Zd ZdZdS )Ú#_IEllipticCurveExchangeKexAlgorithmzž
    An L{_IEllipticCurveExchangeKexAlgorithm} describes a key exchange algorithm
    that uses an elliptic curve exchange between the client and server.
    N©r   r   r   r   r   r   r   r   r   4   s   € € € € € ðð ð ð r   r   c                   ó   — e Zd ZdZdS )Ú_IGroupExchangeKexAlgorithmzõ
    An L{_IGroupExchangeKexAlgorithm} describes a key exchange algorithm
    that uses group exchange between the client and server.

    A prime / generator group should be chosen at run time based on the
    requested size. See RFC 4419.
    Nr   r   r   r   r   r   ;   s   € € € € € ðð ð ð r   r   c                   ó   — e Zd ZdZdZeZdS )Ú_Curve25519SHA256z”
    Elliptic Curve Key Exchange using Curve25519 and SHA256. Defined in
    U{https://datatracker.ietf.org/doc/draft-ietf-curdle-ssh-curves/}.
    é   N©r   r   r   r   r   r   r   r   r   r   r    r    E   ó$   € € € € € ðð ð
 €JØ€M€M€Mr   r    c                   ó   — e Zd ZdZdZeZdS )Ú_Curve25519SHA256LibSSHzN
    As L{_Curve25519SHA256}, but with a pre-standardized algorithm name.
    é   Nr"   r   r   r   r%   r%   P   s$   € € € € € ðð ð €JØ€M€M€Mr   r%   c                   ó   — e Zd ZdZdZeZdS )Ú_ECDH256aX  
    Elliptic Curve Key Exchange with SHA-256 as HASH. Defined in
    RFC 5656.

    Note that C{ecdh-sha2-nistp256} takes priority over nistp384 or nistp512.
    This is the same priority from OpenSSH.

    C{ecdh-sha2-nistp256} is considered preety good cryptography.
    If you need something better consider using C{curve25519-sha256}.
    é   Nr"   r   r   r   r(   r(   Z   s$   € € € € € ð	ð 	ð €JØ€M€M€Mr   r(   c                   ó   — e Zd ZdZdZeZdS )Ú_ECDH384zT
    Elliptic Curve Key Exchange with SHA-384 as HASH. Defined in
    RFC 5656.
    é   N)r   r   r   r   r   r   r   r   r   r   r+   r+   k   r#   r   r+   c                   ó   — e Zd ZdZdZeZdS )Ú_ECDH512zT
    Elliptic Curve Key Exchange with SHA-512 as HASH. Defined in
    RFC 5656.
    é   N)r   r   r   r   r   r   r   r   r   r   r.   r.   v   r#   r   r.   c                   ó   — e Zd ZdZdZeZdS )Ú_DHGroupExchangeSHA256zc
    Diffie-Hellman Group and Key Exchange with SHA-256 as HASH. Defined in
    RFC 4419, 4.2.
    é   Nr"   r   r   r   r1   r1   �   r#   r   r1   c                   ó   — e Zd ZdZdZeZdS )Ú_DHGroupExchangeSHA1za
    Diffie-Hellman Group and Key Exchange with SHA-1 as HASH. Defined in
    RFC 4419, 4.1.
    é   N)r   r   r   r   r   r   r   r   r   r   r4   r4   Œ   s$   € € € € € ðð ð
 €JØ€M€M€Mr   r4   c                   ó4   — e Zd ZdZdZeZ ed¦  «        ZdZ	dS )Ú_DHGroup14SHA1z�
    Diffie-Hellman key exchange with SHA-1 as HASH and Oakley Group 14
    (2048-bit MODP Group). Defined in RFC 4253, 8.2.
    é   Ái  32317006071311007300338913926423828248817941241140239112842009751400741706634354222619689417363569347117901737909704191754605873209195028853758986185622153212175412514901774520270235796078236248884246189477587641105928646099411723245426622522193230540919037680524235519125679715870117001058055877651038861847280257976054903569732561526167081339361799541336476559160368317896729073178384589680639671900977202194168647225871031411336429319536193471636533209717077448227988588565369208645296636077250268955505928362751121174096972998068410554359584866583291642136218231078990999448652468262416972035911852507045361090559r&   N)
r   r   r   r   r   r   r   Úintr   r   r   r   r   r7   r7   —   sA   € € € € € ðð ð
 €JØ€MàˆCð
	ñô €Eð €I€I€Ir   r7   )ó   curve25519-sha256s   curve25519-sha256@libssh.orgs$   diffie-hellman-group-exchange-sha256s"   diffie-hellman-group-exchange-sha1s   diffie-hellman-group14-sha1s   ecdh-sha2-nistp256s   ecdh-sha2-nistp384s   ecdh-sha2-nistp521c                 ó\   — | t           vrt          j        d| › �¦  «        ‚t           |          S )aY  
    Get a description of a named key exchange algorithm.

    @param kexAlgorithm: The key exchange algorithm name.
    @type kexAlgorithm: L{bytes}

    @return: A description of the key exchange algorithm named by
        C{kexAlgorithm}.
    @rtype: L{_IKexAlgorithm}

    @raises ConchError: if the key exchange algorithm is not found.
    z$Unsupported key exchange algorithm: )Ú_kexAlgorithmsr
   Ú
ConchError©ÚkexAlgorithms    r   ÚgetKexrA   ¾   s4   € ð �>Ð)Ð)ÝÔÐTÀlÐTÐTÑUÔUÐUÝ˜,Ô'Ð'r   c                 óP   — t                                t          | ¦  «        ¦  «        S )a  
    Returns C{True} if C{kexAlgorithm} is an elliptic curve.

    @param kexAlgorithm: The key exchange algorithm name.
    @type kexAlgorithm: C{str}

    @return: C{True} if C{kexAlgorithm} is an elliptic curve,
        otherwise C{False}.
    @rtype: C{bool}
    )r   Ú
providedByrA   r?   s    r   ÚisEllipticCurverD   Ð   s    € õ /×9Ò9½&ÀÑ:NÔ:NÑOÔOÐOr   c                 óP   — t                                t          | ¦  «        ¦  «        S )a+  
    Returns C{True} if C{kexAlgorithm} has a fixed prime / generator group.

    @param kexAlgorithm: The key exchange algorithm name.
    @type kexAlgorithm: L{bytes}

    @return: C{True} if C{kexAlgorithm} has a fixed prime / generator group,
        otherwise C{False}.
    @rtype: L{bool}
    )r   rC   rA   r?   s    r   ÚisFixedGrouprF   Þ   s    € õ $×.Ò.­v°lÑ/CÔ/CÑDÔDÐDr   c                 ó.   — t          | ¦  «        }|j        S )a  
    Get the hash algorithm callable to use in key exchange.

    @param kexAlgorithm: The key exchange algorithm name.
    @type kexAlgorithm: L{bytes}

    @return: A callable hash algorithm constructor (e.g. C{hashlib.sha256}).
    @rtype: C{callable}
    )rA   r   ©r@   Úkexs     r   ÚgetHashProcessorrJ   ì   s   € õ �Ñ
Ô
€CØÔÐr   c                 ó<   — t          | ¦  «        }|j        |j        fS )zù
    Get the generator and the prime to use in key exchange.

    @param kexAlgorithm: The key exchange algorithm name.
    @type kexAlgorithm: L{bytes}

    @return: A L{tuple} containing L{int} generator and L{int} prime.
    @rtype: L{tuple}
    )rA   r   r   rH   s     r   ÚgetDHGeneratorAndPrimerL   ú   s    € õ �Ñ
Ô
€CØŒ=˜#œ)Ð#Ð#r   c                  óô  ‡— ddl m}  ddlm} ddlm}  | ¦   «         }t                               ¦   «         Št          ‰¦  «        D ]Ÿ}| 	                    d¦  «        rE| 
                    dd¦  «        }|                     |                     ¦   «         ||         ¦  «        }n,| 	                    d¦  «        r|                     ¦   «         }nd}|s‰                     |¦  «         Œ t          ‰ˆfd	„¬
¦  «        S )z½
    Get a list of supported key exchange algorithm names in order of
    preference.

    @return: A C{list} of supported key exchange algorithm names.
    @rtype: C{list} of L{bytes}
    r   )Údefault_backend)Úec)Ú_curveTables   ecdhs   ecdsar;   Tc                 ó   •— ‰|          j         S )N)r   )r@   ÚkexAlgorithmss    €r   ú<lambda>z*getSupportedKeyExchanges.<locals>.<lambda>$  s   ø€ °¸lÔ0KÔ0V€ r   )Úkey)Úcryptography.hazmat.backendsrN   Ú)cryptography.hazmat.primitives.asymmetricrO   Útwisted.conch.ssh.keysrP   r=   ÚcopyÚlistÚ
startswithÚreplaceÚ+elliptic_curve_exchange_algorithm_supportedÚECDHÚx25519_supportedÚpopÚsorted)rN   rO   rP   ÚbackendÚkeyAlgorithmÚkeyAlgorithmDsaÚ	supportedrR   s          @r   ÚgetSupportedKeyExchangesre     s8  ø€ ð =Ð<Ð<Ð<Ð<Ð<Ø<Ð<Ð<Ð<Ð<Ð<à2Ð2Ð2Ð2Ð2Ð2àˆoÑÔ€GÝ"×'Ò'Ñ)Ô)€MÝ˜]Ñ+Ô+ð ,ð ,ˆØ×"Ò" 7Ñ+Ô+ð 	Ø*×2Ò2°7¸HÑEÔEˆOØ×KÒKØ—’‘	”	˜; Ô7ñô ˆIˆIð ×$Ò$Ð%9Ñ:Ô:ð 	Ø×0Ò0Ñ2Ô2ˆIˆIàˆIØð 	,Ø×Ò˜lÑ+Ô+Ð+øÝØÐVÐVÐVÐVðñ ô ð r   N)r   Úhashlibr   r   r   r   Úzope.interfacer   r   r	   Útwisted.conchr
   r   r   r   r   r    r%   r(   r+   r.   r1   r4   r7   r=   rA   rD   rF   rJ   rL   re   r   r   r   ú<module>ri      sÛ  ðð
ð ð
 1Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0à <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <à Ð Ð Ð Ð Ð ðð ð ð ð �Yñ ô ð ð"ð ð ð ð ˜~ñ ô ð ð$ð ð ð ð ¨.ñ ô ð ðð ð ð ð  .ñ ô ð ð €Ð0Ñ1Ô1ðð ð ð ð ñ ô ñ 2Ô1ðð €Ð0Ñ1Ô1ðð ð ð ð ñ ô ñ 2Ô1ðð €Ð0Ñ1Ô1ðð ð ð ð ñ ô ñ 2Ô1ðð  €Ð0Ñ1Ô1ðð ð ð ð ñ ô ñ 2Ô1ðð €Ð0Ñ1Ô1ðð ð ð ð ñ ô ñ 2Ô1ðð €Ð(Ñ)Ô)ðð ð ð ð ñ ô ñ *Ô)ðð €Ð(Ñ)Ô)ðð ð ð ð ñ ô ñ *Ô)ðð €Ð%Ñ&Ô&ðð ð ð ð ñ ô ñ 'Ô&ðð6 ,Ð+Ñ-Ô-Ø%<Ð%<Ñ%>Ô%>Ø-CÐ-CÑ-EÔ-EØ+?Ð+?Ñ+AÔ+AØ$2 NÑ$4Ô$4Ø#˜8™:œ:Ø#˜8™:œ:Ø#˜8™:œ:ð	ð 	€ð(ð (ð (ð$Pð Pð PðEð Eð Eðð ð ð$ð $ð $ðð ð ð ð r   