Your IP : 172.28.240.42


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

ó
iù™Nc@s„dZeZddlmZddlmZddlmZm	Z	m
Z
ddlmZm
Z
mZddlmZmZddlmZmZmZddlmZdd	lmZdd
lmZddlmZddlmZdd
l m!Z!ddl"m#Z#ddl m$Z$yddl%m&Z&Wne'k
rCd!Z&n'Xddl)m*Z*m+Z+ddl)m,Z,dd"d„ƒYZ-de.fd„ƒYZ/de.fd„ƒYZ0de-ee#e/fd„ƒYZ1de-ee/e#fd„ƒYZ2de-e/ee!efd„ƒYZ3e4ƒj5e2j6ƒƒe4ƒj5e1j6ƒƒe4ƒj5e3ƒj6ƒƒdee$e/fd „ƒYZ7e4ƒj5e7j6ƒƒd!S(#s0
Tests for implementations of L{ITLSTransport}.
iÿÿÿÿ(t
implements(tReactorBuilder(t
ServerFactoryt
ClientFactorytProtocol(tIReactorSSLt
ITLSTransporttIStreamClientEndpoint(tDeferredtDeferredList(tSSL4ServerEndpointtSSL4ClientEndpointtTCP4ClientEndpoint(tConnectionClosed(t
Cooperator(tSkipTest(tplatform(tObjectModelIntegrationMixin(tStreamTransportTestsMixin(tConnectionTestsMixin(tAbortConnectionMixin(tFILETYPE_PEM(tPrivateCertificatetKeyPair(tClientContextFactorytTLSMixincBs:eZegZejƒr8dZied6ed6ZnRS(scFor some reason, these reactors don't deal with SSL disconnection correctly on Windows.  See #3371.s*twisted.internet.glib2reactor.Glib2Reactors(twisted.internet.gtk2reactor.Gtk2Reactor(t__name__t
__module__RtrequiredInterfacesRt	isWindowstmsgtskippedReactors(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR&s	tContextGeneratingMixincBs&eZdZdZd„Zd„ZRS(sW-----BEGIN CERTIFICATE-----
MIIDBjCCAm+gAwIBAgIBATANBgkqhkiG9w0BAQQFADB7MQswCQYDVQQGEwJTRzER
MA8GA1UEChMITTJDcn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TzgApr8DmeQHTYC8ydfzH7EECe4R1Xh
5kwIzOuuFfn178FBiS84gngaNcrFi0Z5fAkCAwEAAQJBAIqm/bz4NA1H++Vx5Ewx
OcKp3w19QSaZAwlGRtsUxrP7436QjnREM3Bm8ygU11BjkPVmtrKm6AayQfCHqJoT
ZIECIQDW0BoMoL0HOYM/mrTLhaykYAVqgIeJsPjvkEhTFXWBuQIhAM3deFAvWNu4
nklUQ37XsCT2c9tmNt1LAT+slG2JOTTRAiAuXDtC/m3NYVwyHfFm+zKHRzHkClk2
HjubeEgjpj32AQIhAJqMGTaZVOwevTXvvHwNEH+vRWsAYU/gbx+OQB+7VOcBAiEA
oolb6NMg/R3enNPvS1O4UU1H8wpaF77L4yiSWlE0p4w=
-----END RSA PRIVATE KEY-----
cCs1tj|jtj|jtƒtƒ}|jƒS(sM
        Return a new SSL context suitable for use in a test server.
        (Rtloadt_certificateTextRt_privateKeyTextRtoptions(tselftcert((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytgetServerContextTs
	cCstƒS(N(R(R%((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytgetClientContext_s(RRR"R#R'R((((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR 2s	tStartTLSClientEndpointcBs*eZdZeeƒd„Zd„ZRS(s!
    An endpoint which wraps another one and adds a TLS layer immediately when
    connections are set up.

    @ivar wrapped: A L{IStreamClientEndpoint} provider which will be used to
        really set up connections.

    @ivar contextFactory: A L{ContextFactory} to use to do TLS.
    cCs||_||_dS(N(twrappedtcontextFactory(R%R*R+((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyt__init__ps	cs2ˆjj|ƒ}‡fd†}|j|ƒ|S(s¼
        Establish a connection using a protocol build by C{factory} and
        immediately start TLS on it.  Return a L{Deferred} which fires with the
        protocol instance.
        cs|jjˆjƒ|S(N(t	transporttstartTLSR+(tprotocol(R%(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyt	connected|s(R*tconnecttaddCallback(R%tfactorytdR0((R%sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR1us
(RRt__doc__RRR,R1(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR)ds	
	tStartTLSClientTestsMixincBs eZdZd„Zd„ZRS(sš
    Tests for TLS connections established using L{ITLSTransport.startTLS} (as
    opposed to L{IReactorSSL.connectSSL} or L{IReactorSSL.listenSSL}).
    cCst|d|jƒƒS(s¸
        Construct an SSL server endpoint.  This should be be constructing a TCP
        server endpoint which immediately calls C{startTLS} instead, but that
        is hard.
        i(R
R'(R%treactor((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytserverEndpointŠscCstt|d|jƒtƒƒS(sS
        Construct a TCP client endpoint wrapped to immediately start TLS.
        s	127.0.0.1(R)RtportR(R%R7t
serverAddress((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytclientEndpoint“s(RRR5R8R;(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR6„s		tSSLClientTestsMixincBs)eZdZd„Zd„Zd„ZRS(s<
    Mixin defining tests relating to L{ITLSTransport}.
    cCst|d|jƒƒS(sQ
        Create an SSL server endpoint on a TCP/IP-stack allocated port.
        i(R
R'(R%R7((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR8¤scCst|d|jtƒƒS(s¨
        Create an SSL client endpoint which will connect localhost on
        the port given by C{serverAddress}.

        @type serverAddress: L{IPv4Address}
        s	127.0.0.1(RR9R(R%R7R:((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR;«scsvdtfd„ƒY}|jƒ‰tƒ}tƒ|_||_|jƒ|_tƒ}tƒ|_||_|j	ƒ|_|jj
|j_
g‰t|j|jgdtƒ}‡fd†}|j
|ƒˆjd|ddƒ}|j|jƒˆj|jƒj|jƒj|ƒ}|j|jƒ|j
‡fd†ƒ|jˆƒˆdjtƒˆd	jtƒd
S(sO
        L{ITCPTransport.loseConnection} ends a connection which was set up with
        L{ITLSTransport.startTLS} and which has recently been written to.  This
        is intended to verify that a socket send error masked by the TLS
        implementation doesn't prevent the connection from being reported as
        closed.
        t
ShortProtocolcBs#eZd„Zd„Zd„ZRS(cSsktj|jƒsA|jj}d|j_|jtdƒƒdS|jj|jj	ƒ|jj
dƒdS(NsNo ITLSTransport supporttx(Rt
providedByR-R3tfinishedtNoneterrbackRR.tcontexttwrite(R%R@((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytconnectionMadeÀscSs!|jjdƒ|jjƒdS(Nty(R-RDtloseConnection(R%tdata((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytdataReceivedÎscSs8|jj}|dk	r4d|j_|j|ƒndS(N(R3R@RAtcallback(R%treasonR@((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytconnectionLostØs(RRRERIRL(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR=¿s		
t
consumeErrorscs'ˆj|dd|ddgƒdS(Nii(textend(tresults(tlostConnectionResults(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyt
cbFinishedñsit	interfaces	127.0.0.1cs
ˆjƒS(N(tstop(tign(R7(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyt<lambda>üsiN(RtbuildReactorRRR@R/R'RCRR(tmethodR	tTrueR2t	listenTCPt
addCleanupt
stopListeningt
connectTCPtgetHostthostR9t
disconnectt
runReactorttrapR
(R%R=t
serverFactoryt
clientFactoryR@RQR9t	connector((R7RPsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyt&test_disconnectAfterWriteAfterStartTLS·s4!					
!
(RRR5R8R;Re(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR<žs		tTLSPortTestsBuildercBs)eZdZd„Zd„Zd„ZRS(s,
    Tests for L{IReactorSSL.listenSSL}
    cCs|jd||jƒƒS(s0
        Get a TLS port from a reactor.
        i(t	listenSSLR'(R%R7R3((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytgetListeningPort	scCsd||jƒjfS(sY
        Get the message expected to be logged when a TLS port starts listening.
        s%s (TLS) starting on %d(R]R9(R%R9R3((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyt#getExpectedStartListeningLogMessagescCsd|jƒjfS(sJ
        Get the expected connection lost message for a TLS port.
        s(TLS Port %s Closed)(R]R9(R%R9((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytgetExpectedConnectionLostLogMsgs(RRR5RhRiRj(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyRfs		tAbortSSLConnectionTestcBs5eZefZd„Zd„Zd„Zd„ZRS(csjtj|ƒ‰yddlm}Wntk
r7ˆSXtd‡fd†ƒ}|j|d|jƒˆS(Niÿÿÿÿ(ttlst	schedulercsˆjd|ƒS(Ngñh㈵øä>(t	callLater(R>(R7(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyRU1st	cooperate(RRVttwisted.protocolsRltImportErrorRtpatchRo(R%Rlt
cooperator((R7sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyRV's
cCsOtdkrtdƒ‚n|jƒ|_|jƒ|_|jj|j_dS(NsOpenSSL not available.(RRARR't
serverContextR(t
clientContextRW(R%((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytsetUp6s
cCs|jd||jddƒS(s#
        Listen using SSL.
        iRRs	127.0.0.1(RgRt(R%R7tserver((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pytlisten>scCs(|j|jƒj|jƒj|jƒS(s$
        Connect using SSL.
        (t
connectSSLR]R^R9Ru(R%t
clientcreatort
serverport((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyR1Fs(RRRRRVRvRxR1(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyRk$s
				N((8R5ttypet
__metaclass__tzope.interfaceRt#twisted.internet.test.reactormixinsRttwisted.internet.protocolRRRttwisted.internet.interfacesRRRttwisted.internet.deferRR	ttwisted.internet.endpointsR
RRttwisted.internet.errorR
ttwisted.internet.taskRttwisted.trial.unittestRttwisted.python.runtimeRttwisted.internet.test.test_coreRttwisted.internet.test.test_tcpRt&twisted.internet.test.connectionmixinsRRtOpenSSL.cryptoRRqRAttwisted.internet.sslRRRRtobjectR R)R6R<RftglobalstupdatetmakeTestCaseClassesRk(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tls.pyt<module>sH

2 d	*