ñÕYf]e ã @ s d d l Z d d l Z y d d l Z Wn e k rB d Z Yn Xd 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 „ Z d d „ Z d Z d Z d Z d Z Gd d „ d e ƒ Z Gd d „ d e j e j ƒ Z Gd d „ d e j ƒ Z d S)é Né )Úbase_events)Úcompat)Ú protocols)Ú transports)Úloggerc C s� | r t d ƒ ‚ t t d ƒ r? t j ƒ } | s‹ d | _ nL t j t j ƒ } | j t j O_ | j t j O_ | j ƒ t j | _ | S)Nz(Server side SSL needs a valid SSLContextÚcreate_default_contextF) Ú ValueErrorÚhasattrÚsslr Úcheck_hostnameZ SSLContextZPROTOCOL_SSLv23ZoptionsZOP_NO_SSLv2ZOP_NO_SSLv3Zset_default_verify_pathsZ CERT_REQUIREDÚverify_mode)Úserver_sideÚserver_hostnameÚ sslcontext© r ú5/opt/alt/python35/lib64/python3.5/asyncio/sslproto.pyÚ_create_transport_context s r c C s t t d ƒ S)NÚ MemoryBIO)r r r r r r Ú_is_sslproto_available% s r Z UNWRAPPEDZDO_HANDSHAKEZWRAPPEDZSHUTDOWNc @ s» e Z d Z d Z d Z d d d „ Z e d d „ ƒ Z e d d „ ƒ Z e d d „ ƒ Z e d d „ ƒ Z d d d „ Z d d d „ Z d d „ Z d d d „ Z d d d „ Z d S)Ú_SSLPipea An 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(). é i Nc C sj | | _ | | _ | | _ t | _ t j ƒ | _ t j ƒ | _ d | _ d | _ d | _ d | _ d S)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)ÚselfÚcontextr r r r r Ú__init__D s z_SSLPipe.__init__c C s | j S)z*The SSL context passed to the constructor.)r )r# r r r r$ Z s z_SSLPipe.contextc C s | j S)z^The internal ssl.SSLObject instance. Return None if the pipe is not wrapped. )r )r# r r r Ú ssl_object_ s z_SSLPipe.ssl_objectc C s | j S)zgWhether more record level data is needed to complete a handshake that is currently in progress.)r )r# r r r Úneed_ssldatag s z_SSLPipe.need_ssldatac C s | j t k S)zj Whether a security layer is currently in effect. Return False during handshake. )r Ú_WRAPPED)r# r r r Úwrappedm s z_SSLPipe.wrappedc C s” | j t k r t d ƒ ‚ | j j | j | j d | j d | j ƒ| _ t | _ | | _ | j d d d ƒ\ } } t | ƒ d k s� t ‚ | S)aL Start 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 completedr r ó Úonly_handshakeTr )r r ÚRuntimeErrorr Zwrap_bior r r r r Ú _DO_HANDSHAKEr! Úfeed_ssldataÚlenÚAssertionError)r# ÚcallbackÚssldataÚappdatar r r Údo_handshakev s z_SSLPipe.do_handshakec C s� | j t k r t d ƒ ‚ | j t k r6 t d ƒ ‚ | j t t f k sQ t ‚ t | _ | | _ | j d ƒ \ } } | g k s™ | d g k s™ t ‚ | S)a1 Start 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* ) r r r, Ú _SHUTDOWNr( r- r0 r" r. )r# r1 r2 r3 r r r Úshutdown‹ s !z_SSLPipe.shutdownc C sG | j j ƒ | j d ƒ \ } } | g k sC | d g k sC t ‚ d S)z†Send a potentially "ragged" EOF. This method will raise an SSL_ERROR_EOF exception if the EOF is unexpected. r* N)r Z write_eofr. r0 )r# r2 r3 r r r Úfeed_eofŸ s z_SSLPipe.feed_eofFc C s | j t k r1 | r! | g } n g } g | f Sd | _ | rP | j j | ƒ g } g } yú | j t k rª | j j ƒ t | _ | j rš | j d ƒ | rª | | f S| j t k rì x™ | j j | j ƒ } | j | ƒ | s¼ Pq¼ Wni | j t k r0| j j ƒ d | _ t | _ | j rU| j ƒ n% | j t k rU| j | j j ƒ ƒ Wn˜ t j t j f k rð} zl t | d d ƒ t j t j t j f k rÉ| j t k rÆ| j rÆ| j | ƒ ‚ | j t j k | _ WYd d } ~ Xn X| j j r| j | j j ƒ ƒ | | f S)a� Feed 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(). FNÚerrno)r r r r Úwriter- r r4 r( r! ÚreadÚmax_sizeÚappendr5 Zunwrapr" r ÚSSLErrorÚCertificateErrorÚgetattrÚSSL_ERROR_WANT_READÚSSL_ERROR_WANT_WRITEÚSSL_ERROR_SYSCALLr8 r Úpending)r# Údatar+ r3 r2 ÚchunkÚexcr r r r. © sV (z_SSLPipe.feed_ssldatar c C s” d | k o t | ƒ k n s( t ‚ | j t k ru | t | ƒ k r_ | | d … g } n g } | t | ƒ f Sg } t | ƒ } x d | _ y6 | t | ƒ k rÈ | | j j | | d … ƒ 7} Wn| t j k rG} zY | j d k rü t j | _ | j t j t j t j f k r ‚ | j t j k | _ WYd d } ~ Xn X| j j rj| j | j j ƒ ƒ | t | ƒ k s…| j rŠ PqŠ W| | f S)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. r NFZPROTOCOL_IS_SHUTDOWN)r/ r0 r r Ú memoryviewr r r9 r r= Úreasonr@ r8 rA rB r rC r<