HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //lib64/python3.9/site-packages/gssapi/__pycache__/sec_contexts.cpython-39.opt-1.pyc
a

��_�J�@s�ddlZddlmZddlmZddlmZddlm	Z	m
Z
ddlmZ
ddlmZddlmZddlmZe�ej�Gd	d
�d
ej��ZdS)�N)�sec_contexts)�message)�named_tuples)�RequirementFlag�IntEnumFlagSet)�_utils)�Name)�Credentialsc	seZdZdZd5�fdd�	Zd6dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zd7dd�Zdd�Z
dd�ZdZejdd��Zedd��Zedd ��Ze�d!d"�Ze�d#d$�Ze�d%d&�Ze�d'd(�Ze�d)d*�Zeejd+d,���Zejd8d-d.��Zd/d0�Zd9d1d2�Z d3d4�Z!�Z"S):�SecurityContexta�A GSSAPI Security Context

    This class represents a GSSAPI security context that may be used
    with and/or returned by other GSSAPI methods.

    It inherits from the low-level GSSAPI
    :class:`~gssapi.raw.sec_contexts.SecurityContext` class,
    and thus may used with both low-level and high-level API methods.

    This class may be pickled and unpickled (the attached delegated
    credentials object will not be preserved, however).
    Nc

s$|durt�|�}tt|��||�S�N)�
rsec_contextsZimport_sec_context�superr
�__new__)
�cls�base�token�name�creds�lifetime�flags�mech�channel_bindings�usage��	__class__��9/usr/lib64/python3.9/site-packages/gssapi/sec_contexts.pyrs
zSecurityContext.__new__c
Cs4d|_|dur�|dur�|	dur@|	dvr8d}
tj|
dd��|	|_n2|dur\|jdkr\|j|_n|durld|_nd|_|jdkr�|dur�td	��||_||_tt|�|_	||_
n(|dus�|dus�|dus�|dur�td
��||_||_d|_
nBz|jr�d|_nd|_Wn(tj�y(d}
tj|
dd��Yn0d|_dS)a
        The constructor creates a new security context, but does not begin
        the initiate or accept process.

        If the `base` argument is used, an existing
        :class:`~gssapi.raw.sec_contexts.SecurityContext` object from
        the low-level API is converted into a high-level object.

        If the `token` argument is passed, the security context is imported
        using the token.

        Otherwise, a new security context is created.

        If the `usage` argument is not passed, the constructor will attempt
        to detect what the appropriate usage is based on either the existing
        security context (if `base` or `token` are used) or the argument set.

        For a security context of the `initiate` usage, the `name` argument
        must be used, and the `creds`, `mech`, `flags`,
        `lifetime`, and `channel_bindings` arguments may be
        used as well.

        For a security context of the `accept` usage, the `creds` and
        `channel_bindings` arguments may optionally be used.
        N)�initiate�acceptz+Usage must be either 'initiate' or 'accept'zsecurity context)�objZbothrrzNYou must pass the 'name' argument when creating an initiating security contextzVYou must pass at most the 'creds' argument when creating an accepting security contextz7Cannot extract usage from a partially completed context)Z	_last_err�excsZUnknownUsageErrorr�	TypeError�_target_name�_mechrr�_desired_flags�_desired_lifetime�_channel_bindings�_creds�_delegated_creds�locally_initiated�MissingContextError�	_complete)�selfrrrrrrrrr�msgrrr�__init__&sH

��
zSecurityContext.__init__cCst�||�S)aBCalculate the signature for a message.

        This method calculates the signature (called a MIC) for
        the given message, which may be then used with
        :meth:`verify_signature` to confirm the validity of the
        signature.  This is useful if you wish to transmit the
        message signature and message in your own format.

        Args:
            message (bytes): the input message

        Returns:
            bytes: the message signature

        Raises:
            ExpiredContextError
            MissingContextError
            BadQoPError
        )�rmessageZget_mic�r,rrrr�
get_signature�szSecurityContext.get_signaturecCst�|||�S)a�Verify the signature for a message.

        This method verifies that a signature (generated by
        :meth:`get_signature` is valid for the given message.

        If the signature is valid, the method will return.
        Otherwise, it will raise an error.

        Args:
            message (bytes): the message
            mic (bytes): the signature to verify

        Raises:
            BadMICError: the signature was not valid
            InvalidTokenError
            DuplicateTokenError
            ExpiredTokenError
            TokenTooLateError
            TokenTooEarlyError
            ExpiredContextError
            MissingContextError
        )r/Z
