Skip to content

Commit 801ee54

Browse files
author
Matthew Valancy
committed
fix: make certificate generation script more resilient
Enhanced manage-certificates.sh to work in more environments: - Skip generation if certificates already exist - Fall back to openssl if mkcert is not available - Generate self-signed certs as fallback (compatible with Playwright ignoreHTTPSErrors) - Exit gracefully instead of failing This fixes TLS test failures in environments without mkcert installed, such as GitHub Actions runners and minimal development setups.
1 parent 0b66021 commit 801ee54

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

scripts/manage-certificates.sh

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,39 @@ mkdir -p "$CERT_DIR"
2424

2525
case "$MODE" in
2626
"local")
27-
echo -e "${YELLOW}📝 Setting up LOCAL development certificates with mkcert...${NC}"
28-
27+
echo -e "${YELLOW}📝 Setting up LOCAL development certificates...${NC}"
28+
29+
# Check if certificates already exist
30+
if [ -f "$CERT_DIR/server-cert.pem" ] && [ -f "$CERT_DIR/server-key.pem" ]; then
31+
echo -e "${GREEN}✅ Certificates already exist, skipping generation${NC}"
32+
echo " Certificate: $CERT_DIR/server-cert.pem"
33+
echo " Private key: $CERT_DIR/server-key.pem"
34+
exit 0
35+
fi
36+
2937
# Check if mkcert is installed
3038
if ! command -v mkcert &> /dev/null; then
31-
echo -e "${RED}❌ mkcert is not installed!${NC}"
32-
echo "Please install mkcert first:"
33-
echo " macOS: brew install mkcert"
34-
echo " Linux: https://github.com/FiloSottile/mkcert#installation"
35-
exit 1
39+
echo -e "${YELLOW}⚠️ mkcert not found, using openssl for self-signed certificates...${NC}"
40+
# Generate self-signed certificate with openssl
41+
openssl req -x509 -newkey rsa:4096 -nodes \
42+
-keyout "$CERT_DIR/server-key.pem" \
43+
-out "$CERT_DIR/server-cert.pem" \
44+
-days 365 \
45+
-subj "/CN=localhost/O=GraphDone Development/C=US" \
46+
-addext "subjectAltName=DNS:localhost,DNS:*.localhost,DNS:graphdone.local,IP:127.0.0.1,IP:::1" 2>/dev/null || \
47+
openssl req -x509 -newkey rsa:4096 -nodes \
48+
-keyout "$CERT_DIR/server-key.pem" \
49+
-out "$CERT_DIR/server-cert.pem" \
50+
-days 365 \
51+
-subj "/CN=localhost/O=GraphDone Development/C=US"
52+
53+
chmod 600 "$CERT_DIR/server-key.pem"
54+
chmod 644 "$CERT_DIR/server-cert.pem"
55+
echo -e "${GREEN}✅ Self-signed certificates generated with openssl${NC}"
56+
echo " Certificate: $CERT_DIR/server-cert.pem"
57+
echo " Private key: $CERT_DIR/server-key.pem"
58+
echo -e "${YELLOW}Note: Browser will show warnings for self-signed certificates${NC}"
59+
exit 0
3660
fi
3761

3862
# Install local CA if not already installed

0 commit comments

Comments
 (0)