Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/internet/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyc


iNc@srdZddlZddlmZedkraddlmZddlmZddlm	Z
n0ddlmZdd	lmZdd
lm
Z
ddlmZddl
mZdd
lmZddlmZmZddlmZddlmZmZddlmZdddYZidZdefdYZdefdYZdefdYZ dS(sH
This module implements OpenSSL socket BIO based TLS support.  It is only used if
memory BIO APIs are not available, which is when the version of pyOpenSSL
installed is older than 0.10 (when L{twisted.protocols.tls} is not importable).
This implementation is undesirable because of the complexity of working with
OpenSSL's non-blocking socket-based APIs (which this module probably does about
99% correctly, but see #4455 for an example of a problem with it).

Eventually, use of this module should emit a warning.  See #4974 and 5014.

@see: L{twisted.internet._newtls}
@since: 11.1
iN(tplatformTypetwin32(tWSAEINTR(tWSAEWOULDBLOCK(t
WSAENOBUFS(tEINTR(tEWOULDBLOCK(tENOBUFS(tSSL(t
implements(tlog(t
ITLSTransportt
ISSLTransport(tFileDescriptor(tCONNECTION_DONEtCONNECTION_LOST(t_TLSDelayedt	_TLSMixincBseZdZdZdZeZZdZdZ	dZ
dZdZdZ
dZd	Zd
ZdZdZd
ZRS(t
sock_shutdownicCs
|jjS(N(tsockettget_peer_certificate(tself((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pytgetPeerCertificate1scCs|jr
tS|jr,d|_|jny|jj|SWntjk
rWtStjk
rkdStj	k
rd|_
|jj||jj|dStj
k
r\}}|dkr|dks|dkrtStjtStjk
r}|SXdS(NiiisUnexpected EOF(tdisconnectedRtwriteBlockedOnReadt_resetReadWritet_basetdoReadRtZeroReturnErrort
WantReadErrortWantWriteErrortreadBlockedOnWritetstartWritingtstopReadingtSysCallErrorRR
terrtError(Rtretvaltdescte((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR4s0			
	
cCsU|jr|jS|jr&|jS|jrEd|_|jn|jj|S(Ni(Rt_postLoseConnectiont_writeDisconnectedt_closeWriteConnectionRRRtdoWrite(R((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR+^s	
	
		
cCsy|jj||SWntjk
r.dStjk
rkd|_|jj||jj|dStjk
rt	Stj
k
r}|ddkr|dkrdSt	Sntjk
r}|SXdS(Niiit(Rt
writeSomeDataRRRRtstopWritingtstartReadingRRR"R$(RtdataR'((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR-us"	cCs;t|_t|jdr1|jjtjn|jS(s
        Gets called after loseConnection(), after buffered data is sent.

        We try to send an SSL shutdown alert, but if it doesn't work, retry
        when the socket is writable.
        tset_shutdown(tTrueRthasattrRR1RtRECEIVED_SHUTDOWNt_sendCloseAlert(R((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR(s
	cCs"ytj|jjdWn4tk
rS}|jdtttfkrOdSt	SXyt
|jdr|jj}|jj|t
jB|jj}|t
j@s|jjt
jqn|jjt}Wnt
jk
r}|SX|r|jtS|j|jdSdS(NR,iR1(tostwriteRtfilenotOSErrortargsRRRRR3tget_shutdownR1RR4tshutdownt
SENT_SHUTDOWNR2R$R.RR R/tNone(Rtset	laststatetdoneR'((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR5s.





cCs,|j}|tkr(|jj|S|S(N(R5RRR*(Rtresult((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR*scCs&t|_|js"|jj|SdS(N(R2t
_userWantReadRRR/(R((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR/s		cCs0t|_|js|jr,|jj|SdS(N(tFalseRCRRRR!(R((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR!s	cCs&t|_|js"|jj|SdS(N(R2t_userWantWriteRRR (R((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR s		cCs0t|_|js|jr,|jj|SdS(N(RDRERRRR.(R((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR.s	cCsD|jr|jn
|j|jr6|jn
|jdS(N(RER R.RCR/R!(R((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR	s	

	
(t__name__t
__module__t_socketShutdownMethodRRR2RCRERRR+R-R(R5R*R/R!R R.R(((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR*s 
		*				A							cs@|kr8dtffdY}||<n|S(Nt
TLSConnectioncseZeeZRS((RFRGR	RR((tklass(s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyRIs
(R(RJt	_existingRI((RJs</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyt_getTLSClasss
tConnectionMixincBsJeZdZdZdZedZdZdZ	dZ
dZRS(s
    Mixin for L{twisted.internet.tcp.Connection} to help implement
    L{ITLSTransport} using pyOpenSSL to do crypto and I/O.
    icCs|jst|js"|jr;tg|||_tS|j|j|j	t
j|j|j
|_
|j
j|_|jtS(N(tTLStAssertionErrort
dataBuffert_tempDataBufferRt_tlsWaitingRDR!R.t	_startTLSRt
Connectiont
getContextRR8R/R2(Rtctxtextra((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pytstartTLS)s



cCsd|_t|j|_dS(Ni(RNRLt	__class__(R((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyRS;s	cCs9|jdk	r%|jjj|ntj||dS(N(RRR>tbufferedDatatappendR
R7(Rtbytes((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR7@scCs9|jdk	r%|jjj|ntj||dS(N(RRR>RZtextendR
t
writeSequence(Rtiovec((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR^GscCsttj|}|jdk	rp|jrp|jrp|j}d|_|j|j|j|j	|j
qpn|S(N(R
R+RRR>RPRQRXtcontextRWR^RZ(RRBtwaiting((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyR+Ns		N(RFRGt__doc__RNR>RRR2RXRSR7R^R+(((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyRM!s			tClientMixincBs$eZdZeeddZRS(sh
    Mixin for L{twisted.internet.tcp.Client} to implement the client part of
    L{ITLSTransport}.
    icCsB|jj|||r>|r.|jjq>|jjndS(N(RRXRtset_connect_statetset_accept_state(RRVtclient((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyRXas(RFRGRbR	RRX(((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyRcZs
tServerMixincBs$eZdZeeddZRS(sh
    Mixin for L{twisted.internet.tcp.Client} to implement the server part of
    L{ITLSTransport}.
    icCsB|jj|||r>|r.|jjq>|jjndS(N(RRXRReRd(RRVtserver((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyRXqs(RFRGRbR	RRX(((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyRgjs
((!RbR6ttwisted.python.runtimeRterrnoRRRRRRtOpenSSLRtzope.interfaceR	ttwisted.pythonR
ttwisted.internet.interfacesRRttwisted.internet.abstractR
ttwisted.internet.mainRRttwisted.internet._sslRRRLtobjectRMRcRg(((s</usr/lib/python2.7/dist-packages/twisted/internet/_oldtls.pyt<module>s*	9