-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-self-signed-cert.sh
More file actions
executable file
·56 lines (45 loc) · 1.34 KB
/
create-self-signed-cert.sh
File metadata and controls
executable file
·56 lines (45 loc) · 1.34 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
#!/bin/bash
# Create self-signed certificate for local HTTPS proxy
CERT_DIR="${CERT_DIR:-$(pwd)/.certs}"
mkdir -p "$CERT_DIR"
cd "$CERT_DIR"
echo "🔐 Creating self-signed certificate for local HTTPS..."
# Get local IP if not provided
if [ -z "$LOCAL_NETWORK_IP" ]; then
if command -v ip &> /dev/null; then
LOCAL_NETWORK_IP=$(ip route get 1.1.1.1 | grep -oP 'src \K\S+' 2>/dev/null)
elif command -v ipconfig &> /dev/null; then
LOCAL_NETWORK_IP=$(ipconfig getifaddr en0 2>/dev/null)
fi
fi
LOCAL_NETWORK_IP="${LOCAL_NETWORK_IP:-127.0.0.1}"
echo "📡 Using local IP: $LOCAL_NETWORK_IP"
# Create certificate configuration
cat > cert.conf << EOF
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US
ST = Development
L = Local
O = ${COMPANY_NAME:-"Firebase Emulator Proxy"}
CN = $LOCAL_NETWORK_IP
[v3_req]
basicConstraints = CA:FALSE
keyUsage = keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
IP.1 = $LOCAL_NETWORK_IP
IP.2 = 127.0.0.1
DNS.1 = localhost
EOF
# Generate private key and certificate
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout key.pem \
-out cert.pem \
-config cert.conf
echo "✅ Certificate created successfully!"
echo "📄 Certificate: $CERT_DIR/cert.pem"
echo "🔑 Private key: $CERT_DIR/key.pem"