clevis-luks-pass 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash -e
  2. # vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
  3. #
  4. # Copyright (c) 2019 Red Hat, Inc.
  5. # Author: Sergio Correia <scorreia@redhat.com>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. . clevis-luks-common-functions
  21. SUMMARY="Returns the LUKS passphrase used for binding a particular slot."
  22. usage() {
  23. exec >&2
  24. echo "Usage: clevis luks pass -d DEV -s SLT"
  25. echo
  26. echo "$SUMMARY"
  27. echo
  28. echo " -d DEV The LUKS device to extract the LUKS passphrase used for binding"
  29. echo
  30. echo " -s SLOT The slot number to extract the LUKS passphrase"
  31. echo
  32. exit 1
  33. }
  34. if [ ${#} -eq 1 ] && [ "${1}" = "--summary" ]; then
  35. echo "${SUMMARY}"
  36. exit 0
  37. fi
  38. while getopts ":d:s:" o; do
  39. case "$o" in
  40. d) DEV=${OPTARG};;
  41. s) SLT=${OPTARG};;
  42. *) usage;;
  43. esac
  44. done
  45. if [ -z "${DEV}" ]; then
  46. echo "Did not specify a device!" >&2
  47. usage
  48. fi
  49. if [ -z "${SLT}" ]; then
  50. echo "Did not specify a slot!" >&2
  51. usage
  52. fi
  53. if ! clevis_luks_unlock_device_by_slot "${DEV}" "${SLT}"; then
  54. echo "It was not possible to decrypt the passphrase associated to slot ${SLT} in ${DEV}!" >&2
  55. exit 1
  56. fi