Ñò ñ1Mc @s\dZdddddgZddkiiZddkZddklZdd kl Z dd k l Z ddk Z dd k l Z lZdd klZd „Zddeiieiƒd„Zddeiieiƒd„Zddeiied„Zddeiidd„Zddd„ƒYZddd„ƒYZdefd„ƒYZdS(sv Make Twisted use M2Crypto for SSL Copyright (c) 2004-2007 Open Source Applications Foundation. All rights reserved. t connectSSLt connectTCPt listenSSLt listenTCPtTLSProtocolWrapperiÿÿÿÿN(tProtocolWrapper(t ITLSTransport(t implements(tm2tX509(tCheckercCsdS(Ni((tpeerX509t expectedHost((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyt"_alwaysSucceedsPostConnectionChecksic s=ti|ƒ}‡‡fd†|_|i|||||ƒS(s~ A convenience function to start an SSL/TLS connection using Twisted. See IReactorSSL interface in Twisted. c s%t||dddddˆdˆƒS(tstartPassThroughitclientitcontextFactorytpostConnectionCheck(R(tfactorytwrappedProtocol(RR(sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyt$s (tpoliciestWrappingFactorytprotocolR( thosttportRRttimeoutt bindAddresstreactorRtwrappingFactory((RRsI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyRs cs:ti|ƒ}‡fd†|_|i|||||ƒS(s¶ A convenience function to start a TCP connection using Twisted. NOTE: You must call startTLS(ctx) to go into SSL/TLS mode. See IReactorTCP interface in Twisted. c s%t||dddddddˆƒS(RiRRRN(RtNone(RR(R(sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR9s (RRRR(RRRRRRRR((RsI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR.s itcs:ti|ƒ}‡‡fd†|_|i||||ƒS(s~ A convenience function to listen for SSL/TLS connections using Twisted. See IReactorSSL interface in Twisted. c s%t||dddddˆdˆƒS(RiRRR(R(RR(RR(sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyRLs (RRRR(RRRtbacklogt interfaceRRR((RRsI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyRCscs7ti|ƒ}‡fd†|_|i||||ƒS(s¾ A convenience function to listen for TCP connections using Twisted. NOTE: You must call startTLS(ctx) to go into SSL/TLS mode. See IReactorTCP interface in Twisted. c s%t||dddddddˆƒS(RiRiRRN(RR(RR(R(sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyRas (RRRR(RRR R!RRR((RsI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyRVs t _BioProxycBs2eZdZeiZd„Zd„Zd„ZRS(s The purpose of this class is to eliminate the __del__ method from TLSProtocolWrapper, and thus letting it be garbage collected. cCs ||_dS(N(tbio(tselfR#((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyt__init__sscCs|iS(N(R#(R$((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyt_ptrvscCs(|idj o|i|iƒndS(N(R#Rtm2_bio_free_all(R$((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyt__del__ys( t__name__t __module__t__doc__Rt bio_free_allR'R%R&R((((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR"ks    t _SSLProxycBs2eZdZeiZd„Zd„Zd„ZRS(s The purpose of this class is to eliminate the __del__ method from TLSProtocolWrapper, and thus letting it be garbage collected. cCs ||_dS(N(tssl(R$R.((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR%†scCs|iS(N(R.(R$((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR&‰scCs(|idj o|i|iƒndS(N(R.Rt m2_ssl_free(R$((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR(Œs( R)R*R+Rtssl_freeR/R%R&R((((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR-~s    cBs–eZdZeeƒd„Zd„Zd„Zd„Zd„Z d„Z d„Z d„Z d „Z d „Zd „Zd d d„Zd d„ZRS(sä A SSL/TLS protocol wrapper to be used with Twisted. Typically you would not use this class directly. Use connectTCP, connectSSL, listenTCP, listenSSL functions defined above, which will hook in this class. cCs||_||_d|_d|_d|_d|_||_d|_|djo t |_ n ||_ |p|i |i ƒƒndS(sŽ @param factory: @param wrappedProtocol: @param startPassThrough: If true we won't encrypt at all. Need to call startTLS() later to switch to SSL/TLS. @param client: True if this should be a client protocol. @param contextFactory: Factory that creates SSL.Context objects. The called function is getContext(). @param postConnectionCheck: The post connection check callback that will be called just after connection has been established but before any real data has been exchanged. The first argument to this function is an X509 object, the second is the expected host name string. RiN( RRtdatat encryptedt tlsStartedtcheckedtisClientt helloDoneRR RtstartTLSt getContext(R$RRRRRR((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR%›s           cCsut|ddƒo(d|_d|_d|_d|_nd|_d|_d|_d|_ d|_ d|_ dS(sI Clear this instance, after which it is ready for reuse. R3iRiN( tgetattrRtsslBioR.t internalBiot networkBioR1R2R3R4R5R6(R$((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pytclearÇs         cCsª|io td‚n||_titiƒƒ|_ti|idƒttitiƒƒƒ|_ ti|i i ƒdƒti |i|i i ƒƒttiti ƒƒƒ|_ tti|iiƒƒ|_|ioti|ii ƒƒnti|ii ƒƒti|ii ƒ|i|iƒti|i i ƒ|ii ƒtiƒti|ii ƒƒ}ti|ii ƒ|tiBtiBƒd|_dS(sq Start SSL/TLS. If this is not called, this instance just passes data through untouched. sTLS already startediiN(R3t ExceptiontctxRtbio_newt bio_s_bioR;tbio_set_write_buf_sizeR"R<R&tbio_make_bio_pairt bio_f_sslR:R-tssl_newR.R5tssl_set_connect_statetssl_set_accept_statet ssl_set_biot bio_set_sslt bio_nocloset ssl_get_modet ssl_set_modetSSL_MODE_ENABLE_PARTIAL_WRITEt#SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER(R$R?tmode((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR7Ùs(    "(  cCs›|ipti||ƒdSy,|i|ƒ}ti||ƒd|_WnItiij o7}ti |i i ƒƒ|i df|_ |‚nXdS(Nii( R3Rtwritet_encryptR6tM2CryptotBIOtBIOErrorRtssl_get_verify_resultR.R&targs(R$R1t encryptedDatate((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyRPs  (cCsB|ipti|di|ƒƒdS|idi|ƒƒdS(NR(R3Rt writeSequencetjoinRP(R$R1((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyRYs cCsti|ƒdS(N(RtloseConnection(R$((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR[scCs>ti|ƒ|io#|io|i o|iƒndS(N(RtconnectionMadeR3R5R6t _clientHello(R$((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR\s cCsé|ipti||ƒdS|i|7_ykxd|iƒ}|iƒ|iƒ}ti||ƒti||ƒ|djo|djoPq4q4WnIti i j o7}t i |i iƒƒ|idf|_|‚nXdS(NRi(R3Rt dataReceivedR2t_decryptt_checkRQRPRRRSRTRRUR.R&RV(R$R1t decryptedDataRWRX((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR^ s      (cCs|iƒti||ƒdS(N(R=RtconnectionLost(R$treason((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyRb:s cCsÃ|i o´ti|iiƒƒo›ti|iiƒƒ}|dj oti|dƒ}n|io|i i d}n|i i ƒi }|i ||ƒptid‚nd|_ndS(Niispost connection check(R4Rtssl_is_init_finishedR.R&tssl_get_peer_certRR R5t transporttaddrtgetPeerRRR tSSLVerificationError(R$tx509R((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR`>s$  cCsy/|iddƒ}ti||ƒd|_WnItiij o7}ti|i i ƒƒ|i df|_ |‚nXdS(Nt clientHelloii( RQRRPR6RRRSRTRRUR.R&RV(R$RWRX((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR]Ks (RicCsLd}|i|7_|iiƒ}|iiƒ}ti}ti}ti}ti} ti } xå||ƒ} | djo|idjp|o\|||iƒ} | djo||ƒpt ‚qï|i pt ‚|i| |_n| |ƒ} | oB| || ƒ}|dj o||7}qE||ƒpt ‚qcPqc|S(NRi( R1R:R&R<Rtbio_ctrl_get_write_guaranteet bio_writetbio_should_retrytbio_ctrl_pendingtbio_readtAssertionErrorR4R(R$R1RkRWt sslBioPtrR<tm2bio_ctrl_get_write_guaranteet m2bio_writetm2bio_should_retrytm2bio_ctrl_pendingt m2bio_readtgtrtpendingtd((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyRQXs2      $   cCs4|i|7_d}|iiƒ}|iiƒ}ti}ti}ti}ti}ti } xÍ||ƒ} | djo[|idjoK|||iƒ} | djo||ƒpt ‚q×|i| |_n||ƒ} | oB| || ƒ} | dj o|| 7}q-||ƒpt ‚qcPqc|S(NRi( R2R:R&R<RRlRmRnRoRpRqR(R$R1RaRrR<RsRtRuRvRwRxRyRzR{((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR_zs0         (R)R*R+RRR%R=R7RPRYR[R\R^RbR`R]RQR_(((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyR‘s  ,  (       "(((R+t__all__ttwisted.protocols.policiest protocolsRttwisted.internet.reactorttwistedRttwisted.internet.interfacesRtzope.interfaceRRRRR t M2Crypto.SSLR R RtinternetRRRRRR"R-R(((sI/usr/lib/python2.6/vendor-packages/M2Crypto/SSL/TwistedProtocolWrapper.pyts6