Browse Source

Merge pull request #1 from J-M0/more-posix

Various fixes
main
Jeffrey Bencteux 3 years ago committed by GitHub
parent
commit
5f5beee8dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      .github/workflows/ci.yml
  2. 57
      mailsecchk.sh

13
.github/workflows/ci.yml

@ -0,0 +1,13 @@
name: CI
on:
push:
pull_request:
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install shellcheck
run: sudo apt install shellcheck
- name: Run shellcheck
run: shellcheck --color=always mailsecchk.sh

57
mailsecchk.sh

@ -5,6 +5,8 @@
# This source code is licensed under the GPLv3 license found in the # This source code is licensed under the GPLv3 license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
# shellcheck disable=SC3043
usage() usage()
{ {
echo "Usage: $0 [OPTIONS]..." echo "Usage: $0 [OPTIONS]..."
@ -16,12 +18,11 @@ usage()
echo " -l log file to output to" echo " -l log file to output to"
echo " -p extract DKIM public key if found" echo " -p extract DKIM public key if found"
echo " -r SPF recursive tests" echo " -r SPF recursive tests"
exit 0
} }
log() log()
{ {
echo "$1" printf '%b\n' "$1"
if [ "$logfile" != "" ]; then if [ "$logfile" != "" ]; then
echo "$1" >> "$logfile" echo "$1" >> "$logfile"
@ -30,7 +31,7 @@ log()
print_good() print_good()
{ {
echo "\e[1;32m[+]\e[0m $1" printf '\033[1;32m[+]\033[0m %s\n' "$1"
if [ "$logfile" != "" ]; then if [ "$logfile" != "" ]; then
echo "[+] $1" >> "$logfile" echo "[+] $1" >> "$logfile"
@ -40,7 +41,7 @@ print_good()
print_bad() print_bad()
{ {
echo "\e[1;31m[-]\e[0m $1" printf '\033[1;31m[-]\033[0m %s\n' "$1"
if [ "$logfile" != "" ]; then if [ "$logfile" != "" ]; then
echo "[-] $1" >> "$logfile" echo "[-] $1" >> "$logfile"
@ -49,7 +50,7 @@ print_bad()
print_medium() print_medium()
{ {
echo "\e[1;33m[~]\e[0m $1" printf '\033[1;33m[~]\033[0m %s\n' "$1"
if [ "$logfile" != "" ]; then if [ "$logfile" != "" ]; then
echo "[~] $1" >> "$logfile" echo "[~] $1" >> "$logfile"
@ -58,7 +59,7 @@ print_medium()
print_info() print_info()
{ {
echo "\e[1;34m[I]\e[0m $1" printf '\033[1;34m[I]\033[0m %s\n' "$1"
if [ "$logfile" != "" ]; then if [ "$logfile" != "" ]; then
echo "[I] $1" >> "$logfile" echo "[I] $1" >> "$logfile"
@ -79,23 +80,25 @@ bimi_selectors_file="./bimi_selectors.txt"
while getopts "d:hl:pr" o; do while getopts "d:hl:pr" o; do
case "${o}" in case "${o}" in
d) d)
d="${OPTARG}" d="${OPTARG}"
;; ;;
h) h)
usage usage
;; exit 0
;;
l) l)
logfile="${OPTARG}" logfile="${OPTARG}"
;; ;;
p) p)
dkim_extract=1 dkim_extract=1
;; ;;
r) r)
spf_recursive=1 spf_recursive=1
;; ;;
*) *)
usage usage
;; exit 1
;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
@ -413,7 +416,8 @@ dkim_specific()
fi fi
for s in $selectors; do for s in $selectors; do
local curr="$(dig +short txt "$s._domainkey.$d" | grep "v=DKIM")" local curr
curr=$(dig +short txt "$s._domainkey.$d" | grep 'v=DKIM')
if [ "$curr" != "" ]; then if [ "$curr" != "" ]; then
print_good "DKIM $full_name set ($s)" print_good "DKIM $full_name set ($s)"
@ -450,7 +454,8 @@ dkim_extract_key()
return return
fi fi
local dkim_p="$(echo "$dkim" | grep -Eo 'p=[^;]+' | sed 's/p=//g' | sed 's/[ "]//g')" local dkim_p
dkim_p=$(echo "$dkim" | grep -Eo 'p=[^;]+' | sed 's/p=//g' | sed 's/[ "]//g')
print_info "Extracting DKIM public key..." print_info "Extracting DKIM public key..."
@ -469,7 +474,8 @@ dkim_crypto_keysize()
return return
fi fi
local keysize="$(echo "$dkim_parsed_key" | grep -E 'Public-Key:[ ]+\([0-9]+[ ]+bit\)' | grep -Eo '[0-9]+')" local keysize
keysize=$(echo "$dkim_parsed_key" | grep -E 'Public-Key:[ ]+\([0-9]+[ ]+bit\)' | grep -Eo '[0-9]+')
if [ "$keysize" -lt $dkim_key_minsize ]; then if [ "$keysize" -lt $dkim_key_minsize ]; then
print_medium "DKIM public key size is < $dkim_key_minsize bits ($keysize bits)" print_medium "DKIM public key size is < $dkim_key_minsize bits ($keysize bits)"
@ -624,7 +630,8 @@ get_bimi()
while read -r s; do while read -r s; do
print_info "$s" print_info "$s"
local curr="$(dig +short txt "$s._bimi.$d" | grep "v=BIMI")" local curr
curr="$(dig +short txt "$s._bimi.$d" | grep 'v=BIMI')"
if [ "$curr" != "" ]; then if [ "$curr" != "" ]; then
print_good "BIMI found for selector $s: $curr" print_good "BIMI found for selector $s: $curr"
@ -665,7 +672,7 @@ if [ "$d" = "" ]; then
exit 1 exit 1
fi fi
log "Checking \e[1;32m$d\e[0m" log "Checking \033[1;32m$d\033[0m"
log log
# Preliminary checks # Preliminary checks

Loading…
Cancel
Save