
    i;                     j   % S SK r S SKr\R                  \   \S'    S SKJr  \R                  \   \S'    \	r
 " S S\5      r " S S\ R                  5      r " S	 S
\5      r " S S\ R                   5      r " S S\5      r " S S\\S9r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S  S!\5      r " S" S#\5      r " S$ S%\5      r " S& S'\5      r " S( S)\5      r g! \ a  r\r SrCNSrCff = f! \ a    \r
 Nf = f)*    NGSSError)r   WinErrorc                   B    \ rS rSrSrS\S\R                  SS4S jrSr	g)	NativeError   zeStub for a native error that can be used to generate a SpnegoError from a known platform native code.msgkwargsreturnNc                 L    Xl         S H  nX2;   d  M
  [        XX#   5        M     g )N)maj_codewinerror)r   setattr)selfr   r	   keys       K/home/james-whalen/.local/lib/python3.13/site-packages/spnego/exceptions.py__init__NativeError.__init__   s"    +C}6;/ ,    )r   )
__name__
__module____qualname____firstlineno____doc__strtypingAnyr   __static_attributes__ r   r   r   r      s#    o0C 06:: 0$ 0r   r   c                   <    \ 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)NegotiateOptions   a:  Flags that the caller can use to control the negotiation behaviour.

A list of features as bit flags that the caller can specify when creating the security context. These flags can
be used on both Windows or Linux but are a no-op on Windows as it should always have the same features available.
On Linux the features it can implement depend on a wide range of factors like the system libraries/headers that
are installed, what GSSAPI implementation is present, and what Python libraries are available.

This is a pretty advanced feature and is mostly a way to control the kerberos to ntlm fallback behaviour on Linux.
The `use_*` options when combined with `protocol='credssp'` control the underlying auth proxy provider that is used
in the CredSSP authentication process and not the parent context proxy the user interacts with.

These are the currently implemented feature flags:

use_sspi:
    Ensures the context proxy used is :class:`spnego._sspi.SSPIProxy`.

use_gssapi:
    Ensures the context proxy used is :class:`spnego._gss.GSSAPIProxy`.

use_negotiate:
    Ensures the context proxy used is :class:`spnego._negotiate.NegotiateProxy`.

use_ntlm:
    Ensures the context proxy used is :class:`spnego._ntlm.NTLMProxy`.

negotiate_kerberos:
    Will make sure that Kerberos is at least available to try for authentication when using the `negotiate`
    protocol. If Kerberos cannot be used due to the Python gssapi library not being installed then it will raise a
    :class:`spnego.exceptions.FeatureMissingError`. If Kerberos was available but it cannot get a credential or
    create a context then it will just fallback to NTLM auth. If you wish to only use Kerberos with no NTLM
    fallback, set `protocol='kerberos'` when creating the security context.

session_key:
    Ensure that the authenticated context will be able to return the session key that was negotiated between the
    client and the server. Older versions of `gss-ntlmssp`_ do not expose the functions required to retrieve this
    info so when this feature flag is set then the NTLM fallback process will use a builtin NTLM process and not
    `gss-ntlmssp`_ if the latter is too old to retrieve the session key. Cannot be used in combination with
    `protocol='credssp'` as CredSSP does not provide a session key.

wrapping_iov:
    The GSSAPI IOV methods are extensions to the Kerberos spec and not implemented or exposed on all platforms,
    macOS is a popular example. If the caller requires the wrap_iov and unwrap_iov methods this will ensure it
    fails fast before the auth has been set up. Unfortunately there is no fallback for this as if the headers
    aren't present for GSSAPI then we can't do anything to fix that. This won't fail if `negotiate` was used and
    NTLM was the chosen protocol as that happens post negotiation.

wrapping_winrm:
    To created a wrapped WinRM message the IOV extensions are required when using Kerberos auth. Setting this flag
    will skip Kerberos when `protocol='negotiate'` if the IOV headers aren't present and just fallback to NTLM.

.. _gss-ntlmssp:
    https://github.com/gssapi/gss-ntlmssp
r                      @      r   N)r   r   r   r   r   noneuse_sspi
use_gssapiuse_negotiateuse_ntlmnegotiate_kerberossession_keywrapping_iovwrapping_winrmr   r   r   r   r    r       s:    4l D HJMH#KLNr   r    c                   R    \ rS rSr\S\4S j5       r\S\4S j5       rS\4S jr	Sr
g)FeatureMissingErrorc   r
   c                      U R                   S   $ )Nr   )argsr   s    r   
