diff --git a/generate_cert.py b/generate_cert.py index 78e1e13..b8185bf 100644 --- a/generate_cert.py +++ b/generate_cert.py @@ -7,54 +7,70 @@ import subprocess import sys import os + def generate_certificate(): """Generate self-signed certificate using OpenSSL""" - + cert_file = "cert.pem" key_file = "key.pem" - + # Check if OpenSSL is available try: - subprocess.run(["openssl", "version"], - capture_output=True, check=True) + subprocess.run(["openssl", "version"], capture_output=True, check=True) except (subprocess.CalledProcessError, FileNotFoundError): print("ERROR: OpenSSL not found!") print("\nFor Windows, you can:") - print("1. Install OpenSSL from: https://slproweb.com/products/Win32OpenSSL.html") + print( + "1. Install OpenSSL from: https://slproweb.com/products/Win32OpenSSL.html" + ) print("2. Or use Git Bash which includes OpenSSL") print("3. Or use WSL (Windows Subsystem for Linux)") return False - + print("Generating self-signed certificate...") print("This will create cert.pem and key.pem files") print() - + # Generate certificate valid for 365 days cmd = [ - "openssl", "req", "-x509", - "-newkey", "rsa:4096", - "-keyout", key_file, - "-out", cert_file, - "-days", "365", + "openssl", + "req", + "-x509", + "-newkey", + "rsa:4096", + "-keyout", + key_file, + "-out", + cert_file, + "-days", + "365", "-nodes", # No passphrase - "-subj", "/C=US/ST=State/L=City/O=Organization/CN=localhost" + "-subj", + "/C=US/ST=State/L=City/O=Organization/CN=localhost", ] - + try: subprocess.run(cmd, check=True) print(f"\nāœ“ Certificate created: {os.path.abspath(cert_file)}") print(f"āœ“ Private key created: {os.path.abspath(key_file)}") print("\nYou can now run the server with HTTPS:") - print(f" python src/test_server.py --ssl-cert {cert_file} --ssl-key {key_file} --hook-port 8443") + print( + f" python src/test_server.py --ssl-cert {cert_file} --ssl-key {key_file} --hook-port 8443" + ) print("\nOr webhook-only HTTPS:") - print(f" python src/test_server.py --ssl-cert {cert_file} --ssl-key {key_file} --hook-port 8443 --hook-ssl-only") - print("\nNote: Self-signed certificates will show security warnings in browsers.") + print( + f" python src/test_server.py --ssl-cert {cert_file} --ssl-key {key_file} --hook-port 8443 --hook-ssl-only" + ) + print( + "\nNote: Self-signed certificates will show security warnings in browsers." + ) print("For production, use certificates from a trusted CA like Let's Encrypt.") return True except subprocess.CalledProcessError as e: print(f"ERROR: Failed to generate certificate: {e}") return False + if __name__ == "__main__": if not generate_certificate(): sys.exit(1) diff --git a/src/test_server.py b/src/test_server.py index 94942c7..df6d94c 100644 --- a/src/test_server.py +++ b/src/test_server.py @@ -306,9 +306,9 @@ if __name__ == "__main__": await site1.start() await site2.start() - print(f"Main server running on {protocol_main}://{args.host}:{args.port}") + print(f"Starting main server on {args.host}:{args.port} ({protocol_main})") print( - f"Webhook server running on {protocol_hook}://{args.host}:{args.hook_port}/hook" + f"Starting webhook server on {args.host}:{args.hook_port} ({protocol_hook})" ) # Keep running diff --git a/src/test_webhook.py b/src/test_webhook.py index 430b5c8..491a27f 100644 --- a/src/test_webhook.py +++ b/src/test_webhook.py @@ -9,7 +9,7 @@ import json async def test_webhook(): - url = "http://localhost:7432/hook" + url = "https://studspider.sh:8443/hook" # Your Square webhook payload payload = {