Skip to content

Server https

https-server.py


#!/usr/bin/env python3
from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl

class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.end_headers()
        self.wfile.write(b'Hello from hacker!')
httpd = HTTPServer(
    ('localhost', 443), 
    SimpleHTTPRequestHandler
)
httpd.socket = ssl.wrap_socket (
    httpd.socket, 
    keyfile="key.pem", 
    certfile='cert.pem', 
    server_side=True
)
httpd.serve_forever()
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -passout pass:hacker