2
# Twisted, the Framework of Your Internet
3
# Copyright (C) 2001 Matthew W. Lefkowitz
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of version 2.1 of the GNU Lesser General Public
7
# License as published by the Free Software Foundation.
9
# This library is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public
15
# License along with this library; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from OpenSSL import SSL
20
class ServerContextFactory:
23
"""Create an SSL context.
25
This is a sample implementation that loads a certificate from a file
26
called 'server.pem'."""
27
ctx = SSL.Context(SSL.SSLv23_METHOD)
28
ctx.use_certificate_file('server.pem')
29
ctx.use_privatekey_file('server.pem')
32
### Persistent Application Builder
34
# This builds a .tap file
36
if __name__ == '__main__':
38
from twisted.protocols.protocol import Factory
39
from twisted.internet.app import Application
40
from twisted.internet import ssl
41
from echoserv_ssl import ServerContextFactory
43
factory.protocol = echoserv.Echo
44
app = Application("echo-ssl")
45
app.listenSSL(8000, factory, ServerContextFactory())