~ubuntu-branches/ubuntu/raring/m2crypto/raring

« back to all changes in this revision

Viewing changes to demo/ssl/twistedsslserver.py

  • Committer: Barry Warsaw
  • Date: 2011-10-25 18:26:01 UTC
  • mfrom: (24.1.4 merge)
  • Revision ID: barry@python.org-20111025182601-uag0ee3eh3ahtofm
Merge from Debian with remaining deltas.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
3
Demonstrates M2Crypto.SSL.TwistedProtocolWrapper
 
4
 
 
5
Copyright (c) 2005 Open Source Applications Foundation. All rights reserved.
 
6
"""
 
7
 
 
8
import sys
 
9
import M2Crypto.SSL as SSL
 
10
import M2Crypto.SSL.TwistedProtocolWrapper as wrapper
 
11
import twisted.internet.protocol as protocol
 
12
import twisted.internet.reactor as reactor
 
13
import twisted.python.log as log
 
14
 
 
15
 
 
16
class Echo(protocol.Protocol):
 
17
    def dataReceived(self, data):
 
18
        print 'received: "%s"' % data
 
19
        self.transport.write(data)
 
20
 
 
21
    def connectionMade(self):
 
22
        print 'connection made'
 
23
 
 
24
 
 
25
class ContextFactory:
 
26
    def getContext(self):
 
27
        ctx = SSL.Context()
 
28
        ctx.load_cert('server.pem')
 
29
        return ctx
 
30
 
 
31
 
 
32
if __name__ == '__main__':
 
33
    log.startLogging(sys.stdout)
 
34
    factory = protocol.Factory()
 
35
    factory.protocol = Echo
 
36
    wrapper.listenSSL(8000, factory, ContextFactory())
 
37
    reactor.run()