V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m40s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-08-26 22:12:48 +02:00
parent 18db8e1001
commit 35da78e891

View File

@@ -35,7 +35,7 @@ declare -g PASSPHRASE=''
# 1: Color code. # 1: Color code.
# *: Text to print. # *: Text to print.
####################################### #######################################
color_echo() { declare c="$1"; shift; declare msg="${*}"; printf "%s%s %s%s" "${c}" "${msg}" "${RES}" "${NL}"; } color_echo() { declare c="${1}"; shift; declare msg="${*}"; printf "%b%s %b%b" "${c}" "${msg}" "${RES}" "${NL}"; }
####################################### #######################################
# Die helper: print and exit hard. # Die helper: print and exit hard.
@@ -45,7 +45,7 @@ color_echo() { declare c="$1"; shift; declare msg="${*}"; printf "%s%s %s%s" "${
# Arguments: # Arguments:
# 1: Message string to print. # 1: Message string to print.
####################################### #######################################
die() { printf "%s✘ %s %s%s" "${RED}" "$1" "${RES}" "${NL}" >&2; power_off 3; } die() { printf "%b✘ %s %b%b" "${RED}" "$1" "${RES}" "${NL}" >&2; power_off 3; }
####################################### #######################################
# Drop to bash environment. # Drop to bash environment.
@@ -71,22 +71,32 @@ extract_nuke_hash() {
### Read '/proc/cmdline' into a single line safely. ### Read '/proc/cmdline' into a single line safely.
read -r CMDLINE < /proc/cmdline read -r CMDLINE < /proc/cmdline
for ARG in ${CMDLINE}; do for ARG in ${CMDLINE}; do
case "${ARG}" in case "${ARG}" in
nuke=*) nuke=*)
NUKE_HASH="${ARG#nuke=}" NUKE_HASH="${ARG#nuke=}"
if [[ "${NUKE_HASH}" =~ ${REGEX} ]]; then if [[ "${NUKE_HASH}" =~ ${REGEX} ]]; then
NUKE_ENABLED="true" NUKE_ENABLED="true"
return 0 return 0
else else
### If there is a malformed Grub Bootparameter 'nuke=HASH', drop to bash. ### If there is a malformed Grub Bootparameter 'nuke=HASH', drop to bash.
color_echo "${RED}" "✘ Nuke Hash Malformat : [${REGEX}] [${NUKE_HASH}]." >&2 color_echo "${RED}" "✘ Nuke Hash Malformat : [${REGEX}] [${NUKE_HASH}]." >&2
color_echo "${RED}" "✘ Dropping to bash ...:" >&2 color_echo "${RED}" "✘ Dropping to bash ...:" >&2
drop_bash drop_bash
fi fi
;; ;;
esac esac
done done
### No 'nuke=HASH' entry found. ### No 'nuke=HASH' entry found.
return 1 return 1
} }
@@ -101,6 +111,7 @@ gather_luks_devices() {
declare -i tries=0 declare -i tries=0
while ((tries < 10)); do while ((tries < 10)); do
# shellcheck disable=SC2312 # shellcheck disable=SC2312
mapfile -t curr < <(blkid -t TYPE=crypto_LUKS -o device | sort) mapfile -t curr < <(blkid -t TYPE=crypto_LUKS -o device | sort)
@@ -127,12 +138,18 @@ gather_luks_devices() {
####################################### #######################################
nuke() { nuke() {
declare dev="" declare dev=""
for dev in "${DEVICES_LUKS[@]}"; do for dev in "${DEVICES_LUKS[@]}"; do
cryptsetup erase --batch-mode "${dev}" || true cryptsetup erase --batch-mode "${dev}" || true
color_echo "${RED}" "✘ Error: LUKS Device Header malfunction: [${dev}]." color_echo "${RED}" "✘ Error: LUKS Device Header malfunction: [${dev}]."
done done
secure_unset_pass secure_unset_pass
color_echo "${RED}" "✘ Error: LUKS Device malfunction. System Power Off in 16 seconds." color_echo "${RED}" "✘ Error: LUKS Device malfunction. System Power Off in 16 seconds."
power_off 16 power_off 16
} }
@@ -168,15 +185,17 @@ print_scr_err() {
declare -r scr_err_errline="$3" declare -r scr_err_errline="$3"
declare -r scr_err_errfunc="$4" declare -r scr_err_errfunc="$4"
declare -r scr_err_errcmmd="$5" declare -r scr_err_errcmmd="$5"
printf "%s" "${NL}"
printf "%b" "${NL}"
color_echo "${RED}" "✘ System caught an 'ERROR'. System Power Off in 16 seconds." >&2 color_echo "${RED}" "✘ System caught an 'ERROR'. System Power Off in 16 seconds." >&2
printf "%s" "${NL}" printf "%b" "${NL}"
color_echo "${RED}" "✘ Error : [${scr_err_errcode}]" >&2 color_echo "${RED}" "✘ Error : [${scr_err_errcode}]" >&2
color_echo "${RED}" "✘ Line : [${scr_err_errline}]" >&2 color_echo "${RED}" "✘ Line : [${scr_err_errline}]" >&2
color_echo "${RED}" "✘ Script : [${scr_err_errscrt}]" >&2 color_echo "${RED}" "✘ Script : [${scr_err_errscrt}]" >&2
color_echo "${RED}" "✘ Function : [${scr_err_errfunc}]" >&2 color_echo "${RED}" "✘ Function : [${scr_err_errfunc}]" >&2
color_echo "${RED}" "✘ Command : [${scr_err_errcmmd}]" >&2 color_echo "${RED}" "✘ Command : [${scr_err_errcmmd}]" >&2
printf "%s" "${NL}" printf "%b" "${NL}"
} }
####################################### #######################################
@@ -229,15 +248,24 @@ read_passphrase() {
PASSPHRASE="$(${ASKPASS} "Enter passphrase: ")" PASSPHRASE="$(${ASKPASS} "Enter passphrase: ")"
if [[ "${NUKE_ENABLED,,}" == 'true' ]]; then if [[ "${NUKE_ENABLED,,}" == 'true' ]]; then
### Validate NUKE_HASH format (e.g., $id$salt$hash) ### Validate NUKE_HASH format (e.g., $id$salt$hash)
if [[ "${NUKE_HASH}" =~ ${REGEX} ]]; then if [[ "${NUKE_HASH}" =~ ${REGEX} ]]; then
SALT="$(cut -d'$' -f3 <<< "${NUKE_HASH}")" SALT="$(cut -d'$' -f3 <<< "${NUKE_HASH}")"
for METHOD in "${METHODS[@]}"; do for METHOD in "${METHODS[@]}"; do
if mkpasswd -m "${METHOD}" -S "${SALT}" "${PASSPHRASE}" 2>/dev/null | grep -qF -- "${NUKE_HASH}"; then if mkpasswd -m "${METHOD}" -S "${SALT}" "${PASSPHRASE}" 2>/dev/null | grep -qF -- "${NUKE_HASH}"; then
nuke nuke
fi fi
done done
fi fi
fi fi
return 0 return 0
@@ -267,6 +295,7 @@ trap_on_err() {
declare -r errline="$3" declare -r errline="$3"
declare -r errfunc="$4" declare -r errfunc="$4"
declare -r errcmmd="$5" declare -r errcmmd="$5"
trap - ERR INT TERM trap - ERR INT TERM
stty echo stty echo
print_scr_err "${errcode}" "${errscrt}" "${errline}" "${errfunc}" "${errcmmd}" print_scr_err "${errcode}" "${errscrt}" "${errline}" "${errfunc}" "${errcmmd}"
@@ -303,15 +332,17 @@ verify_script() {
# shellcheck disable=SC2312 # shellcheck disable=SC2312
dir="$(dirname "$(readlink -f "${0}")")" dir="$(dirname "$(readlink -f "${0}")")"
declare script; script="$(basename "${0}")" declare script; script="$(basename "${0}")"
declare -a algo=("sha512" "sha384") declare -a algo=( "sha512" "sha384" )
declare cmd="" computed="" expected="" hashfile="" item="" sigfile="" declare cmd="" computed="" expected="" hashfile="" item="" sigfile=""
for item in "${algo[@]}"; do for item in "${algo[@]}"; do
hashfile="${dir}/${script}.${item}" hashfile="${dir}/${script}.${item}"
sigfile="${hashfile}.sig" sigfile="${hashfile}.sig"
cmd="${item}sum" cmd="${item}sum"
color_echo "${MAG}" "🔏 Verifying signature of: [${hashfile}]" color_echo "${MAG}" "🔏 Verifying signature of: [${hashfile}]"
gpgv --keyring /etc/keys/pubring.gpg "${sigfile}" "${hashfile}" || { gpgv --keyring /etc/keys/pubring.gpg "${sigfile}" "${hashfile}" || {
color_echo "${RED}" "✘ Signature verification failed for: [${hashfile}]" color_echo "${RED}" "✘ Signature verification failed for: [${hashfile}]"
color_echo "${RED}" "✘ System Power Off in 3 seconds ...." color_echo "${RED}" "✘ System Power Off in 3 seconds ...."
@@ -320,6 +351,7 @@ verify_script() {
color_echo "${GRE}" "🔏 Verifying signature of: [${hashfile}] successful." color_echo "${GRE}" "🔏 Verifying signature of: [${hashfile}] successful."
color_echo "${MAG}" "🔢 Recomputing Hash: [${item}]" color_echo "${MAG}" "🔢 Recomputing Hash: [${item}]"
computed=$(${cmd} "${dir}/${script}" | awk '{print $1}') computed=$(${cmd} "${dir}/${script}" | awk '{print $1}')
expected=$(cat "${hashfile}") expected=$(cat "${hashfile}")
@@ -329,6 +361,7 @@ verify_script() {
power_off 3 power_off 3
fi fi
color_echo "${GRE}" "🔢 Recomputing Hash: [${item}] successful." color_echo "${GRE}" "🔢 Recomputing Hash: [${item}] successful."
done done
color_echo "${GRE}" "🔏 All signatures and hashes verified successfully. Proceeding." color_echo "${GRE}" "🔏 All signatures and hashes verified successfully. Proceeding."
@@ -354,13 +387,13 @@ main() {
color_echo "${RED}" "Coresecret Connection established." color_echo "${RED}" "Coresecret Connection established."
color_echo "${RED}" "Starting Time: ${CURRENTDATE}" color_echo "${RED}" "Starting Time: ${CURRENTDATE}"
color_echo "${MAG}" "Integrity self-check ..." color_echo "${MAG}" "Integrity self-check ..."
printf "%s" "${NL}" printf "%b" "${NL}"
verify_script verify_script
### Read newline-separated output into an array. ### Read newline-separated output into an array.
color_echo "${MAG}" "Scanning for LUKS devices ..." color_echo "${MAG}" "Scanning for LUKS devices ..."
printf "%s" "${NL}" printf "%b" "${NL}"
# shellcheck disable=SC2312 # shellcheck disable=SC2312
mapfile -t DEVICES_LUKS < <(gather_luks_devices) mapfile -t DEVICES_LUKS < <(gather_luks_devices)
@@ -383,7 +416,7 @@ main() {
else else
printf "%s" "${NL}" printf "%b" "${NL}"
color_echo "${RED}" "✘ Unsuccessful command 'cryptroot-unlock'." color_echo "${RED}" "✘ Unsuccessful command 'cryptroot-unlock'."
color_echo "${GRE}" "✘ No LUKS operations performed. Dropping to bash ..." color_echo "${GRE}" "✘ No LUKS operations performed. Dropping to bash ..."
color_echo "${GRE}" "✘ To unlock 'root' partition, and maybe others like 'swap', run 'cryptroot-unlock'." color_echo "${GRE}" "✘ To unlock 'root' partition, and maybe others like 'swap', run 'cryptroot-unlock'."