clevis.in 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2017 Shawn Rose
  4. # Author: Shawn Rose <shawnandrewrose@gmail.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. PREREQ="cryptroot"
  20. prereqs()
  21. {
  22. echo "$PREREQ"
  23. }
  24. case $1 in
  25. prereqs)
  26. prereqs
  27. exit 0
  28. ;;
  29. esac
  30. . @initramfstoolsdir@/hook-functions
  31. die() {
  32. code="$1"
  33. msg="$2"
  34. echo " (ERROR): $msg" >&2
  35. exit $1
  36. }
  37. find_binary() {
  38. bin_name="$1"
  39. resolved=$(command -v ${bin_name})
  40. [ -z "$resolved" ] && die 1 "Unable to find ${bin_name}"
  41. echo "$resolved"
  42. }
  43. if [ -n "${FORCE_CLEVIS}" ] && [ "${FORCE_CLEVIS}" != "n" ]; then
  44. for f in /sbin/cryptsetup /sbin/dmsetup /lib/cryptsetup/askpass; do
  45. if [ ! -e "${DESTDIR}${f}" ]; then
  46. die 2 "cryptsetup utility '$f' wasn't found in the generated ramdisk image. "
  47. fi
  48. done
  49. fi
  50. copy_exec @bindir@/clevis-decrypt-tang || die 1 "@bindir@/clevis-decrypt-tang not found"
  51. copy_exec @bindir@/clevis-decrypt-sss || die 1 "@bindir@/clevis-decrypt-sss not found"
  52. copy_exec @bindir@/clevis-decrypt-null || die 1 "@bindir@/clevis-decrypt-null not found"
  53. copy_exec @bindir@/clevis-decrypt || die 1 "@bindir@/clevis-decrypt not found"
  54. copy_exec @bindir@/clevis-luks-common-functions || die 1 "@bindir@/clevis-luks-common-functions not found"
  55. copy_exec @bindir@/clevis-luks-list || die 1 "@bindir@/clevis-luks-list not found"
  56. if [ -x @bindir@/clevis-decrypt-tpm2 ]; then
  57. copy_exec @bindir@/clevis-decrypt-tpm2 || die 1 "@bindir@/clevis-decrypt-tpm2 not found"
  58. tpm2_creatprimary_bin=$(find_binary "tpm2_createprimary")
  59. tpm2_unseal_bin=$(find_binary "tpm2_unseal")
  60. tpm2_load_bin=$(find_binary "tpm2_load")
  61. tpm2_flushcontext=$(find_binary "tpm2_flushcontext")
  62. copy_exec "${tpm2_creatprimary_bin}" || die 1 "Unable to copy ${tpm2_creatprimary_bin}"
  63. copy_exec "${tpm2_unseal_bin}" || die 1 "Unable to copy ${tpm2_unseal_bin}"
  64. copy_exec "${tpm2_load_bin}" || die 1 "Unable to copy ${tpm2_load_bin}"
  65. copy_exec "${tpm2_flushcontext}" || die 1 "Unable to copy ${tpm2_flushcontext}"
  66. for _LIBRARY in @libdir@/libtss2-tcti-device.so*; do
  67. if [ -e "${_LIBRARY}" ]; then
  68. copy_exec "${_LIBRARY}" || die 2 "Unable to copy ${_LIBRARY}"
  69. fi
  70. done
  71. manual_add_modules tpm_crb
  72. manual_add_modules tpm_tis
  73. fi
  74. luksmeta_bin=$(find_binary "luksmeta")
  75. jose_bin=$(find_binary "jose")
  76. copy_exec "${luksmeta_bin}" || die 2 "Unable to copy ${luksmeta_bin}"
  77. copy_exec "${jose_bin}" || die 2 "Unable to copy ${jose_bin}"
  78. copy_exec @bindir@/clevis || die 1 "@bindir@/clevis not found"
  79. curl_bin=$(find_binary "curl")
  80. awk_bin=$(find_binary "awk")
  81. bash_bin=$(find_binary "bash")
  82. copy_exec "${curl_bin}" || die 2 "Unable to copy ${curl_bin} to initrd image"
  83. copy_exec "${awk_bin}" || die 2 "Unable to copy ${awk_bin} to initrd image"
  84. copy_exec "${bash_bin}" || die 2 "Unable to copy ${bash_bin} to initrd image"