o b!@sDdZddlmZmZmZddlmZddlmZm Z dZ eej GdddZ Gdd d e Z eej Gd d d Zeejgd d ee jDRGddde jZeejGddde jZGddde jZGddde jZddlmZmZmZmZmZmZmZmZmZ m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(gdZ)dS)a This module implements Transport Layer Security (TLS) support for Twisted. It requires U{PyOpenSSL }. If you wish to establish a TLS connection, please use one of the following APIs: - SSL endpoints for L{servers } and L{clients } - L{startTLS } - L{connectSSL } - L{listenSSL } These APIs all require a C{contextFactory} argument that specifies their security properties, such as certificate, private key, certificate authorities to verify the peer, allowed TLS protocol versions, cipher suites, and so on. The recommended value for this argument is a L{CertificateOptions} instance; see its documentation for an explanation of the available options. The C{contextFactory} name is a bit of an anachronism now, as context factories have been replaced with "connection creators", but these objects serve the same role. Be warned that implementing your own connection creator (i.e.: value for the C{contextFactory}) is both difficult and dangerous; the Twisted team has worked hard to make L{CertificateOptions}' API comprehensible and unsurprising, and the Twisted team is actively maintaining it to ensure that it becomes more secure over time. If you are really absolutely sure that you want to take on the risk of implementing your own connection creator based on the pyOpenSSL API, see the L{server connection creator } and L{client connection creator } interfaces. Developers using Twisted, please ignore the L{Port}, L{Connector}, and L{Client} classes defined here, as these are details of certain reactors' TLS implementations, exposed by accident (and remaining here only for compatibility reasons). If you wish to establish a TLS connection, please use one of the APIs listed above. @note: "SSL" (Secure Sockets Layer) is an antiquated synonym for "TLS" (Transport Layer Security). You may see these terms used interchangeably throughout the documentation. ) implementedBy implementerimplementer_only)SSL) interfacestcpTc@seZdZdZdZddZdS)ContextFactoryz>A factory for SSL context objects, for server SSL connections.rcCst)z4Return a SSL.Context object. override in subclasses.NotImplementedErrorselfr 6/usr/lib/python3/dist-packages/twisted/internet/ssl.py getContextJszContextFactory.getContextN)__name__ __module__ __qualname____doc__isClientrr r r rrDs rc@sFeZdZdZdZejejfddZddZ ddZ d d Z d d Z dS) DefaultOpenSSLContextFactoryaQ L{DefaultOpenSSLContextFactory} is a factory for server-side SSL context objects. These objects define certain parameters related to SSL handshakes and the subsequent connection. @ivar _contextFactory: A callable which will be used to create new context objects. This is typically L{OpenSSL.SSL.Context}. NcCs$||_||_||_||_|dS)z @param privateKeyFileName: Name of a file containing a private key @param certificateFileName: Name of a file containing a certificate @param sslmethod: The SSL method to use N)privateKeyFileNamecertificateFileName sslmethod_contextFactory cacheContext)r rrrrr r r__init__[s   z%DefaultOpenSSLContextFactory.__init__cCsH|jdur"||j}|tj||j||j ||_dSdSN) _contextrr set_optionsr OP_NO_SSLv2use_certificate_fileruse_privatekey_filerr ctxr r rrqs      z)DefaultOpenSSLContextFactory.cacheContextcCs|j}|d=|S)Nr)__dict__copy)r dr r r __getstate__{s z)DefaultOpenSSLContextFactory.__getstate__cCs ||_dSr)r$)r stater r r __setstate__s z)DefaultOpenSSLContextFactory.__setstate__cCs|jS)z( Return an SSL context. )rr r r rrsz'DefaultOpenSSLContextFactory.getContext) rrrrrr SSLv23_METHODContextrrr'r)rr r r rrOs    rc@s(eZdZdZdZejZejZ ddZ dS)ClientContextFactoryz"A context factory for SSL clients.cCs||j}|tj|Sr)rmethodrrrr"r r rrs  zClientContextFactory.getContextN) rrrrrrr*r.r+rrr r r rr,s  r,ccs|] }|tjkr|VqdSr)r ITLSTransport).0ir r r sr2c@s"eZdZdZdddZddZdS)Clientz I am an SSL client. NcCs ||_tj||||||dSr) ctxFactoryrr3r)r hostport bindAddressr4 connectorreactorr r rrszClient.__init__cCs$||j|tj|dSr)startTLSr4 startWritingrr3 _connectDoner r r rr<s zClient._connectDoner)rrrrrr<r r r rr3s  r3c@s eZdZdZddZddZdS)Serverz I am an SSL server. cOs,tjj|g|Ri|||jjdSr)rr=rr:serverr4)r argskwargsr r rrszServer.__init__cCstd)NServer.getPeerCertificater r r r rgetPeerCertificatesrAN)rrrrrrBr r r rr=s r=c@s,eZdZdZeZdZ d ddZdd ZdS) Portz I am an SSL port. TLS2NcCs tj||||||||_dSr)rrCrr4)r r6factoryr4backlog interfacer9r r rrs z Port.__init__cCstj||dS)z| Override the normal prefix to include an annotation indicating this is a port for TLS connections. z (TLS))rrC _getLogPrefix)r rGr r rrJszPort._getLogPrefix)rErFN) rrrrr= transport_typerrJr r r rrCs rCc@s eZdZ dddZddZdS) ConnectorNc Cs*||_tj||||||||dSr)contextFactoryrrMrr)r r5r6rGrNtimeoutr7r9r r rrs zConnector.__init__cCst|j|j|j|j||jSr)r3r5r6r7rNr9r r r r_makeTransportszConnector._makeTransportr)rrrrrPr r r rrMs rM)DN CertificateCertificateRequestDistinguishedNameKeyPairOpenSSLAcceptableCiphersOpenSSLCertificateOptionsOpenSSLDefaultPathsOpenSSLDiffieHellmanParametersPrivateCertificateProtocolNegotiationSupport TLSVersionVerificationErroroptionsForClientTLS platformTrustprotocolNegotiationMechanismstrustRootFromCertificates)rrr,rTrQrRrSrZrUAcceptableCiphersCertificateOptionsDiffieHellmanParametersr_rXr\r]r^r[r`raN)*rzope.interfacerrrOpenSSLrtwisted.internetrr supportedIOpenSSLContextFactoryrrr, ISSLTransportr3r=rCrMtwisted.internet._sslverifyrQrRrSrTrUrVrbrWrcrXrYrdrZr[r\r]r^r_r`ra__all__r r r rs,4  ;L