HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/conch/test/__pycache__/test_agent.cpython-38.pyc
U


W[3�@spdZddlmZmZddlZddlmZddlmZzddl	Z	Wne
k
rXdZ	YnXzddlZWne
k
r~dZYnXe	r�er�ddlm
Z
mZndZ
ZddlmZddlmZmZGd	d
�d
e�ZGdd�dej�ZGd
d�de�ZGdd�de�Zedk	�rGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z dS)z'
Tests for L{twisted.conch.ssh.agent}.
�)�absolute_import�divisionN)�unittest)�iosim)�keys�agent)�keydata)�
ConchError�MissingKeyStoreErrorc@seZdZdZdd�ZdS)�StubFactoryzb
    Mock factory that provides the keys attribute required by the
    SSHAgentServerProtocol
    cCs
i|_dS�N)r��self�r�?/usr/lib/python3/dist-packages/twisted/conch/test/test_agent.py�__init__&szStubFactory.__init__N)�__name__�
__module__�__qualname__�__doc__rrrrrr!src@s:eZdZdZedkrdZnedks*edkr.dZdd�ZdS)�
AgentTestBasez*
    Tests for SSHAgentServer/Client.
    Nz,iosim requires SSL, but SSL is not availablez)Cannot run without cryptography or PyASN1cCsjt�tjtj�\|_|_|_t�|j_	t
j�t
j�|_t
j�t
j�|_t
j�t
j�|_t
j�t
j�|_dSr)r�connectedServerAndClientr�SSHAgentServer�SSHAgentClient�client�server�pumpr�factoryr�Key�
fromStringrZprivateRSA_openssh�
rsaPrivateZprivateDSA_openssh�
dsaPrivateZpublicRSA_openssh�	rsaPublicZpublicDSA_openssh�	dsaPublicr
rrr�setUp4s�
zAgentTestBase.setUp)	rrrrr�skiprrr$rrrrr+src@seZdZdZdd�ZdS)�&ServerProtocolContractWithFactoryTestsz�
    The server protocol is stateful and so uses its factory to track state
    across requests.  This test asserts that the protocol raises if its factory
    doesn't provide the necessary storage for that state.
    cCs2t�ddtj�}|jjjd=|�t|jj	|�dS)Nz!LB�r)
�structZpackrZAGENTC_REQUEST_IDENTITIESrr�__dict__ZassertRaisesr
ZdataReceived)r�msgrrr�/test_factorySuppliesKeyStorageForServerProtocolLs�zVServerProtocolContractWithFactoryTests.test_factorySuppliesKeyStorageForServerProtocolN)rrrrr+rrrrr&Fsr&c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�"UnimplementedVersionOneServerTestsa!
    Tests for methods with no-op implementations on the server. We need these
    for clients, such as openssh, that try v1 methods before going to v2.

    Because the client doesn't expose these operations with nice method names,
    we invoke sendRequest directly with an op code.
    cs0�j�tjd�}�j���fdd�}|�|�S)zV
        assert that we get the correct op code for an RSA identities request
        �cs��tjt|dd���dS)Nrr')�assertEqualrZAGENT_RSA_IDENTITIES_ANSWER�ord)Zpacketr
rr�_cbds�zRUnimplementedVersionOneServerTests.test_agentc_REQUEST_RSA_IDENTITIES.<locals>._cb)r�sendRequestrZAGENTC_REQUEST_RSA_IDENTITIESr�flush�addCallback)r�dr0rr
r�"test_agentc_REQUEST_RSA_IDENTITIES^s
zEUnimplementedVersionOneServerTests.test_agentc_REQUEST_RSA_IDENTITIEScCs(|j�tjd�}|j��|�|jd�S)z[
        assert that we get the correct op code for an RSA remove identity request
        r-)rr1rZAGENTC_REMOVE_RSA_IDENTITYrr2r3r.�rr4rrr�test_agentc_REMOVE_RSA_IDENTITYjs
zBUnimplementedVersionOneServerTests.test_agentc_REMOVE_RSA_IDENTITYcCs(|j�tjd�}|j��|�|jd�S)zj
        assert that we get the correct op code for an RSA remove all identities
        request.
        r-)rr1rZ AGENTC_REMOVE_ALL_RSA_IDENTITIESrr2r3r.r6rrr�%test_agentc_REMOVE_ALL_RSA_IDENTITIESss
