decrypt_derived 1.1 KB

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