verify_mic)r,rZmicrrr�verify_signature�sz SecurityContext.verify_signaturecCst�|||�S)aWrap a message, optionally with encryption

        This wraps a message, signing it and optionally
        encrypting it.

        Args:
            message (bytes): the message to wrap
            encrypt (bool): whether or not to encrypt the message

        Returns:
            WrapResult: the wrapped message and details about it
                (e.g. whether encryption was used succesfully)

        Raises:
            ExpiredContextError
            MissingContextError
            BadQoPError
        )r/�wrap)r,r�encryptrrrr3�szSecurityContext.wrapcCst�||�S)aaUnwrap a wrapped message.

        This method unwraps/unencrypts a wrapped message,
        verifying the signature along the way.

        Args:
            message (bytes): the message to unwrap/decrypt

        Returns:
            UnwrapResult: the unwrapped message and details about it
                (e.g. wheter encryption was used)

        Raises:
            InvalidTokenError
            BadMICError
            DuplicateTokenError
            ExpiredTokenError
            TokenTooLateError
            TokenTooEarlyError
            ExpiredContextError
            MissingContextError
        )r/�unwrapr0rrrr5�szSecurityContext.unwrapcCs$|j|dd�}|jst�d��|jS)amEncrypt a message.

        This method wraps and encrypts a message, similarly to
        :meth:`wrap`.  The difference is that encryption is always
        used, and the method will raise an exception if this is
        not possible.  Additionally, this method simply returns
        the encrypted message directly.

        Args:
            message (bytes): the message to encrypt

        Returns:
            bytes: the encrypted message

        Raises:
            EncryptionNotUsed: the encryption could not be used
            ExpiredContextError
            MissingContextError
            BadQoPError
        T)r4z!Wrapped message was not encrypted)r3�	encryptedr �EncryptionNotUsedr�r,r�resrrrr4�s
zSecurityContext.encryptcCs2|�|�}|js,|jtj@r,tjd|jd��|jS)a"Decrypt a message.

        This method decrypts and unwraps a message, verifying the signature
        along the way, similarly to :meth:`unwrap`.  The difference is that
        this method will raise an exception if encryption was established
        by the context and not used, and simply returns the decrypted
        message directly.

        Args:
            message (bytes): the encrypted message

        Returns:
            bytes: the decrypted message

        Raises:
            EncryptionNotUsed: encryption was expected, but not used
            InvalidTokenError
            BadMICError
            DuplicateTokenError
            ExpiredTokenError
            TokenTooLateError
            TokenTooEarlyError
            ExpiredContextError
            MissingContextError
        zTThe context was established with encryption, but unwrapped message was not encrypted)Zunwrapped_message)r5r6�actual_flagsrZconfidentialityr r7rr8rrr�decrypts

��zSecurityContext.decryptTcCst�|||�S)a.Calculate the maximum message size for a given wrapped message size.

        This method calculates the maximum input message size for a given
        maximum wrapped/encrypted message size.

        Args:
            desired_output_size (int): the maximum output message size
            encrypted (bool): whether or not encryption should be taken
                into account

        Returns:
            int: the maximum input message size

        Raises:
            MissingContextError
            ExpiredContextError
            BadQoPError
        )r/Zwrap_size_limit)r,Zdesired_output_sizer6rrr�get_wrap_size_limit,s�z#SecurityContext.get_wrap_size_limitcCst�||�dS)acProcess an output token asynchronously.

        This method processes an output token even when the security context
        was not expecting it.

        Warning:
            This method is deprecated.

        Args:
            token (bytes): the token to process

        Raises:
            InvalidTokenError
            MissingContextError
        N)rZprocess_context_token�r,rrrr�
process_tokenDszSecurityContext.process_tokencCs
t�|�S)aBExport a security context.

        This method exports a security context, allowing it to be passed
        between processes.

        Returns:
            bytes: the exported security context

        Raises:
            ExpiredContextError
            MissingContextError
            OperationUnavailableError
        )rZexport_sec_context�r,rrr�exportWszSecurityContext.export)�initiator_name�target_namerrr�locally_init�completec	Ks�|s
d}nd}|jD]}|�||�||<qtj|fi|��}|�dd�r^|jdur^t|j�}nd}|�dd�r�|jdur�t|j�}nd}t�|||j	|j
|j|j|j
�S)aInspect the security context for information

        This method inspects the security context for information.

        If no keyword arguments are passed, all available information
        is returned.  Otherwise, only the keyword arguments that
        are passed and set to `True` are returned.

        Args:
            initiator_name (bool): get the initiator name for this context
            target_name (bool): get the target name for this context
            lifetime (bool): get the remaining lifetime for this context
            mech (bool): get the :class:`MechType` used by this context
            flags (bool): get the flags set on this context
            locally_init (bool): get whether this context was locally initiated
            complete (bool): get whether negotiation on this context has
                been completed

        Returns:
            InquireContextResult: the results of the inquiry, with unused
                fields set to None

        Raises:
            MissingContextError
        TFrANrB)�
_INQUIRE_ARGS�getrZinquire_contextrArrB�tuplesZInquireContextResultrrrrCrD)r,�kwargsZdefault_val�argr9Z	init_namerBrrr�_inquireks*
���zSecurityContext._inquirecCs
t�|�S)z7The amount of time for which this context remains valid)rZcontext_timer?rrrr�szSecurityContext.lifetimecCs|jS)z�The credentials delegated from the initiator to the acceptor

        .. warning::

            This value will not be preserved across picklings.  These should
            be separately exported and transfered.

        )r(r?rrr�delegated_creds�s
zSecurityContext.delegated_credsrAz2The :class:`Name` of the initiator of this contextrBz/The :class:`Name` of the target of this contextrz8The mechanism (:class:`MechType`) in use by this contextrzThe flags set on this contextrCz)Whether this context was locally intiatedcCsN|jrF|jdur@z|jdd�j}Wntjy8YdS0||_|jSdSdS)z7Whether negotiation for this context has been completedNT)rDF)�_startedr+rJrDr r*)r,r9rrrrD�s
zSecurityContext.completecCs&|jdkr|j|d�S|j|d�SdS)aPerform a negotation step.

        This method performs a negotiation step based on the usage type
        of this context.  If `__DEFER_STEP_ERRORS__` is set to True on
        the class, this method will return a token, even when exceptions
        would be thrown.  The generated exception will be thrown on the next
        method call or property lookup on the context.
        **This is the default behavior.**

        This method should be used in a while loop, as such:

        .. code-block:: python

           input_token = None
           try:
               while not ctx.complete:
                   output_token = ctx.step(input_token)
                   input_token = send_and_receive(output_token)
           except GSSError as e:
                handle_the_issue()

        .. tip::

            Disabling `__DEFER_STEP_ERRORS__` is rarely necessary.
            When this method is used in a loop (as above),
            `__DEFER_STEP_ERRORS__` will ensure that you always
            send an error token when it's available,
            keeping the other end of the security context updated
            with the status of the negotiation.

        Args:
            token (bytes): the input token from the other participant's step

        Returns:
            bytes: the output token to send to the other participant

        Raises:
            InvalidTokenError
            InvalidCredentialsError
            MissingCredentialsError
            ExpiredCredentialsError
            BadChannelBindingsError
            BadMICError
            ExpiredTokenError: (initiate only)
            DuplicateTokenError
            MissingContextError
            BadNameTypeError: (initiate only)
            BadNameError: (initiate only)
            BadMechanismError
        r)rN)r�_acceptor_step�_initiator_stepr=rrr�step�s5
zSecurityContext.stepcCsBt�||j||j�}|jdur,t|j�|_nd|_|j|_|j	Sr)
rZaccept_sec_contextr'r&rKr	r(�
more_stepsr+r�r,rr9rrrrMs
�

zSecurityContext._acceptor_stepc
Cs4t�|j|j||j|j|j|j|�}|j|_	|j
Sr)rZinit_sec_contextr"r'r#r$r%r&rPr+rrQrrrrNs�
zSecurityContext._initiator_stepcCst|�d|��ffSr)�typer@r?rrr�
__reduce__%szSecurityContext.__reduce__)	NNNNNNNNN)	NNNNNNNNN)T)N)N)#�__name__�
__module__�__qualname__�__doc__rr.r1r2r3r5r4r;r<r>r@rErZcheck_last_errrJ�propertyrrKZinquire_propertyrArBrr:r)rDZcatch_and_return_tokenrOrMrNrS�
__classcell__rrrrr
sb
�	�
a'�

5

�����9

r
)ZsixZ
gssapi.rawrrrr/rrGZgssapi.raw.typesrrZgssapi.exceptions�
exceptionsr ZgssapirZgssapi.namesrZgssapi.credsr	Z
add_metaclassZCheckLastErrorr
rrrr�<module>s