# Usage: python3 python_http_listener.py <port> <server_public.pem> <server_private.pem>

import http.server
import ssl
from sys import argv

# Specify the server address and port
host = 'localhost'
port = port=int(argv[1])

# Specify the path to your SSL certificate and key
certfile = str(argv[2])
keyfile = str(argv[3])

#certfile = 'server_public.pem'
#keyfile = 'server_private.pem'

# Create an SSL context
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain(certfile=certfile, keyfile=keyfile)

# Create an HTTPS server
httpd = http.server.HTTPServer((host, port), http.server.SimpleHTTPRequestHandler)

# Configure the server to use SSL
httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True)

print(f"Starting HTTPS server on {host}:{port}...")
httpd.serve_forever()
