WestCoastProjects
WestCoastProjects

Reputation: 63201

Invalid certificate warning when running the python HTTPServer

I am trying to run the python3 HTTPServer with self signed certificates. I created the self-signed certificates :

openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 
 -keyout key.localhost.pem -out cert.localhost.pem

Then I am using the python SimpleHTTPRequestHandler:

#!/usr/bin/env python3 
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
import socketserver

import sys
port = int(sys.argv[1])
# httpd = HTTPServer(('localhost', port), BaseHTTPRequestHandler)
httpd = socketserver.TCPServer(('localhost', port), SimpleHTTPRequestHandler)

keyfile="/Users/steve/key.localhost.pem" ;certfile='/Users/steve/cert.localhost.pem'
httpd.socket = ssl.wrap_socket (httpd.socket, 
       keyfile="/Users/steve/localhost.key", certfile='/Users/steve/localhost.crt', server_side=True)

httpd.serve_forever()

Let's try to load something from the web server at https://localhost:9443/tests.

Notice that we get a Not secure ..

enter image description here

Clicking on the Red Not Secure we get more info:

enter image description here

Let's look at the 'certificate invalid' details:

enter image description here

enter image description here

What step(s) did I do incorrectly?

Upvotes: 0

Views: 722

Answers (1)

furas
furas

Reputation: 142992

When I searched for this in Google I see that self signed certificates can't be trusted.
You would have to accept an exception in web browser to use it.

To create the trusted cert you would have to generate a RootCA and use it to sign your cert. But even here you have to add the RootCA to the system as a trusted cert.

All of this is for security reasons. If you could create a trusted cert so easily then hackers would use it.


BTW: One of the link which I found with Gooogle:

How to get HTTPS working on your local development environment in 5 minutes

Upvotes: 1

Related Questions