o
    ßý°j�  ã                   @   s†   d Z ddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZmZ d
d„ Zddd„Zdd„ Zdd„ Zdd„ ZdS )Ú
é    N)Ú	ucd_3_2_0)Úurandom)Úhexlifyé   )ÚSASL)Ú RESULT_AUTH_METHOD_NOT_SUPPORTED)ÚLDAPSASLPrepErrorÚLDAPPasswordIsMandatoryErrorc                 C   sx  d}| D ]}t  |¡r|d7 }qt  |¡rq||7 }qt d|¡}|s'tdƒ‚|D ]\}t  |¡r4tdƒ‚t  |¡r=tdƒ‚t  |¡rFtdƒ‚t  |¡rOtdƒ‚t  	|¡rXtd	ƒ‚t  
|¡ratd
ƒ‚t  |¡rjtdƒ‚t  |¡rstdƒ‚t  |¡r|tdƒ‚t  |¡r…tdƒ‚q)d}d}|D ]}t  |¡r–d}nt  |¡r�d}|r¥|r¥tdƒ‚qŒ|rºt  |d ¡sºt  |d ¡sºtdƒ‚|S )a’  
    implement SASLPrep profile as per RFC4013:
    it defines the "SASLprep" profile of the "stringprep" algorithm [StringPrep].
    The profile is designed for use in Simple Authentication and Security
    Layer ([SASL]) mechanisms, such as [PLAIN], [CRAM-MD5], and
    [DIGEST-MD5].  It may be applicable where simple user names and
    passwords are used.  This profile is not intended for use in
    preparing identity strings that are not simple user names (e.g.,
    email addresses, domain names, distinguished names), or where
    identity or password strings that are not character data, or require
    different handling (e.g., case folding).
    Ú ú ÚNFKCz*SASLprep error: unable to normalize stringz1SASLprep error: non-ASCII space character presentz/SASLprep error: ASCII control character presentz3SASLprep error: non-ASCII control character presentz)SASLprep error: private character presentz0SASLprep error: non-character code point presentz,SASLprep error: surrogate code point presentz>SASLprep error: inappropriate for plain text character presentzLSASLprep error: inappropriate for canonical representation character presentzGSASLprep error: change display property or deprecated character presentz)SASLprep error: tagging character presentFTzISASLprep error: string cannot contain (R or AL) and L bidirectional charsr   éÿÿÿÿzNr_and_al_cat character present, must be first and last character of the string)Ú
stringprepÚin_table_c12Úin_table_b1Ú	unicode32Ú	normalizer	   Úin_table_c21Úin_table_c22Úin_table_c3Úin_table_c4Úin_table_c5Úin_table_c6Úin_table_c7Úin_table_c8Úin_table_c9Úin_table_d1Úin_table_d2)ÚdataÚprepared_dataÚcÚflag_r_and_al_catÚ
flag_l_cat© r$   ú‹/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/ldap3/protocol/sasl/sasl.pyÚ	sasl_prep$   sZ   













þ

€ r&   Fc                 C   sB   |r| s| S | st dƒ‚t| tƒst| ƒ} t| tƒs|  d¡} | S )zB
    validate simple password as per RFC4013 using sasl_prep:
    zsimple password can't be emptyzutf-8)r
   Ú
isinstanceÚbytesr&   Úencode)ÚpasswordÚaccept_emptyr$   r$   r%   Úvalidate_simple_password}   s   


r,   c                 C   sj   ddl m} || jtd d dd ƒ}|  |  d||¡¡}| jjr"| j}n	|  	|¡d d }|d t
kr3dS dS )	Nr   ©Úbind_operationr   ÚbindRequestr   ÚresultTF)Úoperation.bindr.   Úversionr   Úpost_send_single_responseÚsendÚstrategyÚsyncr0   Úget_responser   )Ú
connectionÚcontrolsr.   ÚrequestÚresponser0   r$   r$   r%   Úabort_sasl_negotiation�   s   r<   c                 C   sZ   ddl m} || jtd d | j|ƒ}|  |  d||¡¡}| jjr$| j	}|S |  
|¡\}}|S )Nr   r-   r/   )r1   r.   r2   r   Úsasl_mechanismr3   r4   r5   r6   r0   r7   )r8   r9   Úpayloadr.   r:   r;   r0   Ú_r$   r$   r%   Úsend_sasl_negotiationœ   s   þr@   c                 C   s   t tt| ƒƒ d¡ƒS )NÚascii)Ústrr   r   Údecode)Úsizer$   r$   r%   Úrandom_hex_stringª   s   rE   )F)Ú__doc__r   Úunicodedatar   r   Úosr   Úbinasciir   r   r   Úcore.resultsr   Úcore.exceptionsr	   r
   r&   r,   r<   r@   rE   r$   r$   r$   r%   Ú<module>   s    
Y