o
    	þðc°  ã                   @   sp   d Z ddlm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
 e d	e¡ eeƒZG d
d„ deƒZdS )z
NTLM authenticating pool, contributed by erikcederstran

Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10
é    )Úabsolute_importN)Ú	getLogger)Úntlmé   )ÚHTTPSConnectionPool)ÚHTTPSConnectiona#  The 'urllib3.contrib.ntlmpool' module is deprecated and will be removed in urllib3 v2.0 release, urllib3 is not able to support it properly due to reasons listed in issue: https://github.com/urllib3/urllib3/issues/2282. If you are a user of this module please comment in the mentioned issue.c                       sD   e Zd ZdZdZ‡ fdd„Zdd„ Z							d‡ fd
d„	Z‡  ZS )ÚNTLMConnectionPoolzQ
    Implements an NTLM authentication version of an urllib3 connection pool
    Úhttpsc                    sP   t t| ƒj|i |¤Ž || _|| _| dd¡}|d  ¡ | _|d | _|| _	dS )zÅ
        authurl is a random URL on the server that is protected by NTLM.
        user is the Windows user, probably in the DOMAIN\username format.
        pw is the password for the user.
        ú\é   r   N)
Úsuperr   Ú__init__ÚauthurlÚrawuserÚsplitÚupperÚdomainÚuserÚpw)Úselfr   r   r   ÚargsÚkwargsÚ
user_parts©Ú	__class__© úE/opt/certbot/lib/python3.10/site-packages/urllib3/contrib/ntlmpool.pyr   "   s   

zNTLMConnectionPool.__init__c                 C   sê  |  j d7  _ t d| j | j| j¡ ddi}d}d}t| j| jd}dt | j	¡ ||< t d	|¡ | 
d
| jd |¡ | ¡ }t|jƒ}t d|j|j¡ t d|¡ t d| d¡¡ d |_||  d¡}d }|D ]}	|	d d… dkrz|	dd … }qj|d u r‰td||| f ƒ‚t |¡\}
}t |
| j| j| j|¡}d| ||< t d	|¡ | 
d
| jd |¡ | ¡ }t d|j|j¡ t dt|jƒ¡ t d| ¡ d d… ¡ |jdkrë|jdkrátdƒ‚td|j|jf ƒ‚d |_t d¡ |S )Nr   z3Starting NTLM HTTPS connection no. %d: https://%s%sÚ
Connectionú
Keep-AliveÚAuthorizationzwww-authenticate)ÚhostÚportzNTLM %szRequest headers: %sÚGETzResponse status: %s %szResponse headers: %szResponse data: %s [...]éd   z, é   zNTLM z!Unexpected %s response header: %séÈ   i‘  z3Server rejected request: wrong username or passwordzWrong server response: %s %szConnection established)Únum_connectionsÚlogÚdebugr    r   r   r!   r   Úcreate_NTLM_NEGOTIATE_MESSAGEr   ÚrequestÚgetresponseÚdictÚheadersÚstatusÚreasonÚreadÚfpr   Ú	ExceptionÚparse_NTLM_CHALLENGE_MESSAGEÚ create_NTLM_AUTHENTICATE_MESSAGEr   r   r   )r   r-   Ú
req_headerÚresp_headerÚconnÚresÚreshdrÚauth_header_valuesÚauth_header_valueÚsÚServerChallengeÚNegotiateFlagsÚauth_msgr   r   r   Ú	_new_conn0   sh   ü
ÿ
€ÿÿÿ


zNTLMConnectionPool._new_connNé   Tc              	      s0   |d u ri }d|d< t t| ƒ |||||||¡S )Nr   r   )r   r   Úurlopen)r   ÚmethodÚurlÚbodyr-   ÚretriesÚredirectÚassert_same_hostr   r   r   rB   s   s   

ÿzNTLMConnectionPool.urlopen)NNrA   TT)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úschemer   r@   rB   Ú__classcell__r   r   r   r   r      s    Gør   )rL   Ú
__future__r   ÚwarningsÚloggingr   r   Ú r   Úpackages.six.moves.http_clientr   ÚwarnÚDeprecationWarningrI   r'   r   r   r   r   r   Ú<module>   s    û