
    Vh                         d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ d
ZdZ ed      rddlmZ ndZdZ eed      sdZdZ eee       G d de             Zy)z,
Tests for L{twisted.conch.openssh_compat}.
    N)skipIf)getDHGeneratorAndPrime)keydata)FilePath)requireModule)MockOS)TestCaseF cryptography)OpenSSHFactoryTzCannot run without cryptographygeteuidzgeteuid/seteuid not availablec                   8    e Zd ZdZddZddZddZddZddZy)	OpenSSHFactoryTestsz&
    Tests for L{OpenSSHFactory}.
    Nc                     t               | _        t        | j                               | _        | j                  j                          | j                  j                  | j                  _        t        | j                               | _        | j                  j                          | j                  j                  | j                  _	        | j                  j                  d      j                  d       | j                  j                  d      j                  d       | j                  j                  d      j                  t        j                         | j                  j                  d      j                  t        j                         | j                  j                  d      j                  d       | j                  j                  d      j                  t        j                         | j                  j                  d	      j                  d
       t!               | _        | j%                  t&        d| j"                  j(                         | j%                  t&        d| j"                  j*                         y )Nssh_host_foos   foobar_keyssh_host_one_keyssh_host_two_keyssh_host_three_keys   not a key contentzssh_host_one_key.pubmodulis  
#    $OpenBSD: moduli,v 1.xx 2016/07/26 12:34:56 jhacker Exp $i
# Time Type Tests Tries Size Generator Modulus
20030501000000 2 6 100 2047 2 FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF
seteuidsetegid)r   factoryr   mktempkeysDirmakedirspathdataRoot	moduliDir
moduliRootchild
setContentr   privateRSA_opensshprivateDSA_opensshpublicRSA_opensshr   mockospatchosr   r   )selfs    V/home/dcms/DCMS/lib/python3.12/site-packages/twisted/conch/test/test_openssh_compat.pysetUpzOpenSSHFactoryTests.setUp%   s   %'. $ 1 1!$++-0!"&.."5"5>*55f=9%008-.99':T:TU-.99':T:TU/0;;<PQ12==g>W>WXX&11	
  h

2y$++"5"56

2y$++"5"56    c                     | j                   j                         }| j                  t        |      d       |j	                         }| j                  t        |      dg       y)zw
        L{OpenSSHFactory.getPublicKeys} should return the available public keys
        in the data directory
              ssh-rsaN)r   getPublicKeysassertEquallenkeyslistr)   r3   keyTypess      r*   test_getPublicKeysz&OpenSSHFactoryTests.test_getPublicKeysJ   sK    
 ||))+TA&99;h*6r,   c                 `   | j                   j                         }| j                  t        |      d       |j	                         }| j                  t        |      ddh       | j                  | j                  j                  g        | j                  | j                  j                  g        y)z
        Will return the available private keys in the data directory, ignoring
        key files which failed to be loaded.
           r/      ssh-dssN)	r   getPrivateKeysr1   r2   r3   setr&   seteuidCallssetegidCallsr5   s      r*   test_getPrivateKeysz'OpenSSHFactoryTests.test_getPrivateKeysT   s    
 ||**,TA&99;XZ(@A11261126r,   c                    | j                   j                  d      j                  d       | j                  j                  d       t        j
                  dt        ddffd}| j                  t        d|       | j                  j                         }| j                  t        |      d	       |j                         }| j                  t        |      d
dh       | j                  | j                  j                  dt	        j                          g       | j                  | j                  j"                  dt	        j$                         g       y)z
        L{OpenSSHFactory.getPrivateKeys} should switch to root if the keys
        aren't readable by the current user.
        r   r     euidreturnNc                 6    j                  d        |       S )NrA   )chmod)rB   keyFilesavedSeteuids    r*   r   z>OpenSSHFactoryTests.test_getPrivateKeysAsRoot.<locals>.seteuidl   s    MM% %%r,   r   r9   r/   r:   )r   r!   rE   
addCleanupr(   r   intr'   r   r;   r1   r2   r3   r<   r&   r=   r   r>   getegid)r)   r   r3   r6   rF   rG   s       @@r*   test_getPrivateKeysAsRootz-OpenSSHFactoryTests.test_getPrivateKeysAsRoot`   s    
 ,,$$%78du-zz	&# 	&$ 	& 	

2y'*||**,TA&99;XZ(@A11Arzz|3DE11Arzz|3DEr,   c                 t    | j                   j                         }| j                  |dt        d      gi       y)zq
        L{OpenSSHFactory.getPrimes} should return the available primes
        in the moduli directory.
        i   s   diffie-hellman-group14-sha1N)r   	getPrimesr1   r   )r)   primess     r*   test_getPrimesz"OpenSSHFactoryTests.test_getPrimesx   s;    
 '')-.LMN	
r,   )rC   N)	__name__
__module____qualname____doc__r+   r7   r?   rK   rO    r,   r*   r   r      s"    #7J7
7F0
r,   r   )rS   r(   unittestr   twisted.conch.ssh._kexr   twisted.conch.testr   twisted.python.filepathr   twisted.python.reflectr   twisted.test.test_processr   twisted.trial.unittestr	   doSkip
skipReason$twisted.conch.openssh_compat.factoryr   hasattrr   rT   r,   r*   <module>r`      s|    
  9 & , 0 , +	
 CF2Jr9F0J 
c
( c
 c
r,   