Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / examples / echoserv_ssl.py
1
2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
4
5
6 from OpenSSL import SSL
7
8 class ServerContextFactory:
9     
10     def getContext(self):
11         """Create an SSL context.
12         
13         This is a sample implementation that loads a certificate from a file 
14         called 'server.pem'."""
15         ctx = SSL.Context(SSL.SSLv23_METHOD)
16         ctx.use_certificate_file('server.pem')
17         ctx.use_privatekey_file('server.pem')
18         return ctx
19
20
21 if __name__ == '__main__':
22     import echoserv, sys
23     from twisted.internet.protocol import Factory
24     from twisted.internet import ssl, reactor
25     from twisted.python import log
26     log.startLogging(sys.stdout)
27     factory = Factory()
28     factory.protocol = echoserv.Echo
29     reactor.listenSSL(8000, factory, ServerContextFactory())
30     reactor.run()