assume-yes 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash -ex
  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. TEST=$(basename "${0}")
  20. . tests-common-functions
  21. . clevis-luks-common-functions
  22. on_exit() {
  23. [ ! -d "${TMP}" ] && return 0
  24. tang_stop "${TMP}"
  25. rm -rf "${TMP}"
  26. }
  27. trap 'on_exit' EXIT
  28. trap 'on_exit' ERR
  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. cfg=$(printf '{"url":"%s"}' "$url")
  35. test_tang() {
  36. local url="${1}"
  37. local cfg data pt
  38. cfg=$(printf '{"url":"%s"}' "$url")
  39. for data in "foo" "bar" "foo bar" "some-password-here"; do
  40. if ! pt="$(echo "${data}" | clevis encrypt tang "${cfg}" -y \
  41. | clevis decrypt)"; then
  42. error "${TEST}: tang - encrypt should succeed."
  43. fi
  44. if ["${pt}" != "${data}" ]; then
  45. error "${TEST}: tang - pt(${pt}) != data("${data}")."
  46. fi
  47. done
  48. }
  49. test_sss() {
  50. local url="${1}"
  51. local sss1 sss2 data pt
  52. sss1=$(printf '{"t":1, "pins": {"tang": [{"url": "%s"}]}}' "${url}")
  53. sss2=$(printf '{"t":2, "pins": {"tang": [{"url": "%s"}, {"url": "%s"}]}}' \
  54. "${url}" "${url}")
  55. for data in "foo" "bar" "foo bar" "some-password-here"; do
  56. if ! pt="$(echo "${data}" | clevis encrypt sss "${sss1}" -y \
  57. | clevis decrypt)"; then
  58. error "${TEST}: sss1 - encrypt should succeed."
  59. fi
  60. if ["${pt}" != "${data}" ]; then
  61. error "${TEST}: sss1 - pt(${pt}) != data("${data}")."
  62. fi
  63. if ! pt="$(echo "${data}" | clevis encrypt sss "${sss2}" -y \
  64. | clevis decrypt)"; then
  65. error "${TEST}: sss2 - encrypt should succeed."
  66. fi
  67. if ["${pt}" != "${data}" ]; then
  68. error "${TEST}: sss2 - pt(${pt}) != data("${data}")."
  69. fi
  70. done
  71. }
  72. test_tang "${url}"
  73. test_sss "${url}"
  74. # LUKS1.
  75. DEV="${TMP}/luks1-device"
  76. new_device "luks1" "${DEV}"
  77. # tang.
  78. if ! clevis luks bind -y -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then
  79. error "${TEST}: Bind should have succeeded (tang - $DEV)."
  80. fi
  81. if ! clevis_luks_unlock_device "${DEV}"; then
  82. error "${TEST}: we were unable to unlock ${DEV} (tang)."
  83. fi
  84. # sss.
  85. new_device "luks1" "${DEV}"
  86. sss=$(printf '{"t":2, "pins": {"tang": [{"url": "%s"}, {"url": "%s"}]}}' \
  87. "${url}" "${url}")
  88. if ! clevis luks bind -y -d "${DEV}" sss "${sss}" <<< "${DEFAULT_PASS}"; then
  89. error "${TEST}: Bind should have succeeded (sss - $DEV)."
  90. fi
  91. if ! clevis_luks_unlock_device "${DEV}"; then
  92. error "${TEST}: we were unable to unlock ${DEV} (sss)."
  93. fi