Skip to content

Instantly share code, notes, and snippets.

@joekir
Last active January 27, 2020 18:27
Show Gist options
  • Save joekir/f014ed2c3e6c3e8a10a8e6cba17f8435 to your computer and use it in GitHub Desktop.
Save joekir/f014ed2c3e6c3e8a10a8e6cba17f8435 to your computer and use it in GitHub Desktop.
Super Simple local HTTPS Server
#!/bin/bash
set -eu
CERTNAME=cert.pem
KEYNAME=key.pem
COMBINED=certs_and_key.pem
openssl req -x509 -newkey rsa:1024 -keyout ${KEYNAME} -out ${CERTNAME} -days 365 -subj '/CN=localhost' -passout pass:foobar
openssl rsa -in ${KEYNAME} -out ${KEYNAME} -passin pass:foobar
cat ${KEYNAME} > ${COMBINED}
cat ${CERTNAME} >> ${COMBINED}
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
httpd = HTTPServer(('localhost', 8443), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket,
keyfile="key.pem",
certfile='cert.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