report-sss-luks2 2.2 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=$(get_random_port)
  31. tang_run "${TMP}" "${port}" &
  32. tang_wait_until_ready "${port}"
  33. url="http://${TANG_HOST}:${port}"
  34. adv="${TMP}/adv"
  35. tang_get_adv "${port}" "${adv}"
  36. cfg=$(printf '{"t": 1, "pins":{"tang":[{"url":"%s"}], "sss":{"t":1,"pins":{"tang":[{"url":"%s"}]}}}}' "${url}" "${url}")
  37. # LUKS2.
  38. DEV="${TMP}/luks2-device"
  39. new_device "luks2" "${DEV}"
  40. SLT=3
  41. if ! clevis luks bind -y -d "${DEV}" -s "${SLT}" sss "${cfg}" <<< "${DEFAULT_PASS}"; then
  42. error "${TEST}: Bind should have succeeded."
  43. fi
  44. # Report should return 0, as no keys are rotated.
  45. if ! clevis luks report -q -d "${DEV}" -s "${SLT}"; then
  46. error "${TEST}: report should have succeeded, since no keys were rotated"
  47. fi
  48. # Now let's rotate the keys.
  49. tang_new_keys "${TMP}" "rotate-keys"
  50. # Report should now return 1.
  51. if clevis luks report -q -d "${DEV}" -s "${SLT}"; then
  52. error "${TEST}: report should have indicated keys were rotated"
  53. fi
  54. # Now let's regen the keys.
  55. if ! clevis luks report -q -r -d "${DEV}" -s "${SLT}"; then
  56. error "${TEST}: report with regen should have succeeded"
  57. fi
  58. # Report should return 0 again.
  59. if ! clevis luks report -q -d "${DEV}" -s "${SLT}"; then
  60. error "${TEST}: report should have succeeded after regen"
  61. fi