AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/conch/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/conch/test/__pycache__/test_ckeygen.cpython-310.pyc
o

5�@g_�@s�dZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZmZddl
mZddlmZddlmZed�r[ed	�r[dd
lmZmZmZmZmZddlmZmZmZmZndZd
d�ZGdd�de�Z dS)z-
Tests for L{twisted.conch.scripts.ckeygen}.
�N)�StringIO)�privateECDSA_openssh�privateEd25519_openssh_new�privateRSA_openssh�privateRSA_openssh_encrypted�publicRSA_openssh)�FilePath)�
requireModule)�TestCase�cryptography�pyasn1)�_saveKey�changePassPhrase�displayPublicKey�enumrepresentation�printFingerprint)�BadFingerPrintFormat�BadKeyError�FingerprintFormats�KeyzBcryptography and pyasn1 required for twisted.conch.scripts.ckeygencst����fdd�}|S)a@
    Return a callable to patch C{getpass.getpass}.  Yields a passphrase each
    time called. Use case is to provide an old, then new passphrase(s) as if
    requested interactively.

    @param passphrases: The list of passphrases returned, one per each call.

    @return: A callable to patch C{getpass.getpass}.
    cst��S�N)�next��_��passphrases��A/usr/lib/python3/dist-packages/twisted/conch/test/test_ckeygen.py�fakeGetpass7�z makeGetpass.<locals>.fakeGetpass)�iter)rrrrr�makeGetpass+s
r!c@s"eZdZdZdd�ZdGdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dS)H�KeyGenTestszN
    Tests for various functions used to implement the I{ckeygen} script.
    cCst�|_|�td|j�dS)zX
        Patch C{sys.stdout} so tests can make assertions about what's printed.
        �stdoutN)rr#�patch�sys��selfrrr�setUpBszKeyGenTests.setUpNcCs�|��}dd|d|dg}|dur|�d|g�|dur"|�d|g�zt�|�Wnty;d|d<t�|�Ynwt�|�}t�|d	�}|d
krU|�|��d�n|dkrb|�|��d
�n
|�|��|�	��|�
|���dS)N�ckeygen�-t�-fz--no-passphrasez-bz--private-key-subtype�ckeygen3rz.pub�ecdsa�EC�ed25519�Ed25519)�mktemp�extend�
subprocess�call�FileNotFoundErrorr�fromFile�assertEqual�type�upper�
assertTrue�isPublic)r'�keyType�keySize�privateKeySubtype�filename�args�privKey�pubKeyrrr�_testrunIs(�
zKeyGenTests._testruncCs�|�dd�|jdddd�|�d�|jddd�|�d�|�dd�|jdddd�|�d�|jddd�|�dd�|jdddd�|�d�|jddd�dS)	Nr-�384�v1)r>r/�dsa�2048�rsa)rCr&rrr�test_keygeneration_s



zKeyGenTests.test_keygenerationcCs�|��}|�tj��Kttjd��,}ztjdddd|g|d�Wnty5tjdddd|g|d�YnwWd�n1s@wYWd�dSWd�dS1sXwYdS)N�rbr)r*�foor+)�stderrr,)	r1�assertRaisesr3�CalledProcessError�open�os�devnull�
check_callr5)r'r?rQrrr�test_runBadKeytypens&
�
�����"�zKeyGenTests.test_runBadKeytypecC�"tddi�}|�|dtj�dS)z�
        L{enumrepresentation} takes a dictionary as input and returns a
        dictionary with its attributes changed to enum representation.
        �format�md5-hexN)r�assertIsr�MD5_HEX�r'�optionsrrr�test_enumrepresentation{sz#KeyGenTests.test_enumrepresentationcCrT)zF
        Test for format L{FingerprintFormats.SHA256-BASE64}.
        rU�
sha256-base64N)rrWr�
SHA256_BASE64rYrrr�test_enumrepresentationsha256�sz)KeyGenTests.test_enumrepresentationsha256cCsN|�t��}tddi�Wd�n1swY|�d|jjd�dS)z9
        Test for unsupported fingerprint format
        rU�
sha-base64N�*Unsupported fingerprint format: sha-base64r)rMrrr7�	exceptionr@)r'�emrrr� test_enumrepresentationBadFormat�s��z,KeyGenTests.test_enumrepresentationBadFormatcC�:|��}t|��t�t|dd��|�|j��d�dS)z�
        L{printFingerprint} writes a line to standard out giving the number of
        bits of the key, its fingerprint, and the basename of the file from it
        was read.
        rV�r?rUz:2048 85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da temp
