On Thu, Dec 17, 2009 at 02:44, Dean Michael Berris
<[email protected]> wrote:
> Hi Everyone,
>
> I'm currently working on getting HTTPS somewhat working with very
> simple queries, and right now I'm looking at a test server set up
> locally. I'm not sure how to do this with Python if it's even
> feasible, nor do I know any public HTTPS servers that I can make a
> test HTTPS call against (with the issue of validation, etc. of
> certificates and whatnot).
>
> Anybody have any ideas how I can easily write tests for HTTPS?
>
> --
> Dean Michael Berris
> blog.cplusplus-soup.com | twitter.com/mikhailberis
> linkedin.com/in/mikhailberis | facebook.com/dean.berris | deanberris.com
>

Hi Dean,

I've attached the simplest HTTPS server I could come up with in
Python, hard-coded to listen on 127.0.0.1:8443, as well as a
certificate pair generated as described at
http://panoptic.com/wiki/aolserver/How_to_generate_self-signed_SSL_certificates,
valid for the next 65536 days. Notice that it needs pyopenssl to
function.

Jeroen
#!/usr/bin/env python

import socket

from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

from OpenSSL import SSL

class SecureHTTPServer(HTTPServer):
    def __init__(self, server_address, HandlerClass):
        HTTPServer.__init__(self, server_address, HandlerClass)
    
        ctx = SSL.Context(SSL.SSLv23_METHOD)
        ctx.use_privatekey_file ("key.pem")
        ctx.use_certificate_file("certificate.pem")
        self.socket = SSL.Connection(ctx, socket.socket(self.address_family,
                                                        self.socket_type))
        self.server_bind()
        self.server_activate()

class SecureHTTPRequestHandler(SimpleHTTPRequestHandler):
    def setup(self):
        self.connection = self.request

        self.rfile = socket._fileobject(self.request, "rb", self.rbufsize)
        self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)

    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-Type", "text/plain")
        self.end_headers()

        self.wfile.write("Hello, world")


if __name__ == '__main__':
    SecureHTTPServer(('127.0.0.1', 8443), SecureHTTPRequestHandler).serve_forever()

Attachment: key.pem
Description: application/x509-ca-cert

Attachment: certificate.pem
Description: application/x509-ca-cert

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Cpp-netlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel

Reply via email to