Ticket #5449: ssl.py

File ssl.py, 0.8 KB (added by wulczer, 2 years ago)

snippet demonstrating the change in behaviour

Line 
1from twisted.internet import protocol, reactor, ssl
2
3from OpenSSL import SSL
4
5
6class CtxFactory(ssl.ClientContextFactory):
7
8    def getContext(self):
9        self.method = SSL.SSLv23_METHOD
10        ctx = ssl.ClientContextFactory.getContext(self)
11        ctx.use_certificate_file('/etc/passwd')
12        ctx.use_privatekey_file('/etc/passwd')
13
14        return ctx
15
16
17class Protocol(protocol.Protocol):
18
19    def connectionMade(self):
20        print "connection made"
21
22    def connectionLost(self, reason):
23        print "connection lost", reason
24
25
26class Factory(protocol.ClientFactory):
27
28    protocol = Protocol
29
30
31def timeout():
32    print "TIMEOUT"
33    reactor.stop()
34
35
36reactor.connectSSL('twistedmatrix.com', 443, Factory(), CtxFactory())
37reactor.callLater(3, timeout)
38reactor.run()