PlasticSlices/Experiments: httpsd.py.patch
File httpsd.py.patch, 1.6 KB (added by , 13 years ago) |
---|
-
httpsd.py
old new 1 1 ''' 2 2 SimpleSecureHTTPServer.py - simple HTTP server supporting SSL. 3 Modified from from http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/ 3 4 4 5 - replace fpem with the location of your .pem server file. 5 - the default port is 443.6 6 7 usage: python SimpleSecureHTTPServer.py 7 usage: python SimpleSecureHTTPServer.py <ipaddr> <port> 8 8 9 ''' 9 import socket, os 10 import socket, os, sys 10 11 from SocketServer import BaseServer 11 12 from BaseHTTPServer import HTTPServer 12 13 from SimpleHTTPServer import SimpleHTTPRequestHandler 13 14 from OpenSSL import SSL 14 15 16 IPADDR = sys.argv[1] 17 PORT = int(sys.argv[2]) 15 18 16 19 class SecureHTTPServer(HTTPServer): 17 20 def __init__(self, server_address, HandlerClass): 18 21 BaseServer.__init__(self, server_address, HandlerClass) 19 22 ctx = SSL.Context(SSL.SSLv23_METHOD) 23 fpem = '../localhost.localdomain.pem' 20 24 #server.pem's location (containing the server private key and 21 25 #the server certificate). 22 fpem = '/path/server.pem'23 26 ctx.use_privatekey_file (fpem) 24 27 ctx.use_certificate_file(fpem) 25 28 self.socket = SSL.Connection(ctx, socket.socket(self.address_family, … … 37 40 38 41 def test(HandlerClass = SecureHTTPRequestHandler, 39 42 ServerClass = SecureHTTPServer): 40 server_address = ( '', 443) # (address, port)43 server_address = (IPADDR, PORT ) # (address, port) 41 44 httpd = ServerClass(server_address, HandlerClass) 42 45 sa = httpd.socket.getsockname() 43 46 print "Serving HTTPS on", sa[0], "port", sa[1], "..."