regen-inplace-luks1 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash -x
  2. # vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
  3. #
  4. # Copyright (c) 2020 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. TEST="${0}"
  21. . tests-common-functions
  22. . clevis-luks-common-functions
  23. function on_exit() {
  24. [ -d "${TMP}" ] || return 0
  25. tang_stop "${TMP}"
  26. rm -rf "${TMP}"
  27. }
  28. trap 'on_exit' EXIT
  29. TMP=$(mktemp -d)
  30. port=$(tang_new_random_port)
  31. tang_run "${TMP}" "${port}"
  32. url="http://localhost:${port}"
  33. adv="${TMP}/adv"
  34. tang_get_adv "${port}" "${adv}"
  35. cfg=$(printf '{"url":"%s","adv":"%s"}' "$url" "$adv")
  36. # LUKS1.
  37. DEV="${TMP}/luks1-device"
  38. new_device "luks1" "${DEV}"
  39. if ! clevis luks bind -f -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then
  40. error "${TEST}: Bind should have succeeded."
  41. fi
  42. # Now let's remove the initial passphrase.
  43. if ! cryptsetup luksRemoveKey --batch-mode "${DEV}" <<< "${DEFAULT_PASS}"; then
  44. error "${TEST}: error removing the default password from ${DEV}."
  45. fi
  46. # Making sure we have a single slot enabled.
  47. enabled=$(clevis_luks_used_slots "${DEV}" | wc -l)
  48. if [ "${enabled}" -ne 1 ]; then
  49. error "${TEST}: we should have only one slot enabled (${enabled})."
  50. fi
  51. old_key=$(clevis_luks_unlock_device_by_slot "${DEV}" "${SLT}")
  52. # Now let's try regen.
  53. SLT=1
  54. if ! clevis luks regen -q -d "${DEV}" -s "${SLT}"; then
  55. error "${TEST}: clevis luks regen failed"
  56. fi
  57. new_key=$(clevis_luks_unlock_device_by_slot "${DEV}" "${SLT}")
  58. if [ "${old_key}" = "${new_key}" ]; then
  59. error "${TEST}: the passphrases should be different"
  60. fi