Skip to content

Commit becd310

Browse files
committed
Address open UI problems for TLS 1.3 only hosts
While in 3.2 there was only a hint how to deal with TLS 1.3 only hosts, a restart with --openssl=/usr/bin/openssl or setting of OSSL_SHORTCUT-true was required. This PR changes the behavior: if an openssl version can be found in /usr/bin/openssl (or SUPPLIED via OPENSSL2=/home/version/ofopenssl testssl <cmdline>) which supports TLS 1.3 it switches automatically and informs the user that it has done so. This message is asynchonous and is implemented with a new function check_msg() and a global OPEN_MSG, so that we maintain the formatting. Otherwise it would have appeared between rDNS and service detection. Now it's nicely after service detection.
1 parent a20fd79 commit becd310

1 file changed

Lines changed: 42 additions & 20 deletions

File tree

testssl.sh

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ SYSTEM2="" # currently only being used for WSL = ba
243243
PRINTF="" # which external printf to use. Empty presets the internal one, see #1130
244244
CIPHERS_BY_STRENGTH_FILE=""
245245
TLS_DATA_FILE="" # mandatory file for socket-based handshakes
246-
OPENSSL="" # If you run this from GitHub it's ~/bin/openssl.$(uname).$(uname -m) otherwise /usr/bin/openssl
247-
OPENSSL2="" # When running from GitHub, this will be openssl version >=1.1.1 (auto determined)
248-
OPENSSL2_HAS_TLS_1_3=false # If we run with supplied binary AND /usr/bin/openssl supports TLS 1.3 this is set to true
246+
OPENSSL="" # ~/bin/openssl.$(uname).$(uname -m) if you run this from GitHub. Linux otherwise probably /usr/bin/openssl
247+
OPENSSL2=${OPENSSL2:-/usr/bin/openssl} # This will be openssl version >=1.1.1 (auto determined) as opposed to openssl-bad (OPENSSL)
248+
OPENSSL2_HAS_TLS_1_3=false # If we run with supplied binary AND $OPENSSL2 supports TLS 1.3 this wil be set to true
249+
OSSL_SHORTCUT=${OSSL_SHORTCUT:-true} # Hack: if during the scan turns out the OpenSSL binary supports TLS 1.3 would be a better choice
249250
OPENSSL_LOCATION=""
250251
IKNOW_FNAME=false
251252
FIRST_FINDING=true # is this the first finding we are outputting to file?
@@ -275,7 +276,6 @@ KNOWN_OSSL_PROB=false # We need OpenSSL a few times. This vari
275276
DETECTED_TLS_VERSION="" # .. as hex string, e.g. 0300 or 0303
276277
APP_TRAF_KEY_INFO="" # Information about the application traffic keys for a TLS 1.3 connection.
277278
TLS13_ONLY=false # Does the server support TLS 1.3 ONLY?
278-
OSSL_SHORTCUT=${OSSL_SHORTCUT:-false} # Hack: if during the scan turns out the OpenSSL binary supports TLS 1.3 would be a better choice, this enables it.
279279
TLS_EXTENSIONS=""
280280
TLS13_CERT_COMPRESS_METHODS=""
281281
CERTIFICATE_TRANSPARENCY_SOURCE=""
@@ -415,6 +415,7 @@ END_TIME=0 # .. ended
415415
SCAN_TIME=0 # diff of both: total scan time
416416
LAST_TIME=0 # only used for performance measurements (MEASURE_TIME=true)
417417
SERVER_COUNTER=0 # Counter for multiple servers
418+
OPEN_MSG="" # Null the poor man's implementation of a message stack
418419

