PlasticSlices/Experiments: httpsd.py.patch

File httpsd.py.patch, 1.6 KB (added by Josh Smift, 13 years ago)

Patch to Python httpsd.py.

  • httpsd.py

    old new  
    11'''
    22SimpleSecureHTTPServer.py - simple HTTP server supporting SSL.
     3Modified from from http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/
    34
    45- replace fpem with the location of your .pem server file.
    5 - the default port is 443.
    66
    7 usage: python SimpleSecureHTTPServer.py
     7usage: python SimpleSecureHTTPServer.py <ipaddr> <port>
     8
    89'''
    9 import socket, os
     10import socket, os, sys
    1011from SocketServer import BaseServer
    1112from BaseHTTPServer import HTTPServer
    1213from SimpleHTTPServer import SimpleHTTPRequestHandler
    1314from OpenSSL import SSL
    1415
     16IPADDR = sys.argv[1]
     17PORT = int(sys.argv[2])
    1518
    1619class SecureHTTPServer(HTTPServer):
    1720    def __init__(self, server_address, HandlerClass):
    1821        BaseServer.__init__(self, server_address, HandlerClass)
    1922        ctx = SSL.Context(SSL.SSLv23_METHOD)
     23        fpem = '../localhost.localdomain.pem'
    2024        #server.pem's location (containing the server private key and
    2125        #the server certificate).
    22         fpem = '/path/server.pem'
    2326        ctx.use_privatekey_file (fpem)
    2427        ctx.use_certificate_file(fpem)
    2528        self.socket = SSL.Connection(ctx, socket.socket(self.address_family,
     
    3740
    3841def test(HandlerClass = SecureHTTPRequestHandler,
    3942         ServerClass = SecureHTTPServer):
    40     server_address = ('', 443) # (address, port)
     43    server_address = (IPADDR, PORT ) # (address, port)
    4144    httpd = ServerClass(server_address, HandlerClass)
    4245    sa = httpd.socket.getsockname()
    4346    print "Serving HTTPS on", sa[0], "port", sa[1], "..."