o
    àý°jw  ã                   @   s<  d dl Z d dlmZ d dlmZmZ d dlmZmZm	Z	m
Z
mZ d dlmZmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ ed
ƒZ	 ejZdevr]e ddddddddddœ	¡ G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZde de!fd d!„Z"	 	"d*d#ed$e#d%ee! d&e d'e!de!fd(d)„Z$dS )+é    N)ÚList)Úhresult_errorsÚLOG)ÚDWORDÚLPWSTRÚNULLÚPBYTEÚULONG)ÚNDRCALLÚ	NDRSTRUCT)ÚcheckNullString)Ú	DCERPC_v5ÚDCERPCException)Ú	constants)Úuuidtup_to_bin)z$91ae6020-9e3c-11cf-8d7c-00aa00c091bez0.0éM   )Ú KDC_ERR_INCONSISTENT_KEY_PURPOSEz;Certificate cannot be used for PKINIT client authentication)Ú#KDC_ERR_DIGEST_IN_CERT_NOT_ACCEPTEDzSDigest algorithm for the public key in the certificate is not acceptable by the KDC)Ú$KDC_ERR_PA_CHECKSUM_MUST_BE_INCLUDEDz2The paChecksum filed in the request is not present)Ú*KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTEDzPThe digest algorithm used by the id-pkinit-authData is not acceptable by the KDC)Ú+KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTEDzFThe KDC does not support the public key encryption key delivery method)ÚKDC_ERR_PREAUTH_EXPIREDz0The conversation is too old and needs to restart)Ú"KDC_ERR_MORE_PREAUTH_DATA_REQUIREDz&Additional pre-authentication required)Ú&KDC_ERR_PREAUTH_BAD_AUTHENTICATION_SETz/KDC cannot accommodate requested padata element)Ú%KDC_ERR_UNKNOWN_CRITICAL_FAST_OPTIONSzUnknown critical option)	r   éN   éO   éP   éQ   éZ   é[   é\   é]   c                   @   s$   e Zd Zddd„Zdefdd„ZdS )ÚDCERPCSessionErrorNc                 C   s   t  | |||¡ d S )N)r   Ú__init__)ÚselfÚerror_stringÚ
error_codeÚpacket© r)   úŠ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/impacket/dcerpc/v5/icpr.pyr$   c   s   zDCERPCSessionError.__init__Úreturnc                 C   s    |  j dM  _ t| j ƒ}d| S )Nì   ÿÿ zRequestSessionError: %s)r'   Útranslate_error_code)r%   Ú	error_msgr)   r)   r*   Ú__str__f   s   
zDCERPCSessionError.__str__)NNN)Ú__name__Ú
__module__Ú__qualname__r$   Ústrr/   r)   r)   r)   r*   r#   b   s    
r#   c                   @   s   e Zd ZdefdeffZdS )ÚCERTTRANSBLOBÚcbÚpbN)r0   r1   r2   r	   r   Ú	structurer)   r)   r)   r*   r4   q   s    þr4   c                   @   s2   e Zd ZdZdefdefdefdefdeffZdS )ÚCertServerRequestr   ÚdwFlagsÚpwszAuthorityÚpdwRequestIdÚpctbAttribsÚpctbRequestN)r0   r1   r2   Úopnumr   r   r4   r7   r)   r)   r)   r*   r8   x   s    ûr8   c                   @   s.   e Zd ZdefdefdefdefdeffZdS )ÚCertServerRequestResponser;   ÚpdwDispositionÚpctbCertÚpctbEncodedCertÚpctbDispositionMessageN)r0   r1   r2   r   r	   r4   r7   r)   r)   r)   r*   r?   „   s    ûr?   r'   r+   c                 C   sD   | dM } | t jv rt j|  d }t j|  d }d| ||f S d|  S )Nr,   r   é   zcode: 0x%x - %s - %szunknown error code: 0x%x)r   ÚERROR_MESSAGES)r'   Úerror_msg_shortÚerror_msg_verboser)   r)   r*   r-   ‘   s   
ýr-   Ú ÚdceÚcsrÚ
attributesÚ
request_idÚcac                 C   s"  t d |¡ƒ d¡}tƒ }t|ƒ|d< ||d< tƒ }t|ƒ|d< ||d< tƒ }d|d< t |ƒ|d< ||d< ||d	< ||d
< |  |¡}	|	d }
|	d }|
dkrTt d¡ n-|
dkr^t 	d¡ n#t
|
ƒ}d|v rzt d|d |	d d ¡ d¡f ¡ nt d| ¡ t d| ¡ d |	d d ¡S )NÚ
zutf-16ler5   r6   r   r9   r:   r;   r<   r=   r@   é   z"Successfully requested certificateé   z'Certificate request is pending approvalzunknown error codez?Got unknown error while trying to request certificate: (%s): %só    rC   z1Got error while trying to request certificate: %szRequest ID is %drB   )r   ÚjoinÚencoder4   Úlenr8   Úrequestr   ÚinfoÚwarningr-   ÚerrorÚdecode)rI   rJ   rK   rL   rM   ÚattribsÚpctb_attribsÚpctb_requestrU   Úresponser'   r.   r)   r)   r*   ÚhCertServerRequestž   sH   
ÿþÿÿ
ÿr^   )r   rH   )%Úbase64Útypingr   Úimpacketr   r   Úimpacket.dcerpc.v5.dtypesr   r   r   r   r	   Úimpacket.dcerpc.v5.ndrr
   r   Úimpacket.dcerpc.v5.nrpcr   Úimpacket.dcerpc.v5.rpcrtr   r   Úimpacket.krb5r   Úimpacket.uuidr   ÚMSRPC_UUID_ICPRrE   ÚKRB5_ERROR_MESSAGESÚupdater#   r4   r8   r?   Úintr3   r-   Úbytesr^   r)   r)   r)   r*   Ú<module>   sZ   ßÿ'ûÿþýüûú