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 ..
Clicking on the Red Not Secure we get more info:
Let's look at the 'certificate invalid' details:
What step(s) did I do incorrectly?




self signed certificatescan'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/…