
    i              	          S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKJrJrJr  S SKJrJrJr  \R&                  " S\R(                  S\R*                  4   S	9r\R&                  " S
\R*                  S	9r\R0                  \\\R2                  \R0                  \\4   \R0                  \\\4   4   \R0                  \\4   \4   rS\R<                  \   S\R2                  \R<                  \   \R<                  \   4   4S jr S&S\RB                  S\R<                  \   S\R(                  \/\4   4S jjr" " S S\RF                  5      r$ " S S\RF                  5      r% " S S\RF                  5      r& " S S\RF                  5      r' " S S\RF                  5      r(\RR                  " SS9 " S S5      5       r* " S S \RV                  5      r, " S! S"\\RZ                  5      r. " S# S$\ R^                  S%9r0g)'    N)
Credential)to_text)GssChannelBindings)FeatureMissingErrorNegotiateOptionsSpnegoError)
BufferType	IOVBufferIOVResBufferF.)bound	NativeIOVusernamereturnc                 l    U c  gSU ;   a  U R                  SS5      u  pOSn[        USS9[        U SS94$ )a  Splits a username and returns the domain component.

Will split a username in the Netlogon form `DOMAIN\username` and return the domain and user part as separate
strings. If the user does not contain the `DOMAIN\` prefix or is in the `UPN` form then then user stays the same
and the domain is an empty string.

Args:
    username: The username to split

Returns:
    Tuple[Optional[str], Optional[str]]: The domain and username.
N)NN\   passthru)	nonstring)splitr   )r   domains     I/home/james-whalen/.local/lib/python3.13/site-packages/spnego/_context.pysplit_usernamer      sJ      x#>>$26Z0'(j2YYY    
error_typecontextc                 4   ^ ^ S[         S[         4UU 4S jjnU$ )a]  Wraps a function that makes a native GSSAPI/SSPI syscall and convert native exceptions to a SpnegoError.

Wraps a function that can potentially raise a WindowsError or GSSError and converts it to the common SpnegoError
that is exposed by this library. This is to ensure the context proxy functions raise a common set of errors rather
than a specific error for the provider. The underlying error is preserved in the SpnegoError if the user wishes to
inspect that.

Args:
    error_type: The native error type that need to be wrapped.
    context: An optional context message to add to the error if raised.
funcr   c                    >^  S[         R                  S[         R                  S[        4UUU 4S jjn[         R                  " [        U5      $ )Nargskwargsr   c                  H   >  T" U 0 UD6$ ! T a  n[        UTS9UeS nAff = f)N)
base_errorcontext_msg)r   )r    r!   
native_errr   r   r   s      r   wrapper5wrap_system_error.<locals>.decorator.<locals>.wrapperB   s;    ^T,V,, ^!ZWMS]]^s    !!)typingAnyr   cast)r   r&   r   r   s   ` r   	decorator$wrap_system_error.<locals>.decoratorA   sB    	^6:: 	^ 	^ 	^ 	^ {{1g&&r   )r   )r   r   r+   s   `` r   wrap_system_errorr-   4   s#    ' 'a ' ' r   c                   .    \ rS rSr% Sr\\S'   \\S'   Srg)
WrapResultN   z Result of the `wrap()` function.data	encrypted N)	__name__
__module____qualname____firstlineno____doc__bytes__annotations__bool__static_attributes__r3   r   r   r/   r/   N   s    *
KOr   r/   c                   L    \ rS rSr% Sr\R                  \S4   \S'   \	\S'   Sr
g)IOVWrapResultU   z$Result of the `wrap_iov()` function..buffersr2   r3   N)r4   r5   r6   r7   r8   r(   Tupler   r:   r;   r<   r3   r   r   r>   r>   U   s    .\\,+,,Or   r>   c                   8    \ rS rSr% Sr\\S'   \\S'   \\S'   Srg)WinRMWrapResult\   z&Result of the `wrap_winrm()` function.headerr1   padding_lengthr3   N)	r4   r5   r6   r7   r8   r9   r:   intr<   r3   r   r   rC   rC   \   s    0M
Kr   rC   c                   8    \ rS rSr% Sr\\S'   \\S'   \\S'   Sr	g)UnwrapResultd   z"Result of the `unwrap()` function.r1   r2   qopr3   N)
r4   r5   r6   r7   r8   r9   r:   r;   rG   r<   r3   r   r   rI   rI   d   s    ,
KO	Hr   rI   c                   V    \ rS rSr% Sr\R                  \S4   \S'   \	\S'   \
\S'   Srg)	IOVUnwrapResultl   z&Result of the `unwrap_iov()` function..r@   r2   rK   r3   N)r4   r5   r6   r7   r8   r(   rA   r   r:   r;   rG   r<   r3   r   r   rM   rM   l   s#    0\\,+,,O	Hr   rM   T)frozenc                   $    \ rS rSr% Sr\\S'   Srg)SecPkgContextSizest   aQ  Sizes of important structures used for messages.

This dataclass exposes the sizes of important structures used in message
support functions like wrap, wrap_iov, sign, etc. Use
:meth:`ContextReq.query_message_sizes` to retrieve this value for an
authenticated context.

Currently only ``header`` is exposed but other sizes may be added in the
future if needed.

Attributes:
    header: The size of the header/signature of a wrapped token. This
        corresponds to cbSecurityTrailer in SecPkgContext_Sizes in SSPI and
        the size of the allocated GSS_IOV_BUFFER_TYPE_HEADER IOV buffer.
rE   r3   N)r4   r5   r6   r7   r8   rG   r:   r<   r3   r   r   rQ   rQ   t   s      Kr   rQ   c                   D    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrg)
ContextReq   r   r                   i   i    i   i   >   r3   N)r4   r5   r6   r7   nonedelegatemutual_authreplay_detectsequence_detectconfidentiality	integrity	dce_styleidentifydelegate_policyno_integritydefaultr<   r3   r   r   rT   rT      sE    D HKM O OIIH O L MGr   rT   c                       \ rS rSrSrSrSrSrSrSr	Sr
S	r\S
\R                  \\4   4S j5       r\S
\4S j5       r\S
\4S j5       r\S\S
S 4S j5       rSrg)GSSMech   z1.3.6.1.4.1.311.2.2.10z1.3.6.1.5.5.2z1.2.840.113554.1.2.2z1.2.840.48018.1.2.2z1.3.5.1.5.2z1.3.6.1.5.2z1.2.840.113554.1.2.2.3z1.3.6.1.4.1.311.2.2.30r   c                    0 [         R                  S_[         R                  R                  S_[         R                  S_[         R                  R                  S_[         R                  S_[         R                  R                  S_[         R
                  S_[         R
                  R                  S_[         R                  S_[         R                  R                  S_[         R                  S_[         R                  R                  S_[         R                  S_[         R                  R                  S_[         R                  S_[         R                  R                  S_$ )	NNTLMSPNEGOKerberoszMS KerberoszKerberos (draft)
IAKerberoszKerberos User to UserNEGOEX)
ri   ntlmvaluespnegokerberos_ms_kerberos_kerberos_draft_iakerbkerberos_u2unegoexclss    r   native_labelsGSSMech.native_labels   sL   
LL&
LL
 NNH
 NN  (	

 j
 ""J
   -
   &&
 ##%7
 ##))+=
 OO\
 OO!!<
   "9
   &&(?
 NNH
  NN  (!
 	
r   c                 >    U R                   (       a  gU R                  $ )Nrt   )is_kerberos_oidnameselfs    r   common_nameGSSMech.common_name   s    yyr   c                     U [         R                  [         R                  [         R                  [         R                  4;   $ )zDetermines if the mech is a Kerberos mech.

Kerberos has been known under serveral OIDs in the past. This tells the caller whether the OID is one of those
"known" OIDs.

Returns:
    bool: Whether the mech is a Kerberos mech (True) or not (False).
)ri   rt   ru   rv   rw   r   s    r   r   GSSMech.is_kerberos_oid   s1     (('*>*>@W@WY`YhYhiiir   oidc                 `    [          H  nUR                  U :X  d  M  Us  $    [        SU -  5      e)zConverts an OID string to a GSSMech value.

Converts an OID string to a GSSMech value if it is known.

Args:
    oid: The OID as a string to convert from.

Raises:
    ValueError: if the OID is not a known GSSMech.
z'%s' is not a valid GSSMech OID)ri   rr   
ValueError)r   mechs     r   from_oidGSSMech.from_oid   s2     DzzS   >DEEr   r3   N)r4   r5   r6   r7   rq   rs   rt   ru   rv   rw   rx   ry   classmethodr(   Dictstrr|   propertyr   r;   r   staticmethodr   r<   r3   r   r   ri   ri      s    #DF &H(L#OG ,L%F
fkk#s(3 
 
( S   	j 	j 	j Fc Fi F Fr   ri   c                      \ rS rSrSrS\R                  \   S\R                  \	   S\R                  \	   S\R                  \
   S\S\	S	\	S
\SS4S jr\S4S j5       r\S4S j5       r\S5S
\R                  \   S\R                  \	   4S jj5       r\S\4S j5       r\\R,                  S\R                  \	   4S j5       5       r\\R,                  S\4S j5       5       r\S\4S j5       r\\R,                  S\R                  \	   4S j5       5       r\\R,                  S\4S j5       5       r\R,                  S6S j5       r\R,                  S\4S j5       r\R,                   S5SS.S\R                  \   S\R                  \
   S\R                  \   4S jjj5       r \R,                  S7S\S\S\R                  \!   S\"4S jj5       r#\R,                    S7S \RH                  \%   S\S\R                  \!   S\&4S! jj5       r'\R,                  S\S\(4S" j5       r)\R,                  S\S\*4S# j5       r+\R,                  S \RH                  \%   S\,4S$ j5       r-\R,                  S%\S\S\4S& j5       r.\R,                  S5S\S\R                  \!   S\4S' jj5       r/\R,                  S\S(\S\!4S) j5       r0\\R,                  S\R                  \Rb                  \\!4      4S* j5       5       r2 S5S+\	S,\Rf                  S\Rf                  4S- jjr4\S\4S. j5       r5S \RH                  \%   S/\Rl                  \7/\84   S\R                  \8   4S0 jr9S8S1\SS4S2 jjr:S3r;g)9ContextProxy   a  Base class for a authentication context.

A base class the defined a common entry point for the various authentication context's that are used in this
library. For a new context to be added it must implement the abstract functions in this class and translate the
calls to what is required internally.

Args:
    credentials: A list of credentials to use for authentication.
    hostname: The principal part of the SPN. This is required for Kerberos auth to build the SPN.
    service: The service part of the SPN. This is required for Kerberos auth to build the SPN.
    channel_bindings: The optional :class:`spnego.channel_bindings.GssChannelBindings` for the context.
    context_req: The :class:`spnego.ContextReq` flags to use when setting up the context.
    usage: The usage of the context, `initiate` for a client and `accept` for a server.
    protocol: The protocol to authenticate with, can be `ntlm`, `kerberos`, or `negotiate`. Not all providers
        support all three protocols as that is handled by :class:`SPNEGOContext`.
    options: The :class:`spnego.NegotiateOptions` that define pyspnego specific options to control the negotiation.

Attributes:
    usage (str): The usage of the context, `initiate` for a client and `accept` for a server.
    protocol (str): The protocol to set the context up with; `ntlm`, `kerberos`, or `negotiate`.
    spn (str): The service principal name of the service to connect to.
    channel_bindings (spnego.channel_bindings.GssChannelBindings): Optional channel bindings to provide with the
        context.
    options (NegotiateOptions): The user specified negotiation options.
    context_req (ContextReq): The context requirements flags as an int value specific to the context provider.
credentialshostnameservicechannel_bindingscontext_requsageprotocoloptionsr   Nc	                 P   UR                  5       U l        U R                  S;  a  [        SU R                  -  5      eUR                  5       U l        U R                  S;  a  [        SU R                  -  5      eU R                  U R	                  US9;  a  [        SU R                  -  5      eX l        X0l        S U l        U(       d  U(       a)  [        U(       a  UOS< SU=(       d    S	< 35      U l        X@l	        [        U5      U l        XPl        S
U l        U R                   H%  u  pXY-  (       d  M  U =R                  U
-  sl        M'     S
U l        SU l        U[        R"                  -  (       a/  U R%                  5       (       d  ['        [        R"                  5      eg g )N)initiateacceptz.Invalid usage '%s', must be initiate or accept)rq   rt   	negotiatecredsspzDInvalid protocol '%s', must be ntlm, kerberos, negotiate, or credssp)r   zProtocol %s is not availableHOST/unspecifiedr   F)lowerr   r   r   available_protocols	_hostname_servicespnr   r   r   r   r   _context_req_context_attr_map_context_attr_is_wrappedwrapping_ioviov_availabler   )r   r   r   r   r   r   r   r   r   genericproviders              r   __init__ContextProxy.__init__  sh    [[]
::33MPTPZPZZ[[ (== LLcfjfsfsstt== 8 8 8 II;dmmKLL!hW'&*H(JcVcJcdeDH 0'0&!%!7!7G$$!!X-! "8  !%2224;M;M;O;O%&6&C&CDD <P2r   c                 6    [         R                  " S[        S9  g )Nzusername is deprecatedcategorywarningswarnDeprecationWarningr   s    r   r   ContextProxy.username3      .9KLr   c                 6    [         R                  " S[        S9  g )Nzpassword is deprecatedr   r   r   s    r   passwordContextProxy.password8  r   r   c                 
    / SQ$ )a  A list of protocols that the provider can offer.

Returns a list of protocols the underlying provider can implement. Currently only kerberos, negotiate, or ntlm
is understood. The protocols that are available for each proxy context depend on the OS platform and what
libraries are installed. See each proxy's `available_protocols` function for more info.

Args:
    options: The context requirements of :class:`NegotiationOptions` that state what the client requires.

Returns:
    List[str]: The list of protocols that the context can use.
)rt   r   rq   r3   )r{   r   s     r   r    ContextProxy.available_protocols=  s
     10r   c                     g)a  Whether the context supports IOV wrapping and unwrapping.

Will return a bool that states whether the context supports IOV wrapping or unwrapping. The NTLM protocol on
Linux does not support IOV and some Linux gssapi implementations do not expose the extension headers for this
function. This gives the caller a sane way to determine whether it can use :meth:`wrap_iov` or
:meth:`unwrap_iov`.

Returns:
    bool: Whether the context provider supports IOV wrapping and unwrapping (True) or not (False).
Tr3   rz   s    r   r   ContextProxy.iov_availableM  s     r   c                     g)a  The principal that was used authenticated by the acceptor.

The name of the client principal that was used in the authentication context. This is `None` when
`usage='initiate'` or the context has not been completed. The format of the principal name is dependent on the
protocol and underlying library that was used to complete the authentication.

Returns:
    Optional[str]: The client principal name.
Nr3   r   s    r   client_principalContextProxy.client_principal[       	r   c                     g)zWhether the context has completed the authentication process.

Will return a bool that states whether the authentication process has completed successfully.

Returns:
    bool: The authentication process is complete (True) or not (False).
Nr3   r   s    r   completeContextProxy.completei  s     	r   c                 z    SnU R                    H  u  p#U R                  U-  (       d  M  X-  nM!     [        U5      $ )a   The context attributes that were negotiated.

This is the context attributes that were negotiated with the counterpart server. These attributes are only
valid once the context is fully established.

Returns:
    ContextReq: The flags that were negotiated.
r   )r   r   rT   )r   attrr   r   s       r   context_attrContextProxy.context_attru  sA     !%!7!7G!!H,, "8 $r   c                     g)an  The name of the negotiated protocol.

Once the authentication process has compeleted this will return the name of the negotiated context that was
used. For pure NTLM and Kerberos this will always be `ntlm` or `kerberos` respectively but for SPNEGO this can
be either of those two.

Returns:
    Optional[str]: The protocol that was negotiated, can be `ntlm`, `kerberos`, or `negotiate. Will be `None`
        for the acceptor until it receives the first token from the initiator. Once the context is establish
        `negotiate` will change to either `ntlm` or `kerberos` to reflect the protocol that was used by SPNEGO.
Nr3   r   s    r   negotiated_protocol ContextProxy.negotiated_protocol       	r   c                     g)aR  The derived session key.

Once the authentication process is complete, this will return the derived session key. It is recommended to not
use this key for your own encryption processes and is only exposed because some libraries use this key in their
protocols.

Returns:
    bytes: The derived session key from the authenticated context.
Nr3   r   s    r   session_keyContextProxy.session_key  r   r   c                     g)a)  Creates a new security context.

Creates a new security context based on the current credential and
options of the current context. This is useful when needing to set up a
new security context without having to retrieve the credentials again.

Returns:
    ContextProxy: The new security context.
Nr3   r   s    r   new_contextContextProxy.new_context  s     	r   c                     g)a{  Gets the important structure sizes for message functions.

Will get the important sizes for the various message functions used by
the current authentication context. This must only be called once the
context has been authenticated.

Returns:
    SecPkgContextSizes: The sizes for the current context.

Raises:
    NoContextError: The security context is not ready to be queried.
Nr3   r   s    r   query_message_sizes ContextProxy.query_message_sizes  r   r   )r   in_tokenc                    g)a  Performs a negotiation step.

This method performs a negotiation step and processes/generates a token. This token should be then sent to the
counterpart context to continue the authentication process.

This should not be called once :meth:`complete` is True as the security context is complete.

For the initiator this is equivalent to `gss_init_sec_context`_ for GSSAPI and `InitializeSecurityContext`_ for
SSPI.

For the acceptor this is equivalent to `gss_accept_sec_context`_ for GSSAPI and `AcceptSecurityContext`_ for
SSPI.

Args:
    in_token: The input token to process (or None to process no input token).
    channel_bindings: Optional channel bindings ot use in this step. Will take priority over channel bindings
        set in the context if both are specified.

Returns:
    Optional[bytes]: The output token (or None if no output token is generated.

.. _gss_init_sec_context:
    https://tools.ietf.org/html/rfc2744.html#section-5.19

.. _InitializeSecurityContext:
    https://docs.microsoft.com/en-us/windows/win32/api/sspi/nf-sspi-initializesecuritycontextw

.. _gss_accept_sec_context:
    https://tools.ietf.org/html/rfc2744.html#section-5.1

.. _AcceptSecurityContext:
    https://docs.microsoft.com/en-us/windows/win32/api/sspi/nf-sspi-acceptsecuritycontext
Nr3   )r   r   r   s      r   stepContextProxy.step  s    P 	r   r1   encryptrK   c                     g)a   Wrap a message, optionally with encryption.

This wraps a message, signing it and optionally encrypting it. The :meth:`unwrap` will unwrap a message.

This is the equivalent to `gss_wrap`_ for GSSAPI and `EncryptMessage`_ for SSPI.

The SSPI function's `EncryptMessage`_ is called with the following buffers::

    SecBufferDesc(SECBUFFER_VERSION, [
        SecBuffer(SECBUFFER_TOKEN, sizes.cbSecurityTrailer, b""),
        SecBuffer(SECBUFFER_DATA, len(data), data),
        SecBuffer(SECBUFFER_PADDING, sizes.cbBlockSize, b""),
    ])

Args:
    data: The data to wrap.
    encrypt: Whether to encrypt the data (True) or just wrap it with a MIC (False).
    qop: The desired Quality of Protection (or None to use the default).

Returns:
    WrapResult: The wrapped result which contains the wrapped message and whether it was encrypted or not.

.. _gss_wrap:
    https://tools.ietf.org/html/rfc2744.html#section-5.33

.. _EncryptMessage:
    https://docs.microsoft.com/en-us/windows/win32/secauthn/encryptmessage--general
Nr3   )r   r1   r   rK   s       r   wrapContextProxy.wrap      < 	r   iovc                     g)a  Wrap/Encrypt an IOV buffer.

This method wraps/encrypts an IOV buffer. The IOV buffers control how the data is to be processed. Because
IOV wrapping is an extension to GSSAPI and not implemented for NTLM on Linux, this method may not always be
available to the caller. Check the :meth:`iov_available` property.

This is the equivalent to `gss_wrap_iov`_ for GSSAPI and `EncryptMessage`_ for SSPI.

Args:
    iov: A list of :class:`spnego.iov.IOVBuffer` buffers to wrap.
    encrypt: Whether to encrypt the message (True) or just wrap it with a MIC (False).
    qop: The desired Quality of Protection (or None to use the default).

Returns:
    IOVWrapResult: The wrapped result which contains the wrapped IOVBuffer bytes and whether it was encrypted
        or not.

.. _gss_wrap_iov:
    http://k5wiki.kerberos.org/wiki/Projects/GSSAPI_DCE

.. _EncryptMessage:
    https://docs.microsoft.com/en-us/windows/win32/secauthn/encryptmessage--general
Nr3   )r   r   r   rK   s       r   wrap_iovContextProxy.wrap_iov  r   r   c                     g)zWrap/Encrypt data for use with WinRM.

This method wraps/encrypts bytes for use with WinRM message encryption.

Args:
    data: The data to wrap.

Returns:
    WinRMWrapResult: The wrapped result for use with WinRM message encryption.
Nr3   r   r1   s     r   
wrap_winrmContextProxy.wrap_winrm+  r   r   c                     g)a  Unwrap a message.

This unwraps a message created by :meth:`wrap`.

This is the equivalent to `gss_unwrap`_ for GSSAPI and `DecryptMessage`_ for SSPI.

The SSPI function's `DecryptMessage`_ is called with the following buffers::

    SecBufferDesc(SECBUFFER_VERSION, [
        SecBuffer(SECBUFFER_STREAM, len(data), data),
        SecBuffer(SECBUFFER_DATA, 0, b""),
    ])

Args:
    data: The data to unwrap.

Returns:
    UnwrapResult: The unwrapped message, whether it was encrypted, and the QoP used.

.. _gss_unwrap:
    https://tools.ietf.org/html/rfc2744.html#section-5.31

.. _DecryptMessage:
    https://docs.microsoft.com/en-us/windows/win32/secauthn/decryptmessage--general
Nr3   r   s     r   unwrapContextProxy.unwrap9  s    6 	r   c                     g)a  Unwrap/Decrypt an IOV buffer.

This method unwraps/decrypts an IOV buffer. The IOV buffers control how the data is to be processed. Because
IOV wrapping is an extension to GSSAPI and not implemented for NTLM on Linux, this method may not always be
available to the caller. Check the :meth:`iov_available` property.

This is the equivalent to `gss_unwrap_iov`_ for GSSAPI and `DecryptMessage`_ for SSPI.

Args:
    iov: A list of :class:`spnego.iov.IOVBuffer` buffers to unwrap.

Returns:
    IOVUnwrapResult: The unwrapped buffer bytes, whether it was encrypted, and the QoP used.

.. _gss_unwrap_iov:
    http://k5wiki.kerberos.org/wiki/Projects/GSSAPI_DCE

.. _DecryptMessage:
    https://docs.microsoft.com/en-us/windows/win32/secauthn/decryptmessage--general
Nr3   )r   r   s     r   
unwrap_iovContextProxy.unwrap_iovV  s    2 	r   rE   c                     g)a\  Unwrap/Decrypt a WinRM message.

This method unwraps/decrypts a WinRM message. It handles the complexities of unwrapping the data and dealing
with the various system library calls.

Args:
    header: The header portion of the WinRM wrapped result.
    data: The data portion of the WinRM wrapped result.

Returns:
    bytes: The unwrapped message.
Nr3   )r   rE   r1   s      r   unwrap_winrmContextProxy.unwrap_winrmq  r   r   c                     g)a  Generates a signature/MIC for a message.

This method generates a MIC for the given data. This is unlike wrap which bundles the MIC and the message
together. The :meth:`verify` method can be used to verify a MIC.

This is the equivalent to `gss_get_mic`_ for GSSAPI and `MakeSignature`_ for SSPI.

Args:
    data: The data to generate the MIC for.
    qop: The desired Quality of Protection (or None to use the default).

Returns:
    bytes: The MIC for the data requested.

.. _gss_get_mic:
    https://tools.ietf.org/html/rfc2744.html#section-5.15

.. _MakeSignature:
    https://docs.microsoft.com/en-us/windows/win32/api/sspi/nf-sspi-makesignature
Nr3   )r   r1   rK   s      r   signContextProxy.sign      , 	r   micc                     g)a  Verify the signature/MIC for a message.

Will verify that the given MIC matches the given data. If the MIC does not match the given data, an exception
will be raised. The :meth:`sign` method can be used to sign data.

This is the equivalent to `gss_verify_mic`_ for GSSAPI and `VerifySignature`_ for SSPI.

Args:
    data: The data to verify against the MIC.
    mic: The MIC to verify against the data.

Returns:
    int: The QoP (Quality of Protection) used.

.. _gss_verify_mic:
    https://tools.ietf.org/html/rfc2744.html#section-5.32

.. _VerifySignature:
    https://docs.microsoft.com/en-us/windows/win32/api/sspi/nf-sspi-verifysignature
Nr3   )r   r1   r   s      r   verifyContextProxy.verify  r   r   c                     g)aw  Map the generic ContextReq into the provider specific flags.

Will return a list of tuples that give the provider specific flag value for the generic ContextReq that is
exposed to end users.

Returns:
    List[Tuple[ContextReq, int], ...]: A list of tuples where tuple[0] is the ContextReq flag and tuple[1] is
        the relevant provider specific flag for our common one.
Nr3   r   s    r   r   ContextProxy._context_attr_map  r   r   r   rg   c                     U$ )a  Return information about the security context.

Returns extra information about the security context that is not defined
as part of the standard :class:`ContextProxy` attributes or properties.
By default there is no context specific information and it's up to the
sub classes to implement their own.

These names can be queried for a CredSSP context.

    client_credential:
        Used on an `acceptor` CredSSP context and contains the delegated
        credential sent by the client to the server. This is only
        available once the context is complete otherwise the default
        value is returned. The types returned can be
        :class:`TSPasswordCreds`, :class:`TSSmartCardCreds`, or
        :class:`TSRemoteGuardCreds`.

    sslcontext:
        The :class:`ssl.SSLContext` instance used for the CredSSP
        context.

    ssl_object:
        The :class:`ssl.SSLObject` instance used for the CredSSP
        context.

    auth_stage - added in 0.5.0:
        A string representing that sub authentication stage being
        performed in the CredSSP authentication stepping. The value
        here is meant to be a human friendly representation and not
        something to be relied upon.

    protocol_version - added in 0.5.0:
        The CredSSP protocol version that was negotiated between the
        initiator and acceptor. This is the minimum version number
        offered by both parties once the Negotiate authentication stage
        is complete.

Args:
    name: The name/id of the information to retrieve.
    default: The default value to return if the information is not
        available on the current context proxy.

Args:
    name: The name/id of the information to retrieve.
    default: The default value to return if the information is not
        available on the current context proxy.

Returns:
    The information requested or the default value specified if the
    information isn't found.
r3   )r   r   rg   s      r   get_extra_infoContextProxy.get_extra_info  s
    p r   c                     g)a  Determine if the SPNEGO mechListMIC is required for the sec context.

When Microsoft hosts deal with NTLM through SPNEGO it always wants the mechListMIC to be present when the NTLM
authentication message contains a MIC. This goes against RFC 4178 as a mechListMIC shouldn't be required if
NTLM was the preferred mech from the initiator but we can't do anything about that now. Because we exclusively
use SSPI on Windows hosts, which does all the work for us, this function only matter for Linux hosts when this
library manually creates the SPNEGO token.

The function performs 2 operations. When called before the NTLM authentication message has been created it
tells the gss-ntlmssp mech that it's ok to generate the MIC. When the authentication message has been created
it returns a bool stating whether the MIC was present in the auth message and subsequently whether we need to
include the mechListMIC in the SPNEGO token.

See `mech_required_mechlistMIC in MIT KRB5`_ for more information about how MIT KRB5 deals with this.

Returns:
    bool: Whether the SPNEGO mechListMIC needs to be generated or not.

.. _mech_requires_mechlistMIC:
    https://github.com/krb5/krb5/blob/b2fe66fed560ae28917a4acae6f6c0f020156353/src/lib/gssapi/spnego/spnego_mech.c#L493
Fr3   r   s    r   _requires_mech_list_mic$ContextProxy._requires_mech_list_mic  s    . r   native_convertc                 @   / nU GH  n[        U[        5      (       a  [        U5      S:w  a  [        S5      e[        US   [        5      (       d  [        S5      eUS   nUS   b.  [        US   [
        [        [        45      (       d  [        S5      eUS   b  US   OSnOM[        U[        5      (       a  UnSnO3[        U[
        5      (       a  [        R                  nUnO[        S	5      e[        [        U5      US
9nUR                  U" U5      5        GM     U$ )z=Creates a list of IOV buffers for the native provider needed.rV   zHIOV entry tuple must contain 2 values, the type and data, see IOVBuffer.r   z2IOV entry[0] must specify the BufferType as an intr   NzbIOV entry[1] must specify the buffer bytes, length of the buffer, or whether it is auto allocated.r   z2IOV entry must be a IOVBuffer tuple, int, or bytes)typer1   )
isinstancetuplelenr   rG   r9   r;   r	   r1   r
   append)r   r   r  provider_ioventrybuffer_typer1   
iov_buffers           r   _build_iov_listContextProxy._build_iov_list  s    02E%''u:?$%opp!%(C00$%YZZ#Ah8'
58eSRVEW0X0X$0  $)8#7uQxSE3''#E5))(oo !!UVV"
;(?dKJz :;; > r   outgoingc                     g)aF  Reset the NTLM crypto handles after signing/verifying the SPNEGO mechListMIC.

`MS-SPNG`_ documents that after signing or verifying the mechListMIC, the RC4 key state needs to be the same
for the mechListMIC and for the first message signed/sealed by the application. Because we use SSPI on Windows
hosts which does all the work for us this function only matters for Linux hosts.

Args:
    outgoing: Whether to reset the outgoing or incoming RC4 key state.

.. _MS-SPNG:
    https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-spng/b87587b3-9d72-4027-8131-b76b5368115f
Nr3   )r   r  s     r   _reset_ntlm_crypto_state%ContextProxy._reset_ntlm_crypto_state;  s     	r   )r   r   r   r   r   r   r   r   r   r   r   )r   NN)r   r   )TN)T)<r4   r5   r6   r7   r8   r(   Listr   Optionalr   r   rT   r   r   r   r   r   r   r   r;   r   abcabstractmethodr   r   r   r   r9   r   r   rQ   r   r   rG   r/   r   IterableIOVr>   r   rC   r   rI   r   rM   r   r   r   r   rA   r   r)   r  r  Callabler
   r   r  r  r<   r3   r   r   r   r      s   6+E[[,+E //#&+E %	+E
 !//*<=+E  +E +E +E "+E 
+EZ     1&//:J*K 1W]WbWbcfWg 1 1 d   
&//#"6 
  
 $     j      V__S%9    
U 
  
 	
 
 	%7   	 ,0' AE	'//%(' !//*<=	'
 
	' 'R 	  6??3;O [e  > 	 $(	__S!  __S!	
 
 > 	u    	5 \  8 	__S! 
 4 	5  %   	 V__S%9 U  . 	5 u   2 
6;;v||JO/L#M 
  
 #88 8 
	8t   0%??3'%9?)V_I_9`%	Y	%N   r   r   )	metaclassr  )1r  dataclassesenumr(   r   spnego._credentialr   spnego._textr   spnego.channel_bindingsr   spnego.exceptionsr   r   r   
spnego.iovr	   r
   r   TypeVarr  r)   r   r   UnionrA   rG   r;   r9   r  r  r   r   Typer-   
NamedTupler/   r>   rC   rI   rM   	dataclassrQ   IntFlagrT   Enumri   ABCMetar   r3   r   r   <module>r/     s        )   6 P P : :
NN3fooc6::o>?NN;fjj9	ll
LLj#o.T5#=M0NNO
LLS!		ZV__S1 Zfll6??SVCWY_YhYhilYmCm6n Z2&++ 8L X^XgXgijhkmnhnXo 4"" F%% f'' 6$$ f''  d#  $(M M0FFc499 FFR^	S[[ ^	r   