@@ -8386,12 +8386,14 @@ wildcard_match()
83868386# 8, if the server name provided is a wildcard match against the CN
83878387# 9, if the server name provided matches a name in the SAN AND is a wildcard match against the CN
83888388# 10, if the server name provided is a wildcard match against the CN AND a name in the SAN
8389+ #
8390+ # Add 128 to the return value if the CN or a DNS name in the SAN is a wildcard.
83898391
83908392compare_server_name_to_cert() {
83918393 local cert="$1"
83928394 local servername cns cn dns_sans ip_sans san dercert tag
83938395 local srv_id="" xmppaddr=""
8394- local -i i len len1 cn_match=0
8396+ local -i i len len1 cn_match=0 wildcard_cert=0
83958397 local -i subret=0 # no error condition, passing results
83968398
83978399 HAS_DNS_SANS=false
@@ -8536,10 +8538,16 @@ compare_server_name_to_cert() {
85368538 fi
85378539
85388540 # Check whether any of the DNS names in the certificate are wildcard names
8539- # that match the servername
8541+ # and if they match the servername
85408542 if [[ $subret -eq 0 ]]; then
85418543 while read san; do
85428544 [[ -n "$san" ]] || continue
8545+ is_wildcard "$san"
8546+ if [[ $? -eq 0 ]]; then
8547+ wildcard_cert=128
8548+ else
8549+ continue
8550+ fi
85438551 wildcard_match "$servername" "$san"
85448552 [[ $? -eq 0 ]] && subret=2 && break
85458553 done <<< "$dns_sans"
@@ -8555,13 +8563,20 @@ compare_server_name_to_cert() {
85558563 # Check whether the CN matches the servername
85568564 [[ $(toupper "$cn") == "$servername" ]] && cn_match=4 && break
85578565
8558- # Check whether the CN is a wildcard name that matches the servername
8566+ # Check whether the CN is a wildcard name and if it matches the servername
85598567 # NOTE: Don't stop loop on a wildcard match in case there is another CN
85608568 # that is an exact match.
8569+ is_wildcard "$cn"
8570+ if [[ $? -eq 0 ]]; then
8571+ wildcard_cert=128
8572+ else
8573+ continue
8574+ fi
85618575 wildcard_match "$servername" "$cn"
85628576 [[ $? -eq 0 ]] && cn_match=8
85638577 done <<< "$cns"
85648578 subret+=$cn_match
8579+ subret+=$wildcard_cert
85658580 return $subret
85668581}
85678582
@@ -9456,7 +9471,7 @@ certificate_info() {
94569471 # supported by the client.
94579472 has_dns_sans=$HAS_DNS_SANS
94589473
9459- case $trust_sni in
9474+ case $(( trust_sni%128)) in
94609475 0) trustfinding="certificate does not match supplied URI"
94619476 set_grade_cap "M" "Domain name mismatch"
94629477 ;;
@@ -9483,10 +9498,10 @@ certificate_info() {
94839498 ;;
94849499 esac
94859500
9486- if [[ $trust_sni -eq 0 ]]; then
9501+ if [[ $(( trust_sni%128)) -eq 0 ]]; then
94879502 pr_svrty_high "$trustfinding"
94889503 trust_sni_finding="HIGH"
9489- elif [[ $trust_sni -eq 4 ]] || [[ $trust_sni -eq 8 ]]; then
9504+ elif [[ $(( trust_sni%128)) -eq 4 ]] || [[ $(( trust_sni%128)) -eq 8 ]]; then
94909505 if [[ $SERVICE == HTTP ]] || "$ASSUME_HTTP"; then
94919506 # https://bugs.chromium.org/p/chromium/issues/detail?id=308330
94929507 # https://bugzilla.mozilla.org/show_bug.cgi?id=1245280
@@ -9513,17 +9528,17 @@ certificate_info() {
95139528 # See issue #733.
95149529 if [[ -z "$sni_used" ]]; then
95159530 trustfinding_nosni=""
9516- elif [[ $trust_sni -eq $trust_nosni && "$has_dns_sans" == "$has_dns_sans_nosni" ]] || \
9517- [[ $trust_sni -eq 0 && $trust_nosni -eq 0 ]]; then
9531+ elif [[ $(( trust_sni%128)) -eq $(( trust_nosni%128)) && "$has_dns_sans" == "$has_dns_sans_nosni" ]] || \
9532+ [[ $(( trust_sni%128)) -eq 0 && $(( trust_nosni%128)) -eq 0 ]]; then
95189533 trustfinding_nosni=" (same w/o SNI)"
9519- elif [[ $trust_nosni -eq 0 ]]; then
9520- if [[ $trust_sni -eq 4 ]] || [[ $trust_sni -eq 8 ]]; then
9534+ elif [[ $(( trust_nosni%128)) -eq 0 ]]; then
9535+ if [[ $(( trust_sni%128)) -eq 4 ]] || [[ $(( trust_sni%128)) -eq 8 ]]; then
95219536 trustfinding_nosni=" (w/o SNI: certificate does not match supplied URI)"
95229537 else
95239538 trustfinding_nosni=" (SNI mandatory)"
95249539 fi
9525- elif [[ $trust_nosni -eq 4 ]] || [[ $trust_nosni -eq 8 ]] || [[ $trust_sni -eq 4 ]] || [[ $trust_sni -eq 8 ]]; then
9526- case $trust_nosni in
9540+ elif [[ $(( trust_nosni%128)) -eq 4 ]] || [[ $(( trust_nosni%128)) -eq 8 ]] || [[ $(( trust_sni%128)) -eq 4 ]] || [[ $(( trust_sni%128)) -eq 8 ]]; then
9541+ case $(( trust_nosni%128)) in
95279542 1) trustfinding_nosni=" (w/o SNI: Ok via SAN)" ;;
95289543 2) trustfinding_nosni=" (w/o SNI: Ok via SAN wildcard)" ;;
95299544 4) if "$has_dns_sans_nosni"; then
@@ -9543,12 +9558,12 @@ certificate_info() {
95439558 9) trustfinding_nosni=" (w/o SNI: Ok via CN wildcard and SAN)" ;;
95449559 10) trustfinding_nosni=" (w/o SNI: Ok via SAN wildcard and CN wildcard)" ;;
95459560 esac
9546- elif [[ $trust_sni -ne 0 ]]; then
9561+ elif [[ $(( trust_sni%128)) -ne 0 ]]; then
95479562 trustfinding_nosni=" (works w/o SNI)"
95489563 else
95499564 trustfinding_nosni=" (however, works w/o SNI)"
95509565 fi
9551- if [[ -n "$sni_used" ]] || [[ $trust_nosni -eq 0 ]] || [[ $trust_nosni -ne 4 && $trust_nosni -ne 8 ]]; then
9566+ if [[ -n "$sni_used" ]] || [[ $(( trust_nosni%128)) -eq 0 ]] || [[ $(( trust_nosni%128)) -ne 4 && $(( trust_nosni%128)) -ne 8 ]]; then
95529567 outln "$trustfinding_nosni"
95539568 elif [[ $SERVICE == HTTP ]] || "$ASSUME_HTTP"; then
95549569 prln_svrty_high "$trustfinding_nosni"
@@ -9558,7 +9573,7 @@ certificate_info() {
95589573
95599574 fileout "cert_trust${json_postfix}" "$trust_sni_finding" "${trustfinding}${trustfinding_nosni}"
95609575
9561- if [[ "$ trust_sni" =~ ^(2|6|8|9|10)$ ]] || [[ "$ trust_nosni" =~ ^(2|6|8|9|10)$ ]]; then
9576+ if [[ $(( trust_sni&128)) -eq 128 ]] || [[ $(( trust_nosni&128)) -eq 128 ]]; then
95629577 out "${spaces}"
95639578 pr_svrty_low "wildcard certificate" ; outln " could be problematic, see other hosts at"
95649579 outln "${spaces}https://search.censys.io/search?resource=hosts&virtual_hosts=INCLUDE&q=$cert_fingerprint_sha2"
@@ -10164,7 +10179,7 @@ run_server_defaults() {
1016410179 # $NODE being tested or if it has the same subject
1016510180 # (CN and SAN) as other certificates for this host.
1016610181 compare_server_name_to_cert "$HOSTCERT"
10167- [[ $? -ne 0 ]] && success[n]=0 || success[n]=1
10182+ [[ $(($?%128)) -ne 0 ]] && success[n]=0 || success[n]=1
1016810183
1016910184 if [[ ${success[n]} -ne 0 ]]; then
1017010185 cn_nosni="$(toupper "$(get_cn_from_cert $HOSTCERT)")"
0 commit comments