Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/system.func
Original file line number Diff line number Diff line change
Expand Up @@ -2178,13 +2178,14 @@ create_self_signed_cert() {
return 100
}

local san="DNS:${HOSTNAME},DNS:localhost,IP:${IP},IP:127.0.0.1"
local san="DNS:${HOSTNAME},DNS:localhost,IP:127.0.0.1" cn="${HOSTNAME%%.*}"
[[ -n "$IP" ]] && san="${san},IP:${IP}"
[[ -n "$EXTRA_SAN" ]] && san="${san},${EXTRA_SAN}"

mkdir -p "$CERT_DIR"
# 825 days is the most macOS and iOS accept, even for a certificate the user trusts.
$STD openssl req -new -newkey rsa:2048 -days 825 -nodes -x509 \
-subj "/CN=${HOSTNAME}" \
-subj "/CN=${cn:0:64}" \
-addext "subjectAltName=${san}" \
-keyout "$CERT_KEY" \
-out "$CERT_CRT" || {
Expand Down
8 changes: 8 additions & 0 deletions tests/self-signed-cert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,13 @@ create_self_signed_cert demo
check "an expiring certificate is renewed" "825" "$(days_left)"
check "and the key stays private" "600" "$(stat -c %a "$TEST_DIR/demo/demo.key")"

# GitHub's runners have a 66-character FQDN; a CN takes at most 64.
hostname() { case "$1" in -f) echo "runnervmccnms.3w315rw44o5elhmmntizv1xeth.bx.internal.cloudapp.net" ;; *) command hostname "$@" ;; esac; }
mv "$TEST_DIR/demo" "$TEST_DIR/demo.before"
create_self_signed_cert demo
check "a FQDN longer than a CN allows still gets a certificate" "825" "$(days_left)"
check "with the full name in its SAN" 1 "$(openssl x509 -noout -ext subjectAltName -in "$crt" 2>/dev/null | grep -c 'runnervmccnms.3w315rw44o5elhmmntizv1xeth.bx.internal.cloudapp.net')"
unset -f hostname

echo "${passed} passed, ${failed} failed"
[[ "$failed" -eq 0 ]]
Loading