pin-tang 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash -xe
  2. # vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
  3. #
  4. # Copyright (c) 2016 Red Hat, Inc.
  5. # Author: Nathaniel McCallum <npmccallum@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. . tang-common-test-functions
  21. on_exit() {
  22. exit_status=$?
  23. tang_stop "${TMP}"
  24. [ -d "$TMP" ] && rm -rf "$TMP"
  25. exit "${exit_status}"
  26. }
  27. trap 'on_exit' EXIT
  28. TMP="$(mktemp -d)"
  29. port=$(tang_new_random_port)
  30. tang_run "${TMP}" "${port}" sig exc
  31. thp="$(jose jwk thp -i "$TMP/db/sig.jwk")"
  32. adv="${TMP}/adv.jws"
  33. tang_get_adv "${port}" "${adv}"
  34. url="http://localhost:${port}"
  35. cfg="$(printf '{"url":"%s","adv":"%s"}' "$url" "$adv")"
  36. enc="$(echo -n "hi" | clevis encrypt tang "$cfg")"
  37. dec="$(echo -n "$enc" | clevis decrypt)"
  38. test "$dec" == "hi"
  39. cfg="$(printf '{"url":"%s","thp":"%s"}' "$url" "$thp")"
  40. enc="$(echo -n "hi" | clevis encrypt tang "$cfg")"
  41. dec="$(echo -n "$enc" | clevis decrypt)"
  42. test "$dec" == "hi"
  43. tang_stop "${TMP}"
  44. ! echo "$enc" | clevis decrypt