Created
September 25, 2024 19:28
-
-
Save Sy3Omda/ca83ebb59ae370d7af806dc8d211b2c8 to your computer and use it in GitHub Desktop.
self-signed certificate with python http.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
#!/bin/bash | |
CERT_FILE="localhost.pem" | |
cleanup() { | |
rm -f "$CERT_FILE" | |
exit 0 | |
} | |
trap cleanup SIGINT | |
openssl req -new -x509 -keyout "$CERT_FILE" -out "$CERT_FILE" -days 365 -nodes -subj "/CN=localhost" | |
python3 -c " | |
import http.server | |
import ssl | |
server_address = ('0.0.0.0', 443) | |
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler) | |
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) | |
context.load_cert_chain(certfile='$CERT_FILE') | |
httpd.socket = context.wrap_socket(httpd.socket, server_side=True) | |
httpd.serve_forever() | |
" | |
cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment