a †oeLOã @sddlmZddlZddlZddlZddlZddlZddlZddlmZ ddlm Z ddl m Z ddlmZddlmZdd lmZzddlZejZWn*eefyÀdZGd d „d eƒZYn0zeZWn"eyìGd d „d eƒZYn0zeZWn$e�yGdd„deƒZYn0ddlmZddl m!Z!ddl"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4e 5e6¡Z7dddœZ8e 9ddd¡Z:e ;d¡Zdd „Z?d!d"„Z@Gd#d$„d$e=ƒZAe�seAZ>e>ZBdS)%é)Úabsolute_importN)Úerror)Útimeouté)Úsix)ÚHTTPConnection)Ú HTTPException)Úcreate_proxy_ssl_contextc@s eZdZdS)Ú BaseSSLErrorN©Ú__name__Ú __module__Ú __qualname__©rrú3C:\Program Files\Certbot\pkgs\urllib3\connection.pyr sr c@s eZdZdS)ÚConnectionErrorNr rrrrr!src@s eZdZdS)ÚBrokenPipeErrorNr rrrrr*sr)ÚHTTPHeaderDict©Ú __version__)ÚConnectTimeoutErrorÚNewConnectionErrorÚSubjectAltNameWarningÚSystemTimeWarning)Ú SKIP_HEADERÚSKIPPABLE_HEADERSÚ connection)Úassert_fingerprintÚcreate_urllib3_contextÚ is_ipaddressÚresolve_cert_reqsÚresolve_ssl_versionÚssl_wrap_socket)ÚCertificateErrorÚmatch_hostnameéPi»)ÚhttpÚhttpsiæz[^-!#$%&'*+.^_`|~0-9a-zA-Z]csžeZdZdZedZejejdfgZ dZ dZ dd„Z e dd „ƒZejd d „ƒZd d „Zd d„Zdd„Zdd„Zdd„Zdd„Zd‡fdd„ Zddd„Z‡ZS)ra5 Based on :class:`http.client.HTTPConnection` but provides an extra constructor backwards-compatibility layer between older and newer Pythons. Additional keyword parameters are used to configure attributes of the connection. Accepted parameters include: - ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool` - ``source_address``: Set the source address for the current connection. - ``socket_options``: Set specific options on the underlying socket. If not specified, then defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy. For example, if you wish to enable TCP Keep Alive in addition to the defaults, you might pass: .. code-block:: python HTTPConnection.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ] Or you may want to disable the defaults by passing an empty list (e.g., ``[]``). r&rFNcOsftjs| dd¡| d¡|_| d|j¡|_| dd¡|_| dd¡|_t j |g|¢Ri|¤ŽdS)NÚstrictÚsource_addressÚsocket_optionsÚproxyÚ proxy_config) rZPY2ÚpopÚgetr)Údefault_socket_optionsr*r+r,Ú_HTTPConnectionÚ__init__)ÚselfÚargsÚkwrrrr1ss  zHTTPConnection.__init__cCs |j d¡S)aŸ Getter method to remove any trailing dots that indicate the hostname is an FQDN. In general, SSL certificates don't include the trailing dot indicating a fully-qualified domain name, and thus, they don't validate properly when checked against a domain name that includes the dot. In addition, some servers may not expect to receive the trailing dot when provided. However, the hostname with trailing dot is critical to DNS resolution; doing a lookup with the trailing dot will properly only resolve the appropriate FQDN, whereas a lookup without a trailing dot will search the system's search domain list. Thus, it's important to keep the original host around for use only in those cases where it's appropriate (i.e., when doing DNS lookup to establish the actual TCP connection across which we're going to send HTTP requests). Ú.)Ú _dns_hostÚrstrip©r2rrrÚhost„szHTTPConnection.hostcCs ||_dS)z× Setter for the `host` property. We assume that only urllib3 uses the _dns_host attribute; httplib itself only uses `host`, and it seems reasonable that other libraries follow suit. N)r6)r2Úvaluerrrr9—sc Cs¤i}|jr|j|d<|jr$|j|d<z"tj|j|jf|jfi|¤Ž}WnXtynt|d|j |jfƒ‚Yn2t yž}zt |d|ƒ‚WYd}~n d}~00|S)zoEstablish a socket connection and set nodelay settings on it. :return: New socket connection. r)r*z0Connection to %s timed out. (connect timeout=%s)z(Failed to establish a new connection: %sN) r)r*rZcreate_connectionr6ÚportrÚ SocketTimeoutrr9Ú SocketErrorr)r2Zextra_kwÚconnÚerrrÚ _new_conn¡s.  ÿÿ   ÿþÿzHTTPConnection._new_conncCs t|ddƒS)NÚ _tunnel_host)Úgetattrr8rrrÚ_is_using_tunnelÀszHTTPConnection._is_using_tunnelcCs ||_| ¡r| ¡d|_dS)Nr)ÚsockrCÚ_tunnelÚ auto_open©r2r>rrrÚ _prepare_connÄszHTTPConnection._prepare_conncCs| ¡}| |¡dS©N)r@rHrGrrrÚconnectÌszHTTPConnection.connectcOs>t |¡}|r"td|| ¡fƒ‚tj|||g|¢Ri|¤ŽS)ú zAMethod cannot contain non-token characters %r (found at least %r))Ú_CONTAINS_CONTROL_CHAR_REÚsearchÚ ValueErrorÚgroupr0Ú putrequest)r2ÚmethodÚurlr3ÚkwargsÚmatchrrrrPÐs  ÿÿzHTTPConnection.putrequestcGs^tdd„|Dƒƒs(tj||g|¢RŽn2t | ¡¡tvrZtdd t t j t tƒƒ¡fƒ‚dS)rKcss |]}t|tƒo|tkVqdSrI)Ú isinstanceÚstrr)Ú.0ÚvrrrÚ ßóz+HTTPConnection.putheader..z+urllib3.util.SKIP_HEADER only supports '%s'z', 'N) Úanyr0Ú putheaderrÚ ensure_strÚlowerrrNÚjoinÚmaprVÚtitleÚsorted)r2ÚheaderÚvaluesrrrr\ÝsÿÿzHTTPConnection.putheadercslt|ddƒdur|j |j¡|dur,i}n| ¡}ddd„|DƒvrPtƒ|d<tt|ƒj||||d�dS)NrDú user-agentcss|]}t | ¡¡VqdSrI©rr]r^©rWÚkrrrrYòrZz)HTTPConnection.request..ú User-Agent)ÚbodyÚheaders) rBrDZ settimeoutrÚcopyÚ_get_default_user_agentÚsuperrÚrequest)r2rQrRrjrk©Ú __class__rrroçs zHTTPConnection.requestcCs&|pi}tdd„|Dƒƒ}d|v}d|v}|j||||d�d|vrR| dtƒ¡| ¡D]\}} | || ¡qZd|vr„| d d ¡| ¡|d u�rtjtf} t || ƒr²|f}|D]`} | sÀq¶t | tƒsÔ|   d ¡} t t | ƒƒd d …} t |   ¡ƒ} | d7} | | 7} | d7} | | ¡q¶| d¡d S)zƒ Alternative to the common request method, which sends the body with chunked encoding and not as one block cSsg|]}t | ¡¡‘qSrrfrgrrrÚ ürZz2HTTPConnection.request_chunked..zaccept-encodingr9)Úskip_accept_encodingÚ skip_hostreriztransfer-encodingzTransfer-EncodingZchunkedNÚutf8és s0 )ÚsetrPr\rmÚitemsZ endheadersrZ string_typesÚbytesrUÚencodeÚhexÚlenÚ bytearrayÚsend)r2rQrRrjrkZ header_keysrsrtrcr:Zstringish_typesÚchunkZlen_strZto_sendrrrÚrequest_chunkedös<ÿ        zHTTPConnection.request_chunked)NN)NN)r r rÚ__doc__Úport_by_schemeÚ default_portÚsocketZ IPPROTO_TCPZ TCP_NODELAYr/Ú is_verifiedÚproxy_is_verifiedr1Úpropertyr9Úsetterr@rCrHrJrPr\ror€Ú __classcell__rrrprrLs$    rc @sjeZdZdZedZdZdZdZdZ dZ dZ dZ ddddde jddfdd„Zd dd„Zd d „Zd d „ZdS)ÚHTTPSConnectionz• Many of the parameters to this constructor are passed to the underlying SSL socket by means of :py:func:`urllib3.util.ssl_wrap_socket`. r'NFc KsDtj|||f||dœ| ¤Ž||_||_||_||_| |_d|_dS)N)r(rr')rr1Úkey_fileÚ cert_fileÚ key_passwordÚ ssl_contextÚserver_hostnameZ _protocol) r2r9r;r‹rŒr�r(rrŽr�r4rrrr1.szHTTPSConnection.__init__c Csv|dur$|jdur|jj}ntdƒ}||_||_||_||_||_||_|oVt j   |¡|_ |oht j   |¡|_ | |_dS)zX This method should only be called once, before the connection is used. N)rŽÚ verify_moder r‹rŒÚ cert_reqsr�Úassert_hostnamerÚosÚpathÚ expanduserÚca_certsÚ ca_cert_dirÚ ca_cert_data) r2r‹rŒr‘r�r–r’rr—r˜rrrÚset_certHs  zHTTPSConnection.set_certc Cs| ¡|_}|j}d}| ¡rP|jr<| ||¡|_}d}| ¡d|_|j}|}|j durd|j }t j   ¡t k}|rˆt d t ¡t¡d}|jdur´d}tt|jƒt|jƒd�|_|j}t|jƒ|_|jsî|jsî|jsî|rît|dƒrî| ¡t||j|j |j!|j|j|j|||d� |_|�rd|jdu�rdt|jdƒ�rd|j "¡d v�rdt d |j|j "¡ft#¡|j$�r„t$|jj%dd �|j$ƒnd|jt&j'k�rèt(|d dƒ�sè|j)du�rè|j %¡}| *d d¡�sÖt d |¡t+¡t,||j)�pä|ƒ|jt&j-k�pþ|j$du|_.dS)NFTrzWSystem time is way off (before {0}). This will probably lead to SSL verification errors)Ú ssl_versionr‘Úload_default_certs) rDZkeyfileZcertfiler�r–r—r˜r�rŽÚ tls_in_tlsÚversion>ZTLSv1zTLSv1.1z±Negotiating TLSv1/TLSv1.1 by default is deprecated and will be disabled in urllib3 v2.0.0. Connecting to '%s' with '%s' can be enabled by explicitly opting-in with 'ssl_version')Z binary_formÚcheck_hostnameÚsubjectAltNamerúëCertificate for {0} has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/urllib3/urllib3/issues/497 for details.))/r@rDr9rCÚtls_in_tls_requiredÚ_connect_tls_proxyrErFrAr�ÚdatetimeÚdateZtodayÚ RECENT_DATEÚwarningsÚwarnÚformatrrŽrr!ršr r‘r�r–r—r˜Úhasattrr›r"r‹rŒr�r�ÚDeprecationWarningrÚ getpeercertÚsslÚ CERT_NONErBr’r.rÚ_match_hostnameÚ CERT_REQUIREDr…) r2r>Úhostnamerœr�Z is_time_offZdefault_ssl_contextÚcontextÚcertrrrrJis´ ÿýû  þ ÿþýüûöÿþ ý üýûÿ ÿ þý ýù þzHTTPSConnection.connectcCs¬|j}|j}|rt|||d�St|j|j|j|j|jƒ}t||j|j|j||d�}|j t j kršt |ddƒsš|  ¡}| dd¡s�t d |¡t¡t||ƒ|j t jk|_|S)zY Establish a TLS connection to the proxy using the provided SSL context. )rDr�rŽ)rDr–r—r˜r�rŽržFrŸrr )r,rŽr"r ršr‘r–r—r˜r�r¬r­rBr«r.r¦r§r¨rr®r¯r†)r2r°r>r,rŽr„r²rrrr¢ßsJýû ú ÿ ýù z"HTTPSConnection._connect_tls_proxy) NNNNNNNNN)r r rr�r‚rƒr‘r–r—r˜ršrr¡r„Z_GLOBAL_DEFAULT_TIMEOUTr1r™rJr¢rrrrrŠs<ö ö !vrŠc Csd| d¡}t|ƒr|}zt||ƒWn:ty^}z"t d||¡||_‚WYd}~n d}~00dS)Nzu[]z@Certificate did not match expected hostname: %s. Certificate: %s)Ústriprr$r#ÚlogZwarningZ _peer_cert)r²Zasserted_hostnameZstripped_hostnamer?rrrr®s ýr®cCsdtS)Nzpython-urllib3/%srrrrrrm.srmc@seZdZdZdS)ÚDummyConnectionz-Used to detect a failed ConnectionCls import.N)r r rr�rrrrrµ2srµ)CZ __future__rr£Zloggingr“Úrer„r¦rr=rr<ZpackagesrZpackages.six.moves.http_clientrr0rZ util.proxyr r¬ZSSLErrorr Ú ImportErrorÚAttributeErrorÚ BaseExceptionrÚ NameErrorÚ ExceptionrÚ _collectionsrZ_versionrÚ exceptionsrrrrÚutilrrrZ util.ssl_rrrr r!r"Zutil.ssl_match_hostnamer#r$Z getLoggerr r´r‚r¤r¥ÚcompilerLÚobjectrŠr®rmrµZVerifiedHTTPSConnectionrrrrÚs\               S{