o
    �õ±j„  ã                   @   sJ   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ G dd„ dƒZ	dS )é    N)Úlogger)ÚNTLMClientNative)ÚISC_REQ)ÚWSNETDirectAuthc                   @   sÂ   e Zd Zdd„ Z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)efd*d+„ZdS )0ÚNTLMClientWSNETDirectc                 C   s8   t  d¡ ¡ | _|| _d | _d| _d | _t| jƒ| _	d S )Né   r   )
ÚosÚurandomÚhexÚ_authidÚ
credentialÚsspiÚ
iterationsÚsession_keyr   Úntlm_ctx)Úselfr   © r   úœ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/asyauth/protocols/ntlm/client/wsnetdirect.pyÚ__init__   s   zNTLMClientWSNETDirect.__init__c                 C   s   d S ©Nr   ©r   r   r   r   Úsetup   s   zNTLMClientWSNETDirect.setupc                 C   ó   | j jS r   )r   ÚntlmChallenger   r   r   r   r      s   z#NTLMClientWSNETDirect.ntlmChallengec                 C   r   r   )r   Ú
seq_numberr   r   r   r   Úget_seq_number   s   z$NTLMClientWSNETDirect.get_seq_numberÚClientc                 C   ó   | j j|d�S ©N)Úmode)r   Úget_sealkey©r   r   r   r   r   r       ó   z!NTLMClientWSNETDirect.get_sealkeyc                 C   r   r   )r   Úget_signkeyr!   r   r   r   r#   !   r"   z!NTLMClientWSNETDirect.get_signkeyc                 Ã   s   �| j  |||¡I d H S r   ©r   Úencrypt)r   ÚdataÚsequence_nor   r   r   r%   $   s   €zNTLMClientWSNETDirect.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NTLMClientWSNETDirect.decryptFc                 Ã   r)   )N)r+   Úreset_cipher)r   Úsign)r   r&   Ú
message_nor+   r1   r   r   r   r2   *   r0   zNTLMClientWSNETDirect.signc                 Ã   ó   �| j  ||¡I d H S r   )r   Úverify)r   r&   Ú	signaturer   r   r   r5   -   ó   €zNTLMClientWSNETDirect.verifyc                 C   s   | j  ||||||¡S r   )r   ÚSEAL)r   Ú
signingKeyÚ
sealingKeyÚmessageToSignÚmessageToEncryptÚseqNumÚcipher_encryptr   r   r   r8   0   s   zNTLMClientWSNETDirect.SEALc                 C   s   | j  ||||¡S r   )r   ÚSIGN)r   r9   Úmessager=   r>   r   r   r   r?   3   s   zNTLMClientWSNETDirect.SIGNc                 C   s   | j S r   )r   r   r   r   r   Úget_session_key6   s   z%NTLMClientWSNETDirect.get_session_keyc                 C   ó
   | j  ¡ S r   )r   Úget_extra_infor   r   r   r   rC   9   ó   
z$NTLMClientWSNETDirect.get_extra_infoc                 C   rB   r   )r   Úis_extended_securityr   r   r   r   rE   <   rD   z*NTLMClientWSNETDirect.is_extended_securityc                 C   rB   r   )r   Úsigning_neededr   r   r   r   rF   ?   rD   z$NTLMClientWSNETDirect.signing_neededc                 C   rB   r   )r   Úencryption_neededr   r   r   r   rG   B   rD   z'NTLMClientWSNETDirect.encryption_neededc                 Ã   r4   r   r$   )r   r&   r3   r   r   r   r%   E   r7   c                 Ã   r)   r*   r-   r/   r   r   r   r.   H   r0   Úflagsc              
   Ë   sª  ��z:|d u r
t j}t d| j|f ¡ t d| j|f ¡ t d| j|f ¡ | jd u rFt| jj 	¡ ƒ| _| j 
¡ I d H \}}|d urF|‚|d u r�t d| j ¡ | jjdddd|jdd	�I d H \}}	}
}|d url|‚t d
| j|f ¡ t d| j|	f ¡ t d| j|
f ¡ |  jd7  _| j |
¡ |
dd fW S t d| j|f ¡ | j |¡ t d| j ¡ | jjdddd|j|d	�I d H \}}	}}|d urÏ|‚| j |¡ t d
| j|f ¡ t d| j|	f ¡ t d| j|f ¡ t d| j ¡ | j ¡ I d H \| _}|d u�r|‚t d| j| j ¡ f ¡ | j |  ¡ ¡ t d| j| j ¡ f ¡ | j ¡ I d H  |dd fW S  t�yT } zd d |fW  Y d }~S d }~ww )Nz[WSNETDirect][NTLM][%s] spn: %sz![WSNETDirect][NTLM][%s] flags: %sz#[WSNETDirect][NTLM][%s] cb_data: %szE[WSNETDirect][NTLM][%s] Initializing auth context, fetching NegotaiteÚNTLMÚ é   ó    )Úauthdataz,[WSNETDirect][NTLM][%s][Response] Status: %sz4[WSNETDirect][NTLM][%s][Response] Response flags: %sz/[WSNETDirect][NTLM][%s][Response] Negotiate: %sé   Tz%[WSNETDirect][NTLM][%s] Challenge: %szB[WSNETDirect][NTLM][%s] Sending Challenge, getting Authenticate...z2[WSNETDirect][NTLM][%s][Response] Authenticate: %sz.[WSNETDirect][NTLM][%s] Fetching SessionKey...z0[WSNETDirect][NTLM][%s][Response] SessionKey: %sz$[WSNETDirect][NTLM][%s][NTLMINFO] %sF)r   Ú
CONNECTIONr   Údebugr   r   r   r   ÚsubprotocolÚget_urlÚconnectÚauthenticateÚvaluer   r   Úload_negotiateÚload_challengeÚload_authenticateÚget_sessionkeyr   r
   Úload_sessionkeyrA   rC   Ú
disconnectÚ	Exception)r   ÚauthDatarH   Úcb_dataÚspnÚkwargsÚ_ÚerrÚstatusÚctxattrÚnegotiate_rawÚauthenticate_rawÚer   r   r   rT   K   s\   €
((
€ÿz"NTLMClientWSNETDirect.authenticate)r   )r(   N)NF)NNN)Ú__name__Ú
__module__Ú__qualname__r   r   Úpropertyr   r   r    r#   r%   r.   r2   r5   r8   r?   rA   rC   rE   rF   rG   r   rT   r   r   r   r   r   
   s,    	





r   )
r   Úasyauth.protocols.ntlmr   Ú$asyauth.protocols.ntlm.client.nativer   Úasyauth.common.winapi.constantsr   Úwsnet.agent.direct.authr   r   r   r   r   r   Ú<module>   s    