N�r1r�
setContentrrr7r#�getvalue�r'r?rrr�test_printFingerprint�s�z!KeyGenTests.test_printFingerprintcCrd)z�
        L{printFigerprint} will print key fingerprint in
        L{FingerprintFormats.SHA256-BASE64} format if explicitly specified.
        r\rez72048 FBTCOoknq0mHy+kpfnY9tDdcAJuWtCpuQMaV3EsvbUI= temp
Nrfrirrr�test_printFingerprintsha256�s�z'KeyGenTests.test_printFingerprintsha256cCsf|��}t|��t�|�t��}t|dd��Wd�n1s"wY|�d|jj	d�dS)zx
        L{printFigerprint} raises C{keys.BadFingerprintFormat} when unsupported
        formats are requested.
        r_reNr`r)
r1rrgrrMrrr7rar@)r'r?rbrrr�)test_printFingerprintBadFingerPrintFormat�s��z5KeyGenTests.test_printFingerprintBadFingerPrintFormatcC�t|���}|��|�d�j}t�t�}t||ddd��|�	|j
��d||f�|�	|�|�d���dd�|�|�	t�|�d����|�
��dS)z�
        L{_saveKey} writes the private and public parts of a key to two
        different files and writes a report of this to standard out.
        �id_rsa�
passphraserV�r?�passrU��Your identification has been saved in %s
Your public key has been saved in %s.pub
The key fingerprint in <FingerprintFormats=MD5_HEX> is:
85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da
N�
id_rsa.pub�rr1�makedirs�child�pathr�
fromStringrr
r7r#rh�
getContent�public�r'�baser?�keyrrr�test_saveKey�s"
����zKeyGenTests.test_saveKeycCrm)z�
        L{_saveKey} writes the private and public parts of a key to two
        different files and writes a report of this to standard out.
        Test with ECDSA key.
        �id_ecdsarorVrpz�Your identification has been saved in %s
Your public key has been saved in %s.pub
The key fingerprint in <FingerprintFormats=MD5_HEX> is:
1e:ab:83:a6:f2:04:22:99:7c:64:14:d2:ab:fa:f5:16
Nzid_ecdsa.pub)rr1rurvrwrrxrr
r7r#rhryrzr{rrr�test_saveKeyECDSA�s"
����zKeyGenTests.test_saveKeyECDSAcCrm)z�
        L{_saveKey} writes the private and public parts of a key to two
        different files and writes a report of this to standard out.
        Test with Ed25519 key.
        �
id_ed25519rorVrpz�Your identification has been saved in %s
Your public key has been saved in %s.pub
The key fingerprint in <FingerprintFormats=MD5_HEX> is:
ab:ee:c8:ed:e5:01:1b:45:b7:8d:b2:f0:8f:61:1c:14
Nzid_ed25519.pub)rr1rurvrwrrxrr
r7r#rhryrzr{rrr�test_saveKeyEd25519�s$
����zKeyGenTests.test_saveKeyEd25519cCrm)z�
        L{_saveKey} will generate key fingerprint in
        L{FingerprintFormats.SHA256-BASE64} format if explicitly specified.
        rnror\rpz�Your identification has been saved in %s
Your public key has been saved in %s.pub
The key fingerprint in <FingerprintFormats=SHA256_BASE64> is:
FBTCOoknq0mHy+kpfnY9tDdcAJuWtCpuQMaV3EsvbUI=
Nrsrtr{rrr�test_saveKeysha256s&
�����zKeyGenTests.test_saveKeysha256cCs~t|���}|��|�d�j}t�t�}|�t	��}t
||ddd��Wd�n1s.wY|�d|jj
d�dS)zq
        L{_saveKey} raises C{keys.BadFingerprintFormat} when unsupported
        formats are requested.
        rnror_rpNr`r)rr1rurvrwrrxrrMrr
r7rar@)r'r|r?r}rbrrr� test_saveKeyBadFingerPrintformat!s

