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