zHUnimplementedVersionOneServerTests.test_agentc_REMOVE_ALL_RSA_IDENTITIESN)rrrrr5r7r8rrrrr,Us	r,c@s eZdZdZdd�Zdd�ZdS)�
CorruptServerz�
        A misbehaving server that returns bogus response op codes so that we can
        verify that our callbacks that deal with these op codes handle such
        miscreants.
        cCs|�dd�dS�N�r-�ZsendResponse�r�datarrr�agentc_REQUEST_IDENTITIES�sz'CorruptServer.agentc_REQUEST_IDENTITIEScCs|�dd�dSr:r<r=rrr�agentc_SIGN_REQUEST�sz!CorruptServer.agentc_SIGN_REQUESTN)rrrrr?r@rrrrr9sr9c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ClientWithBrokenServerTestszM
    verify error handling code in the client using a misbehaving server
    cCs2t�|�t�ttj�\|_|_|_	t
�|j_dSr)rr$rrr9rrrrrrrr
rrrr$�s
�z!ClientWithBrokenServerTests.setUpcCs*|j�|j��d�}|j��|�|t�S)z�
        Assert that L{SSHAgentClient.signData} raises a ConchError
        if we get a response from the server whose opcode doesn't match
        the protocol for data signing requests.
        �John Hancock)r�signDatar"�blobrr2�
assertFailurer	r6rrr�"test_signDataCallbackErrorHandling�s
z>ClientWithBrokenServerTests.test_signDataCallbackErrorHandlingcCs |j��}|j��|�|t�S)z�
        Assert that L{SSHAgentClient.requestIdentities} raises a ConchError
        if we get a response from the server whose opcode doesn't match
        the protocol for identity requests.
        )r�requestIdentitiesrr2rEr	r6rrr�+test_requestIdentitiesCallbackErrorHandling�s

zGClientWithBrokenServerTests.test_requestIdentitiesCallbackErrorHandlingN)rrrrr$rFrHrrrrrA�s	rAc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�AgentKeyAdditionTestsz<
    Test adding different flavors of keys to an agent.
    cs2�j��j���}�j���fdd�}|�|�S)�@
        L{SSHAgentClient.addIdentity} adds the private key it is called
        with to the SSH agent server to which it is connected, associating
        it with the comment it is called with.

        This test asserts that omitting the comment produces an
        empty string for the comment on the server.
        cs:�jjj�j��}���j|d���d|d�dS�Nrr-r'�rrrr rDr.��ignoredZ	serverKeyr
rr�_check�szBAgentKeyAdditionTests.test_addRSAIdentityNoComment.<locals>._check�r�addIdentityr �privateBlobrr2r3�rr4rOrr
r�test_addRSAIdentityNoComment�s	
z2AgentKeyAdditionTests.test_addRSAIdentityNoCommentcs2�j��j���}�j���fdd�}|�|�S)rJcs:�jjj�j��}���j|d���d|d�dSrK�rrrr!rDr.rMr
rrrO�szBAgentKeyAdditionTests.test_addDSAIdentityNoComment.<locals>._check�rrQr!rRrr2r3rSrr
r�test_addDSAIdentityNoComment�s	
z2AgentKeyAdditionTests.test_addDSAIdentityNoCommentcs6�jj�j��dd�}�j���fdd�}|�|�S)�1
        L{SSHAgentClient.addIdentity} adds the private key it is called
        with to the SSH agent server to which it is connected, associating
        it with the comment it is called with.

        This test asserts that the server receives/stores the comment
        as sent by the client.
        �My special key�Zcommentcs:�jjj�j��}���j|d���d|d�dS�NrrYr'rLrMr
rrrO�szDAgentKeyAdditionTests.test_addRSAIdentityWithComment.<locals>._checkrPrSrr
r�test_addRSAIdentityWithComment�s	�
z4AgentKeyAdditionTests.test_addRSAIdentityWithCommentcs6�jj�j��dd�}�j���fdd�}|�|�S)rXrYrZcs:�jjj�j��}���j|d���d|d�dSr[rUrMr
rrrO�szDAgentKeyAdditionTests.test_addDSAIdentityWithComment.<locals>._checkrVrSrr
r�test_addDSAIdentityWithComment�s	�
z4AgentKeyAdditionTests.test_addDSAIdentityWithCommentN)rrrrrTrWr\r]rrrrrI�s
rIc@seZdZdd�ZdS)�AgentClientFailureTestscCs$|j�dd�}|j��|�|t�S)zK
        verify that the client raises ConchError on AGENT_FAILURE
        r;r-)rr1rr2rEr	r6rrr�test_agentFailures
