Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

generate-self-signed-cert: Correct subjectAltName for an IP address.

Anders Kaseorgfa89d1b266f7
diff --git a/scripts/setup/generate-self-signed-cert b/scripts/setup/generate-self-signed-cert
index f2d1a1fffa0..071679850d8 100755
--- a/scripts/setup/generate-self-signed-cert
+++ b/scripts/setup/generate-self-signed-cert
@@ -50,6 +50,17 @@ if [ -z "$FORCE" ] && { [ -e "$KEYFILE" ] || [ -e "$CERTFILE" ]; }; then
fi
rm -f "$KEYFILE" "$CERTFILE"
+if [[ "$EXTERNAL_HOST" =~ ^(([0-9]+\.){3}[0-9]+)(:[0-9]+)?$ ]]; then
+ subjectAltName="IP:${BASH_REMATCH[1]}" # IPv4 address
+elif [[ "$EXTERNAL_HOST" =~ ^\[([^][]*)\](:[0-9]+)?$ ]]; then
+ subjectAltName="IP:${BASH_REMATCH[1]}" # IPv6 address
+elif [[ "$EXTERNAL_HOST" =~ ^([^:]+)(:[0-9]+)?$ ]]; then
+ subjectAltName="DNS:${BASH_REMATCH[1]}"
+else
+ echo "$0: invalid host $EXTERNAL_HOST" >&2
+ exit 1
+fi
+
config="$(mktemp)" || exit 1
trap 'rm -f "$config"' EXIT
@@ -72,7 +83,7 @@ commonName = $EXTERNAL_HOST
[ v3_req ]
basicConstraints = CA:FALSE
-subjectAltName = DNS:$EXTERNAL_HOST
+subjectAltName = $subjectAltName
EOF
if [ "$is_redhat" = true ]; then
diff --git a/tools/ci/success-http-headers-bionic.txt b/tools/ci/success-http-headers-bionic.txt
index d9961e307d2..20c863ed5b9 100644
--- a/tools/ci/success-http-headers-bionic.txt
+++ b/tools/ci/success-http-headers-bionic.txt
@@ -1,6 +1,5 @@
Self-signed certificate encountered.
-WARNING: no certificate subject alternative name matches
- requested host name ‘localhost’.
+ WARNING: certificate common name ‘127.0.0.1’ doesn't match requested host name ‘localhost’.
HTTP/1.1 302 Found
Server: nginx/1.14.0 (Ubuntu)
Content-Type: text/html; charset=utf-8
diff --git a/tools/ci/success-http-headers-focal.txt b/tools/ci/success-http-headers-focal.txt
index ac28296c689..63d6e0b2302 100644
--- a/tools/ci/success-http-headers-focal.txt
+++ b/tools/ci/success-http-headers-focal.txt
@@ -1,6 +1,5 @@
Self-signed certificate encountered.
-WARNING: no certificate subject alternative name matches
- requested host name ‘localhost’.
+ WARNING: certificate common name ‘127.0.0.1’ doesn't match requested host name ‘localhost’.
HTTP/1.1 302 Found
Server: nginx/1.17.10 (Ubuntu)
Content-Type: text/html; charset=utf-8