0

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?

2
  • when I search info in Google then I see self signed certificates can't be trusted. You would have to accept exception in web browser to use it. To create trusted cert you would have to generate RootCA - and use it sign your cert. But even here you have to add RootCA to system as trusted cert. And all this for security reason - if you could so easy create tursted cert then hackers would use it. freecodecamp.org/news/… Commented Jun 11, 2020 at 2:11
  • @furas Nice link : seems there are several small additional steps to do this properly. Feel free to make an answer Commented Jun 11, 2020 at 2:38

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.