419420
TLS_LOW_BYTE="" # For "secret" development stuff, see -q below
420421
HEX_CIPHER="" # -- " --
@@ -20297,7 +20298,7 @@ find_openssl_binary() {
2029720298
# not check /usr/bin/openssl -- if available. This is more a kludge which we shouldn't use for
2029820299
# every openssl feature. At some point we need to decide which with openssl version we go.
2029920300
# We also check, whether there's /usr/bin/openssl which has TLS 1.3
20300-
OPENSSL2=/usr/bin/openssl
20301+
OPENSSL2=${OPENSSL2:-/usr/bin/openssl}
2030120302
if [[ ! "$OSSL_NAME" =~ LibreSSL ]] && [[ ! $OSSL_VER =~ 1.1.1 ]] && [[ ! $OSSL_VER_MAJOR =~ 3 ]]; then
2030220303
if [[ -x $OPENSSL2 ]]; then
2030320304
$OPENSSL2 s_client -help 2>$s_client_has2
@@ -21015,6 +21016,9 @@ EOF
2101521016

2101621017
# arg1: text to display before "-->"
2101721018
# arg2: arg needed to accept to continue
21019+
# ret=0 : arg was acceppted to continue (batch mode doesn't do this,or warnings are turned off)
21020+
# 1 : arg was not acceppted by user or we're in bacth mode
21021+
2101821022
ignore_no_or_lame() {
2101921023
local a
2102021024

@@ -22033,21 +22037,26 @@ determine_optimal_proto() {
2203322037
[[ $? -ne 0 ]] && exit $ERR_CLUELESS
2203422038
elif "$all_failed" && ! "$ALL_FAILED_SOCKETS"; then
2203522039
if ! "$HAS_TLS13" && "$TLS13_ONLY"; then
22036-
pr_magenta " $NODE:$PORT appears to support TLS 1.3 ONLY. You better use --openssl=<path_to_openssl_supporting_TLS_1.3>"
22037-
if ! "$OSSL_SHORTCUT" || [[ ! -x /usr/bin/openssl ]] || /usr/bin/openssl s_client -tls1_3 2>&1 | grep -aiq "unknown option"; then
22038-
outln
22039-
fileout "$jsonID" "WARN" "$NODE:$PORT appears to support TLS 1.3 ONLY, but $OPENSSL does not support TLS 1.3"
22040-
ignore_no_or_lame " Type \"yes\" to proceed with $OPENSSL and accept all scan problems" "yes"
22041-
[[ $? -ne 0 ]] && exit $ERR_CLUELESS
22042-
MAX_OSSL_FAIL=10
22043-
else
22044-
# dirty hack but an idea for the future to be implemented upfront: Now we know, we'll better off
22045-
# with the OS supplied openssl binary. We need to initialize variables / arrays again though.
22046-
# And the service detection can't be made up for now
22047-
outln ", \n proceeding with /usr/bin/openssl"
22048-
OPENSSL=/usr/bin/openssl
22049-
find_openssl_binary
22050-
prepare_arrays
22040+
if "$OPENSSL2_HAS_TLS_1_3"; then
22041+
if "$OSSL_SHORTCUT" || [[ "$WARNINGS" == batch ]]; then
22042+
# switch w/o asking
22043+
OPEN_MSG=" $NODE:$PORT appeared to support TLS 1.3 ONLY. Thus switched implictly from\n \"$OPENSSL\" to \"$OPENSSL2\"."
22044+
fileout "$jsonID" "INFO" "$NODE:$PORT appears to support TLS 1.3 ONLY, switching from $OPENSSL to $OPENSSL2 was implictly enforced"
22045+
OPENSSL="$OPENSSL2"
22046+
find_openssl_binary
22047+
prepare_arrays
22048+
else
22049+
# now we need to ask the user
22050+
ignore_no_or_lame " Type \"yes\" to proceed with \"$OPENSSL2\" OR accept all scan problems" "yes"
22051+
if [[ $? -eq 0 ]]; then
22052+
fileout "$jsonID" "INFO" "$NODE:$PORT appears to support TLS 1.3 ONLY, switching from $OPENSSL to $OPENSSL2 by the user"
22053+
OPENSSL="$OPENSSL2"
22054+
find_openssl_binary
22055+
prepare_arrays
22056+
else
22057+
fileout "$jsonID" "WARN" "$NODE:$PORT appears to support TLS 1.3 ONLY, switching from $OPENSSL to $OPENSSL2 was denied by user"
22058+
fi
22059+
fi
2205122060
fi
2205222061
elif ! "$HAS_SSL3" && [[ "$(has_server_protocol "ssl3")" -eq 0 ]] && [[ "$(has_server_protocol "tls1_3")" -ne 0 ]] && \
2205322062
[[ "$(has_server_protocol "tls1_2")" -ne 0 ]] && [[ "$(has_server_protocol "tls1_1")" -ne 0 ]] &&
@@ -22092,6 +22101,18 @@ determine_optimal_proto() {
2209222101
}
2209322102

2209422103

22104+
# Check messages which needed to be processed. I.e. those which would have destroyed the nice
22105+
# screen output and thus havve been postponed. This is just an idea and is only used once
22106+
# but can be extended in the future. An array migh be more handy
22107+
#
22108+
check_msg() {
22109+
if [[ -n "$OPEN_MSG" ]]; then
22110+
outln "$OPEN_MSG"
22111+
OPEN_MSG=""
22112+
fi
22113+
}
22114+
22115+
2209522116
# arg1 (optional): ftp smtp, lmtp, pop3, imap, sieve, xmpp, xmpp-server, telnet, ldap, postgres, mysql, irc, nntp (maybe with trailing s)
2209622117
#
2209722118
determine_service() {
@@ -22132,6 +22153,7 @@ determine_service() {
2213222153
determine_optimal_proto
2213322154
# returns always 0:
2213422155
service_detection $OPTIMAL_PROTO
22156+
check_msg
2213522157
else # STARTTLS
2213622158
if [[ "$1" == postgres ]] || [[ "$1" == sieve ]]; then
2213722159
protocol="$1"

0 commit comments

Comments
 (0)