Created
November 5, 2020 01:26
-
-
Save stephenbradshaw/a2b72b5b58c93ca74b54f7747f18a481 to your computer and use it in GitHub Desktop.
Python 3 Simple HTTPS server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# python3 update of https://gist.github.com/dergachev/7028596 | |
# Create a basic certificate using openssl: | |
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes | |
# Or to set CN, SAN and/or create a cert signed by your own root CA: https://thegreycorner.com/pentesting_stuff/writeups/selfsignedcert.html | |
import http.server | |
import ssl | |
httpd = http.server.HTTPServer(('127.0.0.1', 443), http.server.SimpleHTTPRequestHandler) | |
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./server.pem', server_side=True) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@BagroSlave Could be a Windows thing with parsing the PEM file in the Python ssl library. You might want to try modifying the load_cert_chain line to specify the key file specifically, as discussed here. Maybe also seperate the key content into a different file from the cert, make sure the openssl command line can still parse both as with the commands above, and try either Windows or Linux line ending patterns in the PEM file in case thats causing a parsing error in Python ssl. If none of that works Im out of ideas.