z)AgentClientFailureTests.test_agentFailureN)rrrr_rrrrr^sr^c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�AgentIdentityRequestsTestszJ
    Test operations against a server with identities already loaded.
    cCsBt�|�|jdf|jjj|j��<|jdf|jjj|j��<dS�N�	a comment�another comment�rr$r!rrrrDr r
rrrr$s
��z AgentIdentityRequestsTests.setUpcCsX|j�|j��d�}|j��|�|�}|j�d�}|�	||�|�
|j�|d��dS)zc
        Sign data with an RSA private key and then verify it with the public
        key.
        rBN)rrCr"rDrr2ZsuccessResultOfr Zsignr.�
assertTrue�verify)rr4Z	signature�expectedrrr�test_signDataRSAs

z+AgentIdentityRequestsTests.test_signDataRSAcs4�j��j��d�}�j���fdd�}|�|�S)zb
        Sign data with a DSA private key and then verify it with the public
        key.
        rBcs���j�|d��dS)NrB)rer#rf)Zsigr
rrrO0sz;AgentIdentityRequestsTests.test_signDataDSA.<locals>._check)rrCr#rDrr2r3rSrr
r�test_signDataDSA)s
z+AgentIdentityRequestsTests.test_signDataDSAcCs<|jjj|j��=|j�|j��d�}|j��|�	|t
�S)zm
        Assert that we get an errback if we try to sign data using a key that
        wasn't added.
        rB)rrrr"rDrrCrr2rEr	r6rrr�$test_signDataRSAErrbackOnUnknownBlob8s
z?AgentIdentityRequestsTests.test_signDataRSAErrbackOnUnknownBlobcs*�j��}�j���fdd�}|�|�S)z}
        Assert that we get all of the keys/comments that we add when we issue a
        request for all identities.
        cs^i}d|�j��<d|�j��<i}|D]$}|d|tjj|ddd���<q(��||�dS)Nrbrcr'rrD)�type)r#rDr"rrrr.)ZkeytrgZreceived�kr
rrrOJs"zAAgentIdentityRequestsTests.test_requestIdentities.<locals>._check)rrGrr2r3rSrr
r�test_requestIdentitiesCs

	z1AgentIdentityRequestsTests.test_requestIdentitiesN)	rrrrr$rhrirjrmrrrrr`sr`c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�AgentKeyRemovalTestsz<
    Test support for removing keys in a remote server.
    cCsBt�|�|jdf|jjj|j��<|jdf|jjj|j��<dSrardr
rrrr$\s
��zAgentKeyRemovalTests.setUpcs2�j��j���}�j���fdd�}|�|�S)z<
        Assert that we can remove an RSA identity.
        csJ��dt�jjj�����j���jjj����j	���jjj�dS�Nr')
r.�lenrrr�assertInr!rDZassertNotInr �rNr
rrrOlsz;AgentKeyRemovalTests.test_removeRSAIdentity.<locals>._check)r�removeIdentityr rDrr2r3rSrr
r�test_removeRSAIdentityds
z+AgentKeyRemovalTests.test_removeRSAIdentitycs2�j��j���}�j���fdd�}|�|�S)z;
        Assert that we can remove a DSA identity.
        cs2��dt�jjj�����j���jjj�dSro)r.rprrrrqr rDrrr
rrrO{sz;AgentKeyRemovalTests.test_removeDSAIdentity.<locals>._check)rrsr!rDrr2r3rSrr
r�test_removeDSAIdentityss
z+AgentKeyRemovalTests.test_removeDSAIdentitycs*�j��}�j���fdd�}|�|�S)z;
        Assert that we can remove all identities.
        cs��dt�jjj��dS)Nr)r.rprrrrrr
rrrO�sz=AgentKeyRemovalTests.test_removeAllIdentities.<locals>._check)rZremoveAllIdentitiesrr2r3rSrr
r�test_removeAllIdentities�s

z-AgentKeyRemovalTests.test_removeAllIdentitiesN)rrrrr$rtrurvrrrrrnWs
rn)!rZ
__future__rrr(Z
twisted.trialrZtwisted.testrZcryptography�ImportErrorZpyasn1Ztwisted.conch.sshrrZtwisted.conch.testrZtwisted.conch.errorr	r
�objectrZTestCaserr&r,rr9rArIr^r`rnrrrr�<module>s8


)
%PI