PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  oY]e @sddlZddlZyddlZWnek rBdZYnXddlmZddlmZddlmZddlmZddl m Z dd Z d d Z d Z d ZdZdZGdddeZGdddejejZGdddejZdS)N) base_events)compat) protocols) transports)loggercCs|rtdttdr?tj}|sd|_nLtjtj}|jtjO_|jtj O_|j tj |_ |S)Nz(Server side SSL needs a valid SSLContextcreate_default_contextF) ValueErrorhasattrsslrcheck_hostnameZ SSLContextZPROTOCOL_SSLv23optionsZ OP_NO_SSLv2Z OP_NO_SSLv3Zset_default_verify_pathsZ CERT_REQUIRED verify_mode) server_sideserver_hostname sslcontextr'/opt/python35/lib/python3.5/sslproto.py_create_transport_contexts     rcCs ttdS)N MemoryBIO)r r rrrr_is_sslproto_available%srZ UNWRAPPEDZ DO_HANDSHAKEZWRAPPEDZSHUTDOWNc@seZdZdZdZdddZeddZed d Zed d Z ed dZ dddZ dddZ ddZ dddZdddZdS)_SSLPipeaAn SSL "Pipe". An SSL pipe allows you to communicate with an SSL/TLS protocol instance through memory buffers. It can be used to implement a security layer for an existing connection where you don't have access to the connection's file descriptor, or for some reason you don't want to use it. An SSL pipe can be in "wrapped" and "unwrapped" mode. In unwrapped mode, data is passed through untransformed. In wrapped mode, application level data is encrypted to SSL record level data and vice versa. The SSL record level is the lowest level in the SSL protocol suite and is what travels as-is over the wire. An SslPipe initially is in "unwrapped" mode. To start SSL, call do_handshake(). To shutdown SSL again, call unwrap(). iNcCsj||_||_||_t|_tj|_tj|_d|_ d|_ d|_ d|_ dS)a The *context* argument specifies the ssl.SSLContext to use. The *server_side* argument indicates whether this is a server side or client side transport. The optional *server_hostname* argument can be used to specify the hostname you are connecting to. You may only specify this parameter if the _ssl module supports Server Name Indication (SNI). NF) _context _server_side_server_hostname _UNWRAPPED_stater r _incoming _outgoing_sslobj _need_ssldata _handshake_cb _shutdown_cb)selfcontextrrrrr__init__Ds       z_SSLPipe.__init__cCs|jS)z*The SSL context passed to the constructor.)r)r$rrrr%Zsz_SSLPipe.contextcCs|jS)z^The internal ssl.SSLObject instance. Return None if the pipe is not wrapped. )r )r$rrr ssl_object_sz_SSLPipe.ssl_objectcCs|jS)zgWhether more record level data is needed to complete a handshake that is currently in progress.)r!)r$rrr need_ssldatagsz_SSLPipe.need_ssldatacCs |jtkS)zj Whether a security layer is currently in effect. Return False during handshake. )r_WRAPPED)r$rrrwrappedmsz_SSLPipe.wrappedcCs|jtkrtd|jj|j|jd|jd|j|_ t |_||_ |j ddd\}}t |dkst|S)aLStart the SSL handshake. Return a list of ssldata. A ssldata element is a list of buffers The optional *callback* argument can be used to install a callback that will be called when the handshake is complete. The callback will be called with None if successful, else an exception instance. z"handshake in progress or completedrronly_handshakeTr)rr RuntimeErrorrZwrap_biorrrrr _DO_HANDSHAKEr" feed_ssldatalenAssertionError)r$callbackssldataappdatarrr do_handshakevs      z_SSLPipe.do_handshakecCs|jtkrtd|jtkr6td|jttfksQtt|_||_|jd\}}|gks|dgkst|S)a1Start the SSL shutdown sequence. Return a list of ssldata. A ssldata element is a list of buffers The optional *callback* argument can be used to install a callback that will be called when the shutdown is complete. The callback will be called without arguments. zno security layer presentzshutdown in progressr+) rrr- _SHUTDOWNr)r.r1r#r/)r$r2r3r4rrrshutdowns     !z_SSLPipe.shutdowncCsG|jj|jd\}}|gksC|dgksCtdS)zSend a potentially "ragged" EOF. This method will raise an SSL_ERROR_EOF exception if the EOF is unexpected. r+N)rZ write_eofr/r1)r$r3r4rrrfeed_eofs z_SSLPipe.feed_eofFcCs|jtkr1|r!|g}ng}g|fSd|_|rP|jj|g}g}y|jtkr|jjt|_|j r|j d|r||fS|jtkrx|jj |j }|j ||sPqWni|jt kr0|jjd|_t|_|jrU|jn%|jtkrU|j |jj Wntjtjfk r}zlt|ddtjtjtjfkr|jtkr|j r|j ||jtjk|_WYdd}~XnX|jjr|j |jj ||fS)aFeed SSL record level data into the pipe. The data must be a bytes instance. It is OK to send an empty bytes instance. This can be used to get ssldata for a handshake initiated by this endpoint. Return a (ssldata, appdata) tuple. The ssldata element is a list of buffers containing SSL data that needs to be sent to the remote SSL. The appdata element is a list of buffers containing plaintext data that needs to be forwarded to the application. The appdata list may contain an empty buffer indicating an SSL "close_notify" alert. This alert must be acknowledged by calling shutdown(). FNerrno)rrr!rwriter.r r5r)r"readmax_sizeappendr6Zunwrapr#r SSLErrorCertificateErrorgetattrSSL_ERROR_WANT_READSSL_ERROR_WANT_WRITESSL_ERROR_SYSCALLr9rpending)r$datar,r4r3chunkexcrrrr/sV                ( z_SSLPipe.feed_ssldatarcCsd|kot|kns(t|jtkru|t|kr_||dg}ng}|t|fSg}t|}xd|_y6|t|kr||jj||d7}Wn|tj k rG}zY|j dkrtj |_ |j tj tj tjfkr |j tj k|_WYdd}~XnX|jjrj|j|jj|t|ks|jrPqW||fS)a Feed plaintext data into the pipe. Return an (ssldata, offset) tuple. The ssldata element is a list of buffers containing record level data that needs to be sent to the remote SSL instance. The offset is the number of plaintext bytes that were processed, which may be less than the length of data. NOTE: In case of short writes, this call MUST be retried with the SAME buffer passed into the *data* argument (i.e. the id() must be the same). This is an OpenSSL requirement. A further particularity is that a short write will always have offset == 0, because the _ssl module does not enable partial writes. And even though the offset is zero, there will still be encrypted data in ssldata. rNFZPROTOCOL_IS_SHUTDOWN)r0r1rr memoryviewr!r r:r r>reasonrAr9rBrCrrDr=r;)r$rEoffsetr3viewrGrrr feed_appdatas4(  $  ( z_SSLPipe.feed_appdatai)__name__ __module__ __qualname____doc__r<r&propertyr%r'r(r*r5r7r8r/rLrrrrr0s   Jrc@seZdZddZdddZddZdd Zd d Zd d Ze j rlddZ ddZ ddZ ddddZddZddZddZddZdS)_SSLProtocolTransportcCs(||_||_||_d|_dS)NF)_loop _ssl_protocol _app_protocol_closed)r$loopZ ssl_protocol app_protocolrrrr&)s   z_SSLProtocolTransport.__init__NcCs|jj||S)z#Get optional transport information.)rT_get_extra_info)r$namedefaultrrrget_extra_info0sz$_SSLProtocolTransport.get_extra_infocCs ||_dS)N)rU)r$protocolrrr set_protocol4sz"_SSLProtocolTransport.set_protocolcCs|jS)N)rU)r$rrr get_protocol7sz"_SSLProtocolTransport.get_protocolcCs|jS)N)rV)r$rrr is_closing:sz _SSLProtocolTransport.is_closingcCsd|_|jjdS)a Close the transport. Buffered data will be flushed asynchronously. No more data will be received. After all buffered data is flushed, the protocol's connection_lost() method will (eventually) called with None as its argument. TN)rVrT_start_shutdown)r$rrrclose=s z_SSLProtocolTransport.closecCs+|js'tjd|t|jdS)Nzunclosed transport %r)rVwarningswarnResourceWarningrb)r$rrr__del__Ls z_SSLProtocolTransport.__del__cCs|jjjdS)zPause the receiving end. No data will be passed to the protocol's data_received() method until resume_reading() is called. N)rT _transport pause_reading)r$rrrrhQsz#_SSLProtocolTransport.pause_readingcCs|jjjdS)zResume the receiving end. Data received will once again be passed to the protocol's data_received() method. N)rTrgresume_reading)r$rrrriYsz$_SSLProtocolTransport.resume_readingcCs|jjj||dS)aSet the high- and low-water limits for write flow control. These two values control when to call the protocol's pause_writing() and resume_writing() methods. If specified, the low-water limit must be less than or equal to the high-water limit. Neither value can be negative. The defaults are implementation-specific. If only the high-water limit is given, the low-water limit defaults to an implementation-specific value less than or equal to the high-water limit. Setting high to zero forces low to zero as well, and causes pause_writing() to be called whenever the buffer becomes non-empty. Setting low to zero causes resume_writing() to be called only once the buffer is empty. Use of zero for either limit is generally sub-optimal as it reduces opportunities for doing I/O and computation concurrently. N)rTrgset_write_buffer_limits)r$highlowrrrrjasz-_SSLProtocolTransport.set_write_buffer_limitscCs|jjjS)z,Return the current size of the write buffer.)rTrgget_write_buffer_size)r$rrrrmvsz+_SSLProtocolTransport.get_write_buffer_sizecCsTt|tttfs6tdjt|j|s@dS|jj |dS)zWrite some data bytes to the transport. This does not block; it buffers the data and arranges for it to be sent out asynchronously. z/data: expecting a bytes-like instance, got {!r}N) isinstancebytes bytearrayrH TypeErrorformattyperMrT_write_appdata)r$rErrrr:zs  z_SSLProtocolTransport.writecCsdS)zAReturn True if this transport supports write_eof(), False if not.Fr)r$rrr can_write_eofsz#_SSLProtocolTransport.can_write_eofcCs|jjdS)zClose the transport immediately. Buffered data will be lost. No more data will be received. The protocol's connection_lost() method will (eventually) be called with None as its argument. N)rT_abort)r$rrrabortsz_SSLProtocolTransport.abort)rMrNrOr&r\r^r_r`rbrZPY34rfrhrirjrmr:rurwrrrrrR&s            rRc@seZdZdZdddddZdddZd d Zd d Zd dZddZ ddZ ddZ dddZ ddZ ddZddZddZdd Zd!d"d#Zd$d%Zd&d'ZdS)( SSLProtocolzSSL protocol. Implementation of SSL on top of a socket using incoming and outgoing buffers which are ssl.MemoryBIO objects. FNTcCstdkrtd|s-t||}||_|rO| rO||_n d|_||_td||_tj |_ d|_ ||_ ||_ ||_t|j ||j|_d|_d|_d|_d|_d|_||_dS)Nzstdlib ssl module not availablerrF)r r-rrr _sslcontextdict_extra collectionsdeque_write_backlog_write_buffer_size_waiterrSrUrR_app_transport_sslpipe_session_established _in_handshake _in_shutdownrg_call_connection_made)r$rWrXrwaiterrrZcall_connection_maderrrr&s.                 zSSLProtocol.__init__cCs^|jdkrdS|jjsQ|dk rA|jj|n|jjdd|_dS)N)r cancelled set_exception set_result)r$rGrrr_wakeup_waiters zSSLProtocol._wakeup_waitercCs5||_t|j|j|j|_|jdS)zXCalled when the low-level connection is made. Start the SSL handshake. N)rgrryrrr_start_handshake)r$ transportrrrconnection_mades   zSSLProtocol.connection_madecCsN|jr+d|_|jj|jj|d|_d|_|j|dS)zCalled when the low-level connection is lost or closed. The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed). FN)rrS call_soonrUconnection_lostrgrr)r$rGrrrrs     zSSLProtocol.connection_lostcCs|jjdS)z\Called when the low-level transport's buffer goes over the high-water mark. N)rU pause_writing)r$rrrrszSSLProtocol.pause_writingcCs|jjdS)z^Called when the low-level transport's buffer drains below the low-water mark. N)rUresume_writing)r$rrrrszSSLProtocol.resume_writingcCsy|jj|\}}Wnatjk r}z>|jjr_tjd||j|j |j dSWYdd}~XnXx|D]}|j j |qWx2|D]*}|r|j j|q|jPqWdS)zXCalled when some SSL data is received. The argument is a bytes object. z%r: SSL error %s (reason %s)N)rr/r r>rS get_debugrwarningr9rIrvrgr:rU data_receivedra)r$rEr3r4erFrrrrs     zSSLProtocol.data_receivedc Cspz[|jjr"tjd||jt|jsZ|jj}|rZtj dWd|j j XdS)aCalled when the other end of the low-level stream is half-closed. If this returns a false value (including None), the transport will close itself. If it returns a true value, closing the transport is up to the protocol. z%r received EOFz?returning true from eof_received() has no effect when using sslN) rSrrdebugrConnectionResetErrorrrU eof_receivedrrgrb)r$Z keep_openrrrrs  zSSLProtocol.eof_receivedcCsD||jkr|j|S|jdk r<|jj||S|SdS)N)r{rgr\)r$rZr[rrrrYs  zSSLProtocol._get_extra_infocCs=|jr dS|jr#|jnd|_|jddS)NTr+)rrrvrt)r$rrrra&s     zSSLProtocol._start_shutdowncCs9|jj|df|jt|7_|jdS)Nr)r~r=rr0_process_write_backlog)r$rErrrrt/szSSLProtocol._write_appdatacCsm|jjr4tjd||jj|_n d|_d|_|jjd|jj |j dS)Nz%r starts SSL handshakeTr+r)r+r) rSrrrtime_handshake_start_timerr~r=rr)r$rrrr4s  zSSLProtocol._start_handshakecCsd|_|jj}ye|dk r*||j}t|jdsy|jry|jjtj krytj ||jWnt k r!}z|j j rt|tjrtjd|ddntjd|dd|jjt|tr |j|dSWYdd}~XnX|j j r^|j j|j}tjd||d|jjd |d |jd |jd ||jr|jj|j |jd|_!|j j"|j#dS) NFr z5%r: SSL handshake failed on verifying the certificateexc_infoTz%r: SSL handshake failedz%r: SSL handshake took %.1f msg@@peercertcipher compressionr')$rrr'Z getpeercertr ryrrr Z CERT_NONEZmatch_hostname BaseExceptionrSrrnr?rrrgrb Exceptionrrrrr{updaterrrrUrrrrr)r$Z handshake_excZsslobjrrGZdtrrr_on_handshake_complete@sD               z"SSLProtocol._on_handshake_completecCs|jdkrdSy+x$tt|jD] }|jd\}}|ri|jj||\}}n?|r|jj|j}d}n|jj|j }d}x|D]}|jj |qW|t|kr||f|jd<|jj st |jj r|jjP|jd=|jt|8_q,WWn`tk r}z@|jrl|j|n|j|dt|tsWYdd}~XnXdS)NrrzFatal error on SSL transport)rgranger0r~rrLr5rr7 _finalizer:r(r1Z_pausedrirrr _fatal_errorrnr)r$irErJr3rFrGrrrrts:        z"SSLProtocol._process_write_backlogzFatal error on transportc Cst|tjr=|jjrhtjd||ddn+|jjd|d|d|jd|i|jr|jj |dS)Nz%r: %srTmessage exceptionrr]) rnrZ_FATAL_ERROR_IGNORErSrrrZcall_exception_handlerrgZ _force_close)r$rGrrrrrs    zSSLProtocol._fatal_errorcCs)d|_|jdk r%|jjdS)N)rrgrb)r$rrrrs zSSLProtocol._finalizec Cs2z |jdk r|jjWd|jXdS)N)rgrwr)r$rrrrvszSSLProtocol._abort)rMrNrOrPr&rrrrrrrrYrartrrrrrrvrrrrrxs& #       4 , rx)r|rcr ImportErrorrrrrlogrrrrr.r)r6objectrZ_FlowControlMixinZ TransportrRZProtocolrxrrrrs(       n