Hi there,
I've implemented a simple HTTP server using Twisted just to change data between browser and this server. My class is declared:
from twisted.web import http
class MyRequestHandler(http.Request):
def process(self): ... my processing code
class MyHttp(http.HTTPChannel):
requestFactory = MyRequestHandler
class MyHttpFactory(http.HTTPFactory):
protocol = MyHttp
Everything works fine. But know, I want to transform that in HTTPS. I just want to respond browser requests if it access by "https://" And I don't know how to do that. I didn't find any previous post concerning this subject. Anyone can help me?
Thanks in advance.
Regards,
Evandro
On 08/02/2008 21:37 Evandro Dugnani wrote:
But know, I want to transform that in HTTPS. I just want to respond browser requests if it access by "https://" And I don't know how to do that. I didn't find any previous post concerning this subject.
Change TCPServer to SSLServer. Will also help to read the API docs.
On Feb 8, 2008 9:10 PM, Colin Alston karnaugh@karnaugh.za.net wrote:
Change TCPServer to SSLServer. Will also help to read the API docs.
Hi Colin,
Thanks for the tip. Using that, I discovered that I had to generate a private key file, and then generate a self-signed SSL certificate.. After that, I just created a ssl context with the private key and the certificate and changed my call "reactor.listenTCP()" to "reactor.listenSSL()", passing the ssl context as parameter.
Here is the code if anyone wants:
from twisted.web import http
class MyRequestHandler(http.Request):
def process(self): ... my processing code
class MyHttp(http.HTTPChannel):
requestFactory = MyRequestHandler
class MyHttpFactory(http.HTTPFactory):
protocol = MyHttp
if __name__ == "__main__":
from twisted.internet import reactor, ssl
sslContext = ssl.DefaultOpenSSLContextFactory('privkey.pem','cacert.pem') reactor.listenSSL(TCP_PORT, MyHttpFactory( ), contextFactory = sslContext)
reactor.run( )
Link for reference: - http://blog.vrplumber.com/356
Regards,
Evandro
On 12/02/2008 15:32 Evandro Dugnani wrote:
On Feb 8, 2008 9:10 PM, Colin Alston karnaugh@karnaugh.za.net wrote:
Change TCPServer to SSLServer. Will also help to read the API docs.
Hi Colin,
Thanks for the tip. Using that, I discovered that I had to generate a private key file, and then generate a self-signed SSL certificate.. After that, I just created a ssl context with the private key and the certificate and changed my call "reactor.listenTCP()" to "reactor.listenSSL()", passing the ssl context as parameter.
Oh I forgot about the context factory you need. Still, the keys is basically swapping TCPServer or listenTCP for SSLServer or listenSSL :P