o
    j                     @   sJ   d dl mZmZ d dlmZmZ d dlmZ d dlm	Z	 G dd dZ
dS )    )WinSSPISSPIPackage)ISC_REQ
SSPIResult)NTLMClientNative)NTLMCredentialc                   @   s   e Zd ZdefddZedd Zdd Zd+d	d
Zd+ddZ	dd Z
d,ddZd-ddZdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d Z
d,d'dZd.d)d*ZdS )/NTLMClientSSPI
credentialc                 C   s0   || _ ttj| _d | _t| j | _tj	| _
d S N)r	   r   r   NTLMsspisession_keyr   ntlm_ctxr   
CONNECTIONflags)selfr	    r   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/asyauth/protocols/ntlm/client/sspi.py__init__   s
   zNTLMClientSSPI.__init__c                 C      | j jS r
   )r   ntlmChallenger   r   r   r   r      s   zNTLMClientSSPI.ntlmChallengec                 C   r   r
   )r   
seq_numberr   r   r   r   get_seq_number   s   zNTLMClientSSPI.get_seq_numberClientc                 C      | j j|dS N)mode)r   get_sealkeyr   r   r   r   r   r         zNTLMClientSSPI.get_sealkeyc                 C   r   r   )r   get_signkeyr   r   r   r   r!      r    zNTLMClientSSPI.get_signkeyc                    s   | j |||I d H S r
   r   encrypt)r   datasequence_nor   r   r   r#      s   zNTLMClientSSPI.encryptinitNc                       | j j||||dI d H S N)	direction	auth_datar   decryptr   r$   r%   r)   r*   r   r   r   r,         zNTLMClientSSPI.decryptFc                    r'   )N)r)   reset_cipher)r   sign)r   r$   
message_nor)   r/   r   r   r   r0   !   r.   zNTLMClientSSPI.signc                       | j ||I d H S r
   )r   verify)r   r$   	signaturer   r   r   r3   $      zNTLMClientSSPI.verifyc                 C   s   | j ||||||S r
   )r   SEAL)r   
signingKey
sealingKeymessageToSignmessageToEncryptseqNumcipher_encryptr   r   r   r6   '   s   zNTLMClientSSPI.SEALc                 C   s   | j ||||S r
   )r   SIGN)r   r7   messager;   r<   r   r   r   r=   *   s   zNTLMClientSSPI.SIGNc                 C   s   | j s	| j | _ | j S r
   )r   r   get_session_keyr   r   r   r   r?   -   s   zNTLMClientSSPI.get_session_keyc                 C   
   | j  S r
   )r   get_extra_infor   r   r   r   rA   3      
zNTLMClientSSPI.get_extra_infoc                 C   r@   r
   )r   is_extended_securityr   r   r   r   rC   6   rB   z#NTLMClientSSPI.is_extended_securityc                 C   r@   r
   )r   signing_neededr   r   r   r   rD   9   rB   zNTLMClientSSPI.signing_neededc                 C   r@   r
   )r   encryption_neededr   r   r   r   rE   <   rB   z NTLMClientSSPI.encryption_neededc                    r2   r
   r"   )r   r$   r1   r   r   r   r#   ?   r5   c                    r'   r(   r+   r-   r   r   r   r,   B   r.   r   c                    s   d}|d u r
| j }|d u r6| jd | | jj||||d\}}	| _ }
|tjkr+d}| j|	 |	|d fS | j| | jj||||d\}}	| _ }
|tjkrRd}| j	|	 | j
|   |	|d fS )NF)r   cb_dataT)r   r   acquire_handleinitialize_contextr   CONTINUEr   load_negotiateload_challengeload_authenticateload_sessionkeyr?   )r   authDatar   r   spnrF   kwargsto_continueresultr$   expiryr   r   r   authenticateE   s$   



zNTLMClientSSPI.authenticate)r   )r&   N)NF)NNr   NN)__name__
__module____qualname__r   r   propertyr   r   r   r!   r#   r,   r0   r3   r6   r=   r?   rA   rC   rD   rE   rT   r   r   r   r   r      s*    





r   N)asyauth.common.winapi.winsspir   r   asyauth.common.winapi.constantsr   r   $asyauth.protocols.ntlm.client.nativer   asyauth.common.credentials.ntlmr   r   r   r   r   r   <module>   s
    