| 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 <[email protected]> |
| 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 | |
| 21 | . tang-common-test-functions |
| 22 | |
| 23 | on_exit() { |
| 24 | exit_status=$? |
| 25 | tang_stop "${TMP}" |
| 26 | [ -d "$TMP" ] && rm -rf "$TMP" |
| 27 | exit "${exit_status}" |
| 28 | } |
| 29 | |
| 30 | trap 'on_exit' EXIT |
| 31 | |
| 32 | TMP="$(mktemp -d)" |
| 33 | |
| 34 | tang_run "${TMP}" sig exc |
| 35 | port=$(tang_get_port "${TMP}") |
| 36 | |
| 37 | thp="$(jose jwk thp -i "$TMP/db/sig.jwk")" |
| 38 | adv="${TMP}/adv.jws" |
| 39 | tang_get_adv "${port}" "${adv}" |
| 40 | url="http://localhost:${port}" |
| 41 | |
| 42 | cfg="$(printf '{"url":"%s","adv":"%s"}' "$url" "$adv")" |
| 43 | enc="$(echo -n "hi" | clevis encrypt tang "$cfg")" |
| 44 | dec="$(echo -n "$enc" | clevis decrypt)" |
| 45 | test "$dec" == "hi" |
| 46 | |
| 47 | cfg="$(printf '{"url":"%s","thp":"%s"}' "$url" "$thp")" |
| 48 | enc="$(echo -n "hi" | clevis encrypt tang "$cfg")" |
| 49 | dec="$(echo -n "$enc" | clevis decrypt)" |
| 50 | test "$dec" == "hi" |
| 51 | |
| 52 | tang_stop "${TMP}" |
| 53 | |
| 54 | ! echo "$enc" | clevis decrypt |