feature_idFeatureMissingError.feature_idd   s    yy|r   c                     [         R                  S[         R                  S[         R                  S[         R                  S0R                  U R                  SU R                  -  5      nU$ )NzLThe Python gssapi library is not installed so Kerberos cannot be negotiated.z|The system is missing the GSSAPI IOV extension headers or CredSSP is being requested, cannot utilize wrap_iov and unwrap_iovzcThe system is missing the GSSAPI IOV extension headers required for WinRM encryption with Kerberos.z?The protocol selected does not support getting the session key.zUnknown option flag: %d)r    r/   r1   r2   r0   getr9   )r   r   s     r   messageFeatureMissingError.messageh   sh     // 2)) ,F++ ..((*k
 #doo84??J
K 	 
r   c                     U R                   $ N)r=   r8   s    r   __str__FeatureMissingError.__str__v   s    ||r   r   N)r   r   r   r   propertyr    r9   r   r=   rA   r   r   r   r   r4   r4   c   sC    ,      r   r4   c                   L    \ 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SrSrg)	ErrorCodez   a]  Common error codes for SPNEGO operations.

Mostly a copy of the `GSS major error codes`_ with the names made more pythonic. Not all codes have a corresponding
SpnegoError class as they are reserved for the codes that apply to both GSSAPI and SSPI.

.. _GSS major error codes:
    https://docs.oracle.com/cd/E19683-01/816-1331/reference-4/index.html
r"   r#   r$         r%   	   
               r&   r   N)r   r   r   r   r   bad_mechbad_namebad_bindingsbad_micno_cred
no_contextinvalid_tokeninvalid_credentialcredentials_expiredcontext_expiredfailurebad_qopunavailabler   r   r   r   rE   rE   z   sL     HHLGGJMOGGKr   rE   c                   |  ^  \ rS rSr% 0 r\R                  \\R                  4   \	S'   0 r
\R                  \\4   \	S'   0 r\R                  \\4   \	S'   S\R                  S\R                  SS4S	 jr  SS
\R                  \   S\R                  \   S\R                  S\R                  SS 4
U 4S jjjrSrU =r$ )_SpnegoErrorRegistry   _SpnegoErrorRegistry__registry _SpnegoErrorRegistry__gssapi_map_SpnegoErrorRegistry__sspi_mapr7   r	   r
   Nc                 2   [        U SS 5      nUb  X0R                  ;  a  X R                  U'   SU R                  4SU R                  44 HJ  u  pE[        XS 5      nUc  M  [	        U[
        [        45      (       d  U/nU H  nU=(       d    SXW'   M     ML     g )N
ERROR_CODE_GSSAPI_CODE
_SSPI_CODEr   )getattrr_   r`   ra   
isinstancelisttuple)clsr7   r	   
error_codesystem_attrmappingcodescs           r   r   _SpnegoErrorRegistry.__init__   s     S,5
!j&F),NN:& '5c6F6F%G,X[XfXfIg$h KCd3E}edE]33'_1
  %ir   rk   
base_errorc                   > Ub  UO[        U SS 5      nUc  U(       d  [        SU R                  -  5      e[        USS 5      n[        USS 5      nUb  U R                  R	                  US 5      nOAUb  U R
                  R	                  US 5      nO![        S[        U5      R                  -  5      eU R                  R	                  U=(       d    SU 5      n[        [        U]*  " UU/UQ70 UD6$ )Nrc   z.%s requires either an error_code or base_errorr   r   z^base_error of type '%s' is not supported, must be a gssapi.exceptions.GSSError or WindowsErrorr   )rf   
ValueErrorr   r`   r<   ra   typer_   superr]   __call__)	rj   rk   rq   r7   r	   r   r   new_cls	__class__s	           r   rv   _SpnegoErrorRegistry.__call__   s    $.#9ZwsLZ^?_
 !QTWT`T`!`aa z:t<Hz:t<H# --11(DA
% ^^//$?
 !#%)*%5%>%>? 
 ..$$Z_1c:)7<
 
 	
 	
r   r   )NN)r   r   r   r   r_   r   DictintType__annotations__r`   ra   r   r   Optional	Exceptionrv   r   __classcell__rx   s   @r   r]   r]      s    02JC,-2*,L&++c3h',(*JCH%*-zz- **- 
	-4 ,015$
OOC($
 OOI.$
 zz	$

 **$
 
 $
 $
r   r]   c            	          ^  \ rS rSrSr   SS\R                  \R                  \\	4      S\R                  \
   S\R                  \   SS4U 4S jjjr\S\4S	 j5       r\S\4S
 j5       rSrU =r$ )SpnegoError   av  Common error for SPNEGO exception.

Creates an common error record for SPNEGO errors raised by pyspnego. This error record can wrap system level error
records raised by GSSAPI or SSPI and wrap them into a common error record across the various platforms. While this
reflects the GSSAPI major codes that can be raised, it is up to the GSSAPI platform to conform to those error
codes. Some platforms like MIT krb5 always report `GSS_S_FAILURE` and use the minor code to report the actual
error message.

