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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-06-26 17:27:32 -07:00 committed by Tim Abbott
parent 918fcb9f6f
commit fa89d1b266
3 changed files with 14 additions and 5 deletions

View File

@ -50,6 +50,17 @@ if [ -z "$FORCE" ] && { [ -e "$KEYFILE" ] || [ -e "$CERTFILE" ]; }; then
fi fi
rm -f "$KEYFILE" "$CERTFILE" 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 config="$(mktemp)" || exit 1
trap 'rm -f "$config"' EXIT trap 'rm -f "$config"' EXIT
@ -72,7 +83,7 @@ commonName = $EXTERNAL_HOST
[ v3_req ] [ v3_req ]
basicConstraints = CA:FALSE basicConstraints = CA:FALSE
subjectAltName = DNS:$EXTERNAL_HOST subjectAltName = $subjectAltName
EOF EOF
if [ "$is_redhat" = true ]; then if [ "$is_redhat" = true ]; then

View File

@ -1,6 +1,5 @@
Self-signed certificate encountered. Self-signed certificate encountered.
WARNING: no certificate subject alternative name matches WARNING: certificate common name 127.0.0.1 doesn't match requested host name localhost.
requested host name localhost.
HTTP/1.1 302 Found HTTP/1.1 302 Found
Server: nginx/1.14.0 (Ubuntu) Server: nginx/1.14.0 (Ubuntu)
Content-Type: text/html; charset=utf-8 Content-Type: text/html; charset=utf-8

View File

@ -1,6 +1,5 @@
Self-signed certificate encountered. Self-signed certificate encountered.
WARNING: no certificate subject alternative name matches WARNING: certificate common name 127.0.0.1 doesn't match requested host name localhost.
requested host name localhost.
HTTP/1.1 302 Found HTTP/1.1 302 Found
Server: nginx/1.17.10 (Ubuntu) Server: nginx/1.17.10 (Ubuntu)
Content-Type: text/html; charset=utf-8 Content-Type: text/html; charset=utf-8