Ϫf#dZddlmZddlmZddlmZddlmZGddZ dZ Gd d Z Gd d Z Gd dZ y)z This module implements memory BIO based TLS support. It is the preferred implementation and will be used whenever pyOpenSSL 0.10 or newer is installed (whenever L{twisted.protocols.tls} is importable). @since: 11.1 )directlyProvides)FileDescriptor) ISSLTransport)TLSMemoryBIOFactoryc:eZdZdZdZdZdZdZdZdZ dZ y ) _BypassTLSa L{_BypassTLS} is used as the transport object for the TLS protocol object used to implement C{startTLS}. Its methods skip any TLS logic which C{startTLS} enables. @ivar _base: A transport class L{_BypassTLS} has been mixed in with to which methods will be forwarded. This class is only responsible for sending bytes over the connection, not doing TLS. @ivar _connection: A L{Connection} which TLS has been started on which will be proxied to by this object. Any method which has its behavior altered after C{startTLS} will be skipped in favor of the base class's implementation. This allows the TLS protocol object to have direct access to the transport, necessary to actually implement TLS. c ||_||_y)N)_base _connection)selfbase connections :/usr/lib/python3/dist-packages/twisted/internet/_newtls.py__init__z_BypassTLS.__init__&s %c.t|j|S)z Forward any extra attribute access to the original transport object. For example, this exposes C{getHost}, the behavior of which does not change after TLS is enabled. )getattrr )r names r __getattr__z_BypassTLS.__getattr__*s t''..rcN|jj|j|S)z> Write some bytes directly to the connection. )r writer )r datas rrz_BypassTLS.write2s!zz 0 0$77rcN|jj|j|S)z@ Write a some bytes directly to the connection. )r writeSequencer r iovecs rrz_BypassTLS.writeSequence8s!zz''(8(8%@@rcV|jj|jg|i|S)z2 Close the underlying connection. )r loseConnectionr )r argskwargss rrz_BypassTLS.loseConnection>s+)tzz(()9)9KDKFKKrcP|jj|j||S)zE Register a producer with the underlying connection. )r registerProducerr r producer streamings rr"z_BypassTLS.registerProducerDs#zz**4+;+;XyQQrcL|jj|jS)zG Unregister a producer with the underlying connection. )r unregisterProducerr r s rr'z_BypassTLS.unregisterProducerJszz,,T-=-=>>rN) __name__ __module__ __qualname____doc__rrrrrr"r'rrrrs- &/8 A L R ?rrc|r |j}n |j }d\}}|j(|j|j}}|jt ||d}|j ||j d}||_|j |_|j|_t|td|_ |j jt|||r|j||yy)a` Add a layer of SSL to a transport. @param transport: The transport which will be modified. This can either by a L{FileDescriptor} or a L{FileHandle}. The actual requirements of this instance are that it have: - a C{_tlsClientDefault} attribute indicating whether the transport is a client (C{True}) or a server (C{False}) - a settable C{TLS} attribute which can be used to mark the fact that SSL has been started - settable C{getHandle} and C{getPeerCertificate} attributes so these L{ISSLTransport} methods can be added to it - a C{protocol} attribute referring to the L{IProtocol} currently connected to the transport, which can also be set to a new L{IProtocol} for the transport to deliver data to @param contextFactory: An SSL context factory defining SSL parameters for the new SSL layer. @type contextFactory: L{twisted.internet.interfaces.IOpenSSLContextFactory} @param normal: A flag indicating whether SSL will go in the same direction as the underlying transport goes. That is, if the SSL client will be the underlying client and the SSL server will be the underlying server. C{True} means it is the same, C{False} means they are switched. @type normal: L{bool} @param bypass: A transport base class to call methods on to bypass the new SSL layer (so that the SSL layer itself can send its bytes). @type bypass: L{type} )NNNFT)_tlsClientDefaultr$streamingProducerr'rprotocol getHandlegetPeerCertificaterrTLSmakeConnectionrr") transportcontextFactorynormalbypassclientr$r% tlsFactory tlsProtocols rstartTLSr=QsJ,,000%Hi%'00)2M2M)$$&$^VTBJ%%j)2D2DeLK$I%//I#.#A#AI Y .IM%%j&CD""8Y7rc:eZdZdZdZd dZdZdZdZdZ dZ y ) ConnectionMixinaN A mixin for L{twisted.internet.abstract.FileDescriptor} which adds an L{ITLSTransport} implementation. @ivar TLS: A flag indicating whether TLS is currently in use on this transport. This is not a good way for applications to check for TLS, instead use L{twisted.internet.interfaces.ISSLTransport}. Fc(t|||ty)z1 @see: L{ITLSTransport.startTLS} N)r=r)r ctxr8s rr=zConnectionMixin.startTLSs sFN3rc|jr)|jr|jj|yyt j||y)z Write some bytes to this connection, passing them through a TLS layer if necessary, or discarding them if the connection has already been lost. N)r4 connectedr1rr)r bytess rrzConnectionMixin.writes; 88~~ ##E*  u -rc|jr)|jr|jj|yyt j||y)z Write some bytes to this connection, scatter/gather-style, passing them through a TLS layer if necessary, or discarding them if the connection has already been lost. N)r4rCr1rrrs rrzConnectionMixin.writeSequences; 88~~ ++E2  ( (u 5rc|jr5|jr(|js|jj yyyt j|y)z Close this connection after writing all pending data. If TLS has been negotiated, perform a TLS shutdown. N)r4rC disconnectingr1rrr(s rrzConnectionMixin.loseConnectionsA 88~~d&8&8 ,,.'9~  ) )$ /rc|jr|jj||ytj|||y)zc Register a producer. If TLS is enabled, the TLS connection handles this. N)r4r1r"rr#s rr"z ConnectionMixin.registerProducers3 88 MM * *8Y ?  + +D(I Frc||jr|jjytj|y)ze Unregister a producer. If TLS is enabled, the TLS connection handles this. N)r4r1r'rr(s rr'z"ConnectionMixin.unregisterProducers) 88 MM , , .  - -d 3rN)T) r)r*r+r,r4r=rrrr"r'r-rrr?r?s- C4 . 6 0 G 4rr?ceZdZdZdZy) ClientMixina= A mixin for L{twisted.internet.tcp.Client} which just marks it as a client for the purposes of the default TLS handshake. @ivar _tlsClientDefault: Always C{True}, indicating that this is a client connection, and by default when TLS is negotiated this class will act as a TLS client. TNr)r*r+r,r/r-rrrKrKsrrKceZdZdZdZy) ServerMixina> A mixin for L{twisted.internet.tcp.Server} which just marks it as a server for the purposes of the default TLS handshake. @ivar _tlsClientDefault: Always C{False}, indicating that this is a server connection, and by default when TLS is negotiated this class will act as a TLS server. FNrLr-rrrNrNsrrNN)r,zope.interfacertwisted.internet.abstractrtwisted.internet.interfacesrtwisted.protocols.tlsrrr=r?rKrNr-rrrSsK ,4559?9?xE8PM4M4`    r