Args:
    error_code: The ErrorCode for the error, this must be set if base_error is not set.
    base_error: The system level error from SSPI or GSSAPI, this must be set if error_code is not set.
    context_msg: Optional message to provide more context around the error.

Attributes:
    base_error (Optional[Union[GSSError, WinError]]): The system level error if one was provided.
Nrk   rq   context_msgr
   c                 d   > X l         Xl        X0l        [        [        U ]  U R                  5        g r@   )rq   _error_code_context_messageru   r   r   r=   )r   rk   rq   r   rx   s       r   r   SpnegoError.__init__   s)     %% +k4)$,,7r   c                     [        U SU R                  5      =(       d    Sn[        U[        [        45      (       a  US   $ U$ )z6The Windows NT Status code that represents this error.re       r   )rf   r   rg   rh   ri   )r   rn   s     r   	nt_statusSpnegoError.nt_status  s<     lD,<,<=K%edE];;uQxFFr   c                     U R                   b  U R                   OSnU R                  (       a  [        U R                  5      nO[        U SS5      nSX4-  nU R                  (       a  USU R                  -  -  nU$ )Nr   _BASE_MESSAGEzUnknown error codezSpnegoError (%d): %sz, Context: %s)r   rq   r   rf   r   )r   rk   base_messager   s       r   r=   SpnegoError.message  sp    )-)9)9)ET%%:
??t/L #4:NOL$
'AA  ?T%:%:::C
r   )r   r   rq   )NNN)r   r   r   r   r   r   r~   Unionr{   rE   r   r   r   rC   r   r=   r   r   r   s   @r   r   r      s    8 EI15,0	
8OOFLLi$@A
8 OOI.
8 __S)	
8
 

8 
8 G3 G G
   r   r   )	metaclassc                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)BadMechanismErrori  z&An unsupported mechanism was requestedi   i	r   N)r   r   r   r   rE   rO   rc   r   rd   re   r   r   r   r   r   r     s    ##J<MLJr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)BadNameErrori$  zAn invalid name was suppliedi  i	r   N)r   r   r   r   rE   rP   rc   r   rd   re   r   r   r   r   r   r   $  s    ##J2MLJr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)BadBindingsErrori,  zInvalid channel bindingsi   iF	r   N)r   r   r   r   rE   rQ   rc   r   rd   re   r   r   r   r   r   r   ,  s    ''J.MLJr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)BadMICErrori4  z4A token had an invalid Message Integrity Check (MIC)i < i	r   N)r   r   r   r   rE   rR   rc   r   rd   re   r   r   r   r   r   r   4  s    ""JJMLJr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)NoCredentialErrori<  zQNo credentials were supplied, or the credentials were unavailable or inaccessiblei   i	r   N)r   r   r   r   rE   rS   rc   r   rd   re   r   r   r   r   r   r   <  s    ""JgMLJr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)NoContextErroriD  z=No context has been established, or invalid handled passed ini   i	r   N)r   r   r   r   rE   rT   rc   r   rd   re   r   r   r   r   r   r   D  s    %%JSMLJr   r   c                   <    \ rS rSr\R
                  rSrSrSS/r	Sr
g)InvalidTokenErroriL  z,A token was invalid, or the logon was deniedi  	 i	i	r   N)r   r   r   r   rE   rU   rc   r   rd   re   r   r   r   r   r   r   L  s!    ((JBML{+Jr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)InvalidCredentialErroriT  zA credential was invalidi  
 im  r   N)r   r   r   r   rE   rV   rc   r   rd   re   r   r   r   r   r   r   T  s    --J.MLJr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)CredentialsExpiredErrori\  z'The referenced credentials have expiredi   iq  r   N)r   r   r   r   rE   rW   rc   r   rd   re   r   r   r   r   r   r   \  s    ..J=MLJr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)ContextExpiredErrorid  zSecurity context has expiredi   i	r   N)r   r   r   r   rE   rX   rc   r   rd   re   r   r   r   r   r   r   d  s    **J2MLJr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)UnsupportedQopil  z9The quality-of-protection requested could not be providedi   i
	r   N)r   r   r   r   rE   rZ   rc   r   rd   re   r   r   r   r   r   r   l  s    ""JOMLJr   r   c                   8    \ rS rSr\R
                  rSrSrSr	Sr
g)OperationNotAvailableErrorit  z$Operation not supported or availablei   i	r   N)r   r   r   r   rE   r[   rc   r   rd   re   r   r   r   r   r   r   t  s    &&J:MLJr   r   )!enumr   r|   r   r}   
gssapi.rawr   ImportErroreWindowsErrorr   	NameErrorr   IntFlagr    r4   IntEnumrE   rt   r]   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      sW    
++i
   # ++i
   H
0) 0B t|| B J) . @A
4 A
H;)'; ;| ; { +  [ , ,[ k + [  U  H  Hs(   D D' D$DD$'D21D2