-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_https_server.sh
More file actions
168 lines (149 loc) · 4.93 KB
/
Copy pathstart_https_server.sh
File metadata and controls
168 lines (149 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# A2A Server HTTPS/TLS Setup Script
# This script demonstrates how to run the A2A server in both HTTP and HTTPS modes
echo "🔐 A2A Server HTTPS/TLS Setup"
echo "=============================="
# Function to check if port is available
check_port() {
local port=$1
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
echo "❌ Port $port is already in use"
return 1
else
echo "✅ Port $port is available"
return 0
fi
}
# Function to start HTTP server (development mode)
start_http_server() {
echo
echo "🌐 Starting HTTP Server (Development Mode)"
echo "----------------------------------------"
if check_port 8081; then
echo "Starting A2A server on HTTP port 8081..."
echo "Agent Card: http://localhost:8081/.well-known/agent-card.json"
echo "Server Info: http://localhost:8081/server-info"
echo
echo "Press Ctrl+C to stop the server"
echo
php -S localhost:8081 https_a2a_server.php
fi
}
# Function to start HTTPS server (production mode)
start_https_server() {
echo
echo "🔒 Starting HTTPS Server (Production Mode)"
echo "------------------------------------------"
if check_port 8443; then
echo "Generating SSL certificates..."
echo "Starting A2A server on HTTPS port 8443..."
echo "Agent Card: https://localhost:8443/.well-known/agent-card.json"
echo "Server Info: https://localhost:8443/server-info"
echo
echo "⚠️ Note: You may see SSL warnings for self-signed certificates"
echo " This is normal for development. Use proper certificates in production."
echo
echo "Press Ctrl+C to stop the server"
echo
A2A_MODE=production php -S localhost:8443 https_a2a_server.php
fi
}
# Function to run tests on both servers
run_tests() {
echo
echo "🧪 Testing Both HTTP and HTTPS Servers"
echo "======================================"
# Test HTTP server
echo "Testing HTTP server..."
if curl -s http://localhost:8081/.well-known/agent-card.json > /dev/null 2>&1; then
echo "✅ HTTP server is responding"
else
echo "❌ HTTP server is not responding"
fi
# Test HTTPS server (skip SSL verification for self-signed certs)
echo "Testing HTTPS server..."
if curl -k -s https://localhost:8443/.well-known/agent-card.json > /dev/null 2>&1; then
echo "✅ HTTPS server is responding"
else
echo "❌ HTTPS server is not responding"
fi
}
# Function to show server comparison
show_comparison() {
echo
echo "📊 HTTP vs HTTPS Comparison"
echo "==========================="
echo
echo "HTTP Mode (Development):"
echo " • Port: 8081"
echo " • Security: Basic (no encryption)"
echo " • Certificates: None required"
echo " • Usage: Development and testing"
echo
echo "HTTPS Mode (Production):"
echo " • Port: 8443"
echo " • Security: TLS encrypted"
echo " • Certificates: Auto-generated self-signed"
echo " • Usage: Production deployment"
echo " • Additional headers: HSTS, security headers"
echo
}
# Function to generate production certificates
generate_production_certs() {
echo
echo "🏭 Production Certificate Generation"
echo "==================================="
echo
echo "For production use, you should use proper SSL certificates."
echo "Here are some options:"
echo
echo "1. Let's Encrypt (free, automated):"
echo " certbot --nginx -d yourdomain.com"
echo
echo "2. Commercial SSL Certificate:"
echo " - Purchase from a trusted CA"
echo " - Generate CSR and private key"
echo " - Install issued certificate"
echo
echo "3. Self-signed (development only):"
echo " openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.crt -days 365 -nodes"
echo
}
# Main menu
show_menu() {
echo
echo "Please choose an option:"
echo "1) Start HTTP Server (Development)"
echo "2) Start HTTPS Server (Production)"
echo "3) Run Tests on Both Servers"
echo "4) Show HTTP vs HTTPS Comparison"
echo "5) Production Certificate Guide"
echo "6) Exit"
echo
read -p "Enter your choice (1-6): " choice
case $choice in
1) start_http_server ;;
2) start_https_server ;;
3) run_tests ;;
4) show_comparison ;;
5) generate_production_certs ;;
6) echo "Goodbye! 👋"; exit 0 ;;
*) echo "Invalid choice. Please try again."; show_menu ;;
esac
}
# Check requirements
echo "Checking requirements..."
if ! command -v php &> /dev/null; then
echo "❌ PHP is not installed"
exit 1
fi
if ! command -v curl &> /dev/null; then
echo "⚠️ curl is not installed (optional for testing)"
fi
echo "✅ Requirements satisfied"
# Show initial information
show_comparison
# Start menu loop
while true; do
show_menu
done