Skip to content

Commit 769837b

Browse files
committed
Force SNI to be the --xmpphost if passed
XMPP can be used with SNI in two contexts: - Standard RFC 6120 STARTTLS-based connections; in that case, SNI is most likely to be ignored, as XMPP uses another way to signal the target domain name (via the @to attribute on the stream header, which is already set correctly by testssl.sh). However, setting SNI to a different value than the @to attribute may lead to confusion. - XEP-0368 (XMPP-over-TLS) connections which omit the STARTTLS phase and go right for TLS (and inside that, XMPP). In that case, SNI is obviously required to be correct. XEP-0368 specifies that the SNI name MUST be the domain name of the service (not necessarily the host name of the endpoint, thanks to SRV records). Hence, this patch forces the SNI name to be the --xmpphost value, if --xmpphost is given. Note that it blatantly ignores whether XMPP is used otherwise.
1 parent b4c9437 commit 769837b

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

testssl.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4522,10 +4522,11 @@ modify_clienthello() {
45224522
# the SNI extension or replace it with the correct server name.
45234523
sni_extension_found=true
45244524
if [[ -n "$SNI" ]]; then
4525+
servername=${XMPP_HOST:-${NODE}}
45254526
# Create a server name extension that corresponds to $SNI
4526-
len_servername=${#NODE}
4527+
len_servername=${#servername}
45274528
hexdump_format_str="$len_servername/1 \"%02x\""
4528-
servername_hexstr=$(printf $NODE | hexdump -v -e "${hexdump_format_str}")
4529+
servername_hexstr=$(printf $servername | hexdump -v -e "${hexdump_format_str}")
45294530
# convert lengths we need to fill in from dec to hex:
45304531
len_servername_hex=$(printf "%02x\n" $len_servername)
45314532
len_sni_listlen=$(printf "%02x\n" $((len_servername+3)))
@@ -14514,9 +14515,10 @@ prepare_tls_clienthello() {
1451414515
#00 # server_name type (hostname)
1451514516
#00 15 # server_name length
1451614517
#66 66 66 66 66 66 2e 66 66 66 66 66 66 66 66 66 66 2e 66 66 66 target.mydomain1.tld # server_name target
14517-
len_servername=${#NODE}
14518+
servername=${XMPP_HOST:-${NODE}}
14519+
len_servername=${#servername}
1451814520
hexdump_format_str="$len_servername/1 \"%02x,\""
14519-
servername_hexstr=$(printf $NODE | hexdump -v -e "${hexdump_format_str}" | sed 's/,$//')
14521+
servername_hexstr=$(printf $servername | hexdump -v -e "${hexdump_format_str}" | sed 's/,$//')
1452014522
# convert lengths we need to fill in from dec to hex:
1452114523
len_servername_hex=$(printf "%02x\n" $len_servername)
1452214524
len_sni_listlen=$(printf "%02x\n" $((len_servername+3)))
@@ -19710,7 +19712,12 @@ parse_hn_port() {
1971019712
fi
1971119713

1971219714
debugme echo $NODE:$PORT
19713-
SNI="-servername $NODE"
19715+
if [[ -n "$XMPP_HOST" ]]; then
19716+
# XMPP host is set, force SNI to be that
19717+
SNI="-servername $XMPP_HOST"
19718+
else
19719+
SNI="-servername $NODE"
19720+
fi
1971419721
URL_PATH=$(sed 's/https:\/\///' <<< "$1" | sed 's/'"${NODE}"'//' | sed 's/.*'"${PORT}"'//') # remove protocol and node part and port
1971519722
URL_PATH=$(sed 's/\/\//\//g' <<< "$URL_PATH") # we rather want // -> /
1971619723
URL_PATH=${URL_PATH%%.} # strip trailing "." so that it is not interpreted as URL

0 commit comments

Comments
 (0)