Creating a secure web server

Creating a secure web server

Postby PeterSteele » Thu Dec 05, 2013 7:11 pm

We've been using Python's SimpleHTTPServer module for use as a simple file server. We've decided to make the file server more secure by using https, and after doing some research I found lots of code to setup a secure web server in Python. None of the examples I've found though work.

The simplest code fragment I found was this:

Code: Select all
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='path/to/server.pem', server_side=True)
httpd.serve_forever()

where server.pem is a pem file we've been using with another web server we're running. The Python code launches and runs without apparent errors but when I try to connect to the server using https://<server-ip>:4443 the browser prints the message "This webpage is not available." The Python code does not report any errors, and I can't even tell if the connection made it all the way through. I've tried various other versions of this code that I've come across but none of them work.

I have a Jersey-based web server running on another system that uses this same pem file and that works fine, but we want a small and light web server on this particular system, not a full blown web server like Jersey. As a test though I did setup Jersey on this system and it runs as expected, so I assume there is something wrong with my Python code. Can anyone explain what the problem might be?
Last edited by Yoriz on Thu Dec 05, 2013 7:13 pm, edited 1 time in total.
Reason: First post lock
PeterSteele
 
Posts: 2
Joined: Thu Dec 05, 2013 6:44 pm

Re: Creating a secure web server

Postby PeterSteele » Fri Dec 06, 2013 1:07 pm

Turns out my pem file was wrong. Why one pem file works for my Jersey based server but not my Python based server I don't really know--I'm not a pem file expert. Our resident security guy generated a new pem for me and that solved the probem...
PeterSteele
 
Posts: 2
Joined: Thu Dec 05, 2013 6:44 pm

Re: Creating a secure web server

Postby micseydel » Fri Dec 06, 2013 11:23 pm

Thanks for posting back the solution to your problem!
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1391
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to Networking

Who is online

Users browsing this forum: No registered users and 1 guest