#!/usr/bin/env bash set -euo pipefail SNI="${SEOH_GATEWAY_SNI:-api-gateway.dev.seoh.local}" DEPLOY="${SEOH_DEPLOY_ROOT:-/Users/chengang/Documents/surkw/产品/seoh/seoh-deploy}" cur=$(echo | timeout 8 openssl s_client -connect 127.0.0.1:3000 -servername "$SNI" 2>/dev/null \ | openssl x509 -noout -subject 2>/dev/null || true) echo "网关当前出示: ${cur:-<握手失败>}" if printf '%s' "$cur" | grep -q "CN *= *${SNI}"; then echo "✅ 证书匹配,无需处理"; exit 0 fi echo "❌ 未出示对外证书(C1),执行自愈…" cd "$DEPLOY" python3 scripts/enable-gateway-external-tls.py --root "$DEPLOY" docker compose -p seoh-deploy restart api-gateway for _ in $(seq 1 10); do sleep 3 [ "$(curl -sk -m 4 -o /dev/null -w '%{http_code}' https://localhost:3000/health)" = "200" ] && break done echo "=== 严格校验(证书链 + 主机名)===" curl -sS --cacert deploy-data/ca-dev/external-edge/root-ca.crt -m 8 -o /dev/null -w "HTTP=%{http_code}\n" \ -X POST "https://${SNI}:3000/api/system/seoh-identity-provider/otp/captcha/create@v1" \ -H 'Content-Type: application/json' -d '{"data":{"channel":"captcha","scene":"playground"}}'