bind-luks1-avoid-luksmeta-corruption 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash -ex
  2. #
  3. # Copyright (c) 2021 Red Hat, Inc.
  4. # Author: Sergio Arroutbi Braojos <sarroutb@redhat.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. TEST=$(basename "${0}")
  20. . tests-common-functions
  21. on_exit() {
  22. [ ! -d "${TMP}" ] && return 0
  23. tang_stop "${TMP}"
  24. rm -rf "${TMP}"
  25. }
  26. trap 'on_exit' EXIT
  27. TMP="$(mktemp -d)"
  28. ADV_AMOUNT=50
  29. # Create LUKS1 device
  30. DEV="${TMP}/luks1-device"
  31. new_device "luks1" "${DEV}"
  32. # TANG server specifics
  33. port=$(tang_new_random_port)
  34. tang_run "${TMP}" "${port}"
  35. url="http://localhost:${port}"
  36. # Initial binding to ensure luksmeta gets corrupted
  37. for ADV_NU in $(seq 0 ${ADV_AMOUNT}); do
  38. "${TANGD_KEYGEN}" "${TMP}/db"
  39. done
  40. tang_new_keys "${TMP}"
  41. CFG=$(printf '{"url":"%s"}' "${url}")
  42. # At this point, luks bind must return an error. If not, test fails
  43. if clevis luks bind -y -d "${DEV}" tang "${CFG}" <<< "${DEFAULT_PASS}"; then
  44. error "${TEST}: Binding is expected to fail when given a too long adv"
  45. fi