Debian Codegraph @

debian/scripts/decrypt_derived

raw symbols SCIP
1 #!/bin/sh
2
3 # WARNING: If you use the decrypt_derived keyscript for devices with
4 # persistent data (i.e. not swap or temp devices), then you will lose
5 # access to that data permanently if something damages the LUKS header
6 # of the LUKS device you derive from. The same applies if you luksFormat
7 # the device, even if you use the same passphrase(s). A LUKS header
8 # backup, or better a backup of the data on the derived device may be
9 # a good idea. See the Cryptsetup FAQ on how to do this right.
10
11 if [ -z "$1" ]; then
12 echo "$0: must be executed with a crypto device as argument" >&2
13 exit 1
14 fi
15
16 unset -v keys count
17 keys="$(dmsetup table --target crypt --showkeys -- "$1" 2>/dev/null | cut -s -d' ' -f5)"
18 count="$(printf '%s' "$keys" | wc -l)"
19
20 if [ -n "$keys" ] && [ $count -le 1 ]; then
21 if [ "${keys#:}" = "$keys" ]; then
22 printf '%s' "$keys"
23 exit 0
24 else
25 echo "$0: device $1 uses the kernel keyring" >&2
26 fi
27 elif [ $count -eq 0 ]; then
28 echo "$0: device $1 doesn't exist or isn't a crypto device" >&2
29 else
30 echo "$0: more than one device match" >&2
31 fi
32 exit 1