diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 14:14:45 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 14:14:45 +0000 |
commit | 5ee2f2f5960044bdca0a5e1baf77225bdad6409d (patch) | |
tree | a1515ac00329374a37113d5d3ea1991f8a5d3c23 /askpass | |
parent | Initial commit. (diff) | |
download | cryptsetup-nuke-password-5ee2f2f5960044bdca0a5e1baf77225bdad6409d.tar.xz cryptsetup-nuke-password-5ee2f2f5960044bdca0a5e1baf77225bdad6409d.zip |
Adding upstream version 4+nmu1.upstream/4+nmu1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'askpass')
-rwxr-xr-x | askpass | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -0,0 +1,58 @@ +#!/bin/sh + +DIVERTED_ASKPASS=${DIVERTED_ASKPASS:-/lib/cryptsetup/askpass.cryptsetup} +NUKE_PASSWORD_HASH_PATH=${NUKE_PASSWORD_HASH_PATH:-/etc/cryptsetup-nuke-password/password_hash} +CRYPT_HELPER=${CRYPT_HELPER:-/usr/lib/cryptsetup-nuke-password/crypt} + +sanity_checks() { + local cryptsetup="$(which cryptsetup 2>/dev/null)" + if [ -z "$cryptsetup" ]; then + echo "$0: WARNING: cryptsetup not found in PATH" >&2 + return 1 + fi + if [ ! -e "$CRYPTTAB_SOURCE" ]; then + echo "$0: WARNING: \$CRYPTTAB_SOURCE (value: $CRYPTTAB_SOURCE) does not exist" >&2 + return 1 + fi + if [ ! -x "$CRYPT_HELPER" ]; then + echo "$0: WARNING: $CRYPT_HELPER is not executable" >&2 + return 1 + fi + return 0 +} + +hash_is_matching() { + local pass="$1" + local pass_hash + + if [ ! -r $NUKE_PASSWORD_HASH_PATH ]; then + # No hash, no match + return 1 + fi + pass_hash=$(cat $NUKE_PASSWORD_HASH_PATH) + if echo -n "$pass" | $CRYPT_HELPER --check "$pass_hash"; then + # User typed the nuke password! + return 0 + else + return 1 + fi +} + +nuke_cryptsetup_partition() { + local partition="$1" + cryptsetup --batch-mode erase "$partition" +} + +if [ ! -x "$DIVERTED_ASKPASS" ]; then + echo "ERROR: $DIVERTED_ASKPASS is not available/executable" >&2 + exit 1 +fi + +PASSWORD=$($DIVERTED_ASKPASS "$1") + +if sanity_checks && hash_is_matching "$PASSWORD"; then + nuke_cryptsetup_partition "$CRYPTTAB_SOURCE" +fi + +# Forward the password +echo -n "$PASSWORD" |