@@ -7354,12 +7354,15 @@ tls_time() {
7354
7354
return 0
7355
7355
}
7356
7356
7357
- # rfc8461
7357
+ # rfc8461, rfc8460
7358
7358
sub_mta_sts() {
7359
7359
local mta_sts_record=""
7360
7360
local policy=""
7361
7361
local smtp_tls_record=""
7362
7362
local spaces="$1"
7363
+ # we might reconsider this as booleans arent very flexible:
7364
+ local mta_sts_record_ok=false policy_ok=false smtp_tls_record_ok=false
7365
+ local jsonID="smtp_mtasts"
7363
7366
local useragent="$UA_STD"
7364
7367
$SNEAKY && useragent="$UA_SNEAKY"
7365
7368
@@ -7377,23 +7380,19 @@ sub_mta_sts() {
7377
7380
pr_bold " MTA-STS Policy "
7378
7381
7379
7382
mta_sts_record="$(get_txt_record _mta-sts.$NODE)"
7380
- # look for exact match for 'v=STSv1'
7381
- # look for exact match for 'id='
7382
-
7383
+ # look for exact match for 'v=STSv1' and 'id='
7384
+ if [[ "$mta_sts_record" =~ v=STSv1 ]] && [[ "$mta_sts_record" =~ id= ]] && [[ "$mta_sts_record" =~ \; ]]; then
7385
+ # id check needs to improved , see sts-id in https://tools.ietf.org/html/rfc8461#section-3.1
7386
+ mta_sts_record_ok=true
7387
+ fi
7383
7388
# echo "$mta_sts_record"; echo
7384
7389
7385
7390
policy="$(safe_echo "GET /.well-known/mta-sts.txt HTTP/1.1\r\nHost: mta-sts.$NODE\r\nUser-Agent: $useragent\r\nAccept-Encoding: identity\r\nAccept: text/*\r\nConnection: Close\r\n\r\n" | $OPENSSL s_client $(s_client_options "-quiet -ign_eof -connect $NODEIP:443 $PROXY $SNI") 2>$ERRFILE)"
7386
7391
# here also the openssl return val needs to be checked
7387
7392
7388
- #tmp="$(printf "$policy" | awk '/^$/ { p=1;next } { if(!p) { print } }')"
7389
- # policy="$(awk '/^$/ { p=1;next } { if(!p) { print } }' <<< "$policy")"
7390
7393
policy="$(print_after_blankline "$policy")"
7391
- #echo "POLICY2: $tmp "
7392
7394
# echo "$policy"; echo
7393
7395
7394
- # header needs to be stripped. Either the lower bytes which come after Content-Length in the header.
7395
- # or starting from version or starting after blank line
7396
-
7397
7396
# check policy:
7398
7397
# - grep -Ew 'version|mode|mx|max_age'
7399
7398
# - version.*STSv1$
@@ -7402,28 +7401,54 @@ sub_mta_sts() {
7402
7401
# - max_age should be sufficient otherwise caching it is ~useless, see HSTS
7403
7402
# - whether mx record matches
7404
7403
7404
+ # for the time being:
7405
+ [[ -n "$policy" ]] && policy_ok=true
7406
+
7405
7407
if [[ $DEBUG -ge 1 ]]; then
7406
7408
echo "$mta_sts_record" >$TMPFILE/_mta-sts.$NODE.txt
7407
7409
echo "$policy" >$TMPFILE/$NODE.mta-sts.well-known_mta-sts.txt
7408
7410
echo "$smtp_tls_record" > $TMPFILE/_smtp._tls.$NODE
7409
7411
fi
7410
7412
7411
7413
smtp_tls_record="$(get_txt_record _smtp._tls.$NODE)"
7414
+ # for the time being:
7415
+ [[ -n "$smtp_tls_record" ]] && smtp_tls_record_ok=true
7412
7416
7413
- outln "valid _mta-sts TXT record \"$mta_sts_record\""
7417
+ if "$mta_sts_record_ok"; then
7418
+ pr_svrty_good "valid"
7419
+ fileout "${jsonID}_txtrecord" "OK" "valid _mta-sts TXT record \"$mta_sts_record\""
7420
+ else
7421
+ pr_svrty_low "invalid"
7422
+ fileout "${jsonID}_txtrecord" "OK" "valid _mta-sts TXT record \"$mta_sts_record\""
7423
+ fi
7424
+ outln " _mta-sts TXT record \"$mta_sts_record\""
7414
7425
out "$spaces"
7415
- outln "valid enforced policy \"https://mta-sts.$NODE/.well-known/mta-sts.txt\""
7426
+
7427
+ if "$policy_ok"; then
7428
+ pr_svrty_good "valid and enforced"
7429
+ fileout "${jsonID}_policy" "OK" "valid and enforced policy file \"https://mta-sts.$NODE/.well-known/mta-sts.txt\""
7430
+ else
7431
+ # missing: too short, not enforced, etc..
7432
+ pr_svrty_low "invalid"
7433
+ fileout "${jsonID}_policy" "LOW" "invalid policy file \"https://mta-sts.$NODE/.well-known/mta-sts.txt\""
7434
+ fi
7435
+ outln " policy file \"https://mta-sts.$NODE/.well-known/mta-sts.txt\""
7416
7436
out "$spaces"
7417
- outln "optional _smtp._tls TXT record \"$smtp_tls_record\""
7437
+
7438
+ if "$smtp_tls_record_ok"; then
7439
+ outln "optional _smtp._tls TXT record \"$smtp_tls_record\""
7440
+ fileout "${jsonID}_tlsrpt" "INFO" "optional _smtp._tls TXT record \"$smtp_tls_record\""
7441
+ else
7442
+ outln "No TLS RPT record"
7443
+ fileout "${jsonID}_tlsrpt" "INFO" "no or invalid optional _smtp._tls TXT record \"$smtp_tls_record\""
7444
+ fi
7418
7445
7419
7446
return 0
7420
7447
}
7421
7448
7422
- # e.g. for removing the HTTP header
7449
+ # e.g. for removing the HTTP header. To be moved to the top
7423
7450
#
7424
7451
print_after_blankline() {
7425
- # doesn't work (oneliner with $1 instead of multiline):
7426
- #awk '/^$/ { p=1;next } { if(p) { print } }' <<< $1
7427
7452
local first=true
7428
7453
local line=""
7429
7454
@@ -7438,15 +7463,8 @@ print_after_blankline() {
7438
7463
fi
7439
7464
fi
7440
7465
done <<< $1
7441
- set +x
7442
7466
}
7443
7467
7444
- # e.g. for removing the body
7445
- #
7446
- print_before_blankline() {
7447
- # doesn't work (oneliner with $1 instead of multiline):
7448
- awk '/^$/ { p=1;next } { if(!p) { print } }' <<< $1
7449
- }
7450
7468
7451
7469
7452
7470
# RFC 6394
0 commit comments