���z,KeyGenTests.test_saveKeyBadFingerPrintformatcCs`t|���}|��|�d�j}t�t�}t||ddd��|�	|�|�d��
�dd�|�dS)�q
        L{_saveKey} will choose an empty string for the passphrase if
        no-passphrase is C{True}.
        rnTrV�r?z
no-passphraserUN�)rr1rurvrwrrxrr
r7ryr{rrr�test_saveKeyEmptyPassphrase3s
��z'KeyGenTests.test_saveKeyEmptyPassphrasecC�^t|���}|��|�d�j}t�t�}t||ddd��|�	|�|�d��
�d�|�dS)r�rTrVr�N)rr1rurvrwrrxrr
r7ryr{rrr� test_saveKeyECDSAEmptyPassphraseCs
�"z,KeyGenTests.test_saveKeyECDSAEmptyPassphrasecCr�)r�r�TrVr�N)rr1rurvrwrrxrr
r7ryr{rrr�"test_saveKeyEd25519EmptyPassphraseQs
��z.KeyGenTests.test_saveKeyEd25519EmptyPassphrasecs�t|���}|��|�d�j�ddl}|�|jjj	d�fdd��t
�t�}t
|dddd	��|�d���}|�|dd
�}|�||�dS)zd
        When no path is specified, it will ask for the path used to store the
        key.
        �
custom_keyrN�_inputSaveFilecs�Srrr��keyPathrr�<lambda>l�z4KeyGenTests.test_saveKeyNoFilename.<locals>.<lambda>TrVr�r�)rr1rurvrw�twisted.conch.scripts.ckeygenr$�conch�scriptsr)rrxrr
ryr7)r'r|�twistedr}�persistedKeyContent�persistedKeyrr�r�test_saveKeyNoFilenameas
z"KeyGenTests.test_saveKeyNoFilenamecCs�t|���}|��|�d�j}t�t�}t||dddd��|�	|j
��d||f�|�d���}|�	|�|dd�|�|�
|�d��|�	t�|�d	����|���dS)
zi
        L{_saveKey} can be told to write the new private key file in OpenSSH
        v1 format.
        rnrorVrE)r?rqrU�private-key-subtyperrN�$-----BEGIN OPENSSH PRIVATE KEY-----
rs)rr1rurvrwrrxrr
r7r#rhryr:�
startswithrz)r'r|r?r}�privateKeyContentrrr�test_saveKeySubtypeV1ts4
��	����z!KeyGenTests.test_saveKeySubtypeV1cCsf|��}t�t�}t|��t�td|i�|j�	��
d�}t|t�r(|�
d�}|�||�d��dS)zl
        L{displayPublicKey} prints out the public key associated with a given
        private key.
        r?�
�ascii�opensshN)r1rrxrrrgrrr#rh�strip�
isinstance�str�encoder7�toString�r'r?rB�	displayedrrr�test_displayPublicKey�s


z!KeyGenTests.test_displayPublicKeycCsh|��}t�t�}t|��t�t|dd��|j�	��
d�}t|t�r)|�
d�}|�||�d��dS)z�
        L{displayPublicKey} prints out the public key associated with a given
        private key using the given passphrase when it's encrypted.
        �	encrypted�r?rqr�r�r�N)r1rrxrrrgrrr#rhr�r�r�r�r7r�r�rrr�test_displayPublicKeyEncrypted�s


z*KeyGenTests.test_displayPublicKeyEncryptedcCsx|��}t�t�}t|��t�|�tddd��t	d|i�|j
���d�}t
|t�r1|�d�}|�||�d��dS)	z�
        L{displayPublicKey} prints out the public key associated with a given
        private key, asking for the passphrase when it's encrypted.
        �getpasscS�dS)Nr�r)�xrrrr��r�zLKeyGenTests.test_displayPublicKeyEncryptedPassphrasePrompt.<locals>.<lambda>r?r�r�r�N)r1rrxrrrgrr$r�rr#rhr�r�r�r�r7r�r�rrr�.test_displayPublicKeyEncryptedPassphrasePrompt�s


z:KeyGenTests.test_displayPublicKeyEncryptedPassphrasePromptcCs.|��}t|��t�|�tt|dd��dS)z�
        L{displayPublicKey} fails with a L{BadKeyError} when trying to decrypt
        an encrypted key with the wrong password.
        �wrongr�N)r1rrgrrMrrrirrr�$test_displayPublicKeyWrongPassphrase�s
�z0KeyGenTests.test_displayPublicKeyWrongPassphrasecCsltddd�}|�td|�|��}t|��t�td|i�|�|j	�
��d�d�|�tt|��
��dS)zt
        L{changePassPhrase} allows a user to change the passphrase of a
        private key interactively.
        r��newpassr�r?r��;Your identification has been saved with the new passphrase.N�r!r$r�r1rrgrrr7r#rhr��assertNotEqualry)r'�
oldNewConfirmr?rrr�test_changePassphrase�s��z!KeyGenTests.test_changePassphrasecCsltdd�}|�td|�|��}t|��t�t|dd��|�|j	�
��d�d�|�tt|��
��dS)z�
        L{changePassPhrase} allows a user to change the passphrase of a
        private key, providing the old passphrase and prompting for new one.
        r�r�r�r�r�r�Nr�)r'�
newConfirmr?rrr�test_changePassphraseWithOld�s
��z(KeyGenTests.test_changePassphraseWithOldcCsV|��}t|��t�t|ddd��|�|j���d�d�|�	tt|��
��dS)z�
        L{changePassPhrase} allows a user to change the passphrase of a private
        key by providing both old and new passphrases without prompting.
        r��
newencrypt)r?rqr�r�r�N)r1rrgrrr7r#rhr�r�ryrirrr�test_changePassphraseWithBoth�s
���z)KeyGenTests.test_changePassphraseWithBothcC�R|��}t|��t�|�tt|dd��}|�dt|��|�tt|��	��dS)z�
        L{changePassPhrase} exits if passed an invalid old passphrase when
        trying to change the passphrase of a private key.
        r�r�z1Could not change passphrase: old passphrase errorN)
r1rrgrrM�
SystemExitrr7r�ry�r'r?�errorrrr�$test_changePassphraseWrongPassphrases��z0KeyGenTests.test_changePassphraseWrongPassphrasecCsb|�tdtd��|��}t|��t�|�tt	d|i�}|�
dt|��|�
tt|����dS)z�
        L{changePassPhrase} exits if no passphrase is specified for the
        C{getpass} call and the key is encrypted.
        r��r?zMCould not change passphrase: Passphrase must be provided for an encrypted keyN)
r$r�r!r1rrgrrMr�rr7r�ryr�rrr�!test_changePassphraseEmptyGetPasss�z-KeyGenTests.test_changePassphraseEmptyGetPasscCsT|��}t|��d�|�ttd|i�}d}|�|t|��|�dt|����dS)zc
        L{changePassPhrase} exits if the file specified points to an invalid
        key.
        sfoobarr?z?Could not change passphrase: cannot guess the type of b'foobar'N)	r1rrgrMr�rr7r�ry)r'r?r��expectedrrr�test_changePassphraseBadKey&sz'KeyGenTests.test_changePassphraseBadKeycCsh|��}t|��t�dd�}|�td|�|�tt|dd��}|�	dt
|��|�	tt|����dS)z�
        L{changePassPhrase} doesn't modify the key file if an unexpected error
        happens when trying to create the key with the new passphrase.
        c_std��)N�oops)�RuntimeError�r@�kwargsrrrr�;rz>KeyGenTests.test_changePassphraseCreateError.<locals>.toStringr�r��r?r�z!Could not change passphrase: oopsN�r1rrgrr$rrMr�rr7r�ry)r'r?r�r�rrr� test_changePassphraseCreateError3s�z,KeyGenTests.test_changePassphraseCreateErrorcCsl|��}t|��t�dd�}|�td|�|�tt|dd��}d}|�	|t
|��|�	tt|����dS)zq
        L{changePassPhrase} doesn't modify the key file if C{toString} returns
        an empty string.
        c_r�)Nr�rr�rrrr�RszCKeyGenTests.test_changePassphraseEmptyStringError.<locals>.toStringr�r�r�z9Could not change passphrase: cannot guess the type of b''Nr�)r'r?r�r�r�rrr�%test_changePassphraseEmptyStringErrorJs�z1KeyGenTests.test_changePassphraseEmptyStringErrorcCr�)z�
        L{changePassPhrase} exits when trying to change the passphrase on a
        public key, and doesn't change the file.
        rqr�z.Could not change passphrase: key not encryptedN)
r1rrgrrMr�rr7r�ryr�rrr�test_changePassphrasePublicKeybs�z*KeyGenTests.test_changePassphrasePublicKeycCs�tddd�}|�td|�|��}t|��t�t|dd��|�|j	�
��d�d�t|���}|�
t|�|�|�d��d	S)
zq
        L{changePassPhrase} can be told to write the new private key file in
        OpenSSH v1 format.
        r�r�r�rE)r?r�r�r�r�N)r!r$r�r1rrgrrr7r#rhr�ryr�r:r�)r'r�r?r�rrr�test_changePassphraseSubtypeV1os��z*KeyGenTests.test_changePassphraseSubtypeV1)NN)&�__name__�
__module__�__qualname__�__doc__r(rCrIrSr[r^rcrjrkrlr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr"=sH




"

r")!r�r�r3r%rP�ior�twisted.conch.test.keydatarrrrr�twisted.python.filepathr�twisted.python.reflectr	�twisted.trial.unittestr
r�r
rrrr�twisted.conch.ssh.keysrrrr�skipr!r"rrrr�<module>s 

Anon7 - 2022